From f2c3aaca6eef27d20db8d02b767f7d4e6b589e0f Mon Sep 17 00:00:00 2001 From: raffael Date: Wed, 30 Aug 2017 12:51:45 +0200 Subject: [PATCH 1/3] Retrofit2: Return ResponseBody if response if file. Until now -------------------- If a swagger endpoint returned a file (e.g. an image), then the Retrofit2 template has choosen the return type java.io.File. However, retrofit cannot deal with this and throws a com.google.gson.stream.MalformedJsonException. New: ------------------- If a swagger endpoint returns a file, then the corresponding Retrofit2 endpoint will return a okhttp3.ResponseBody which can be used to retrieve the file. --- .../src/main/resources/Java/libraries/retrofit2/api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache index 36d4a5c55a9..bee45765669 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache @@ -14,6 +14,7 @@ import retrofit2.Call; import retrofit2.http.*; import okhttp3.RequestBody; +import okhttp3.ResponseBody; {{#imports}}import {{import}}; {{/imports}} @@ -60,7 +61,7 @@ public interface {{classname}} { {{/prioritizedContentTypes}} {{/formParams}} @{{httpMethod}}("{{{path}}}") - {{^usePlay24WS}}{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}{{/usePlay24WS}}{{#usePlay24WS}}F.Promise{{#usePlay24WS}}>{{/usePlay24WS}} {{operationId}}({{^allParams}});{{/allParams}} + {{^usePlay24WS}}{{^doNotUseRx}}Observable{{/doNotUseRx}}{{#doNotUseRx}}Call{{/doNotUseRx}}{{/usePlay24WS}}{{#usePlay24WS}}F.Promise{{#usePlay24WS}}>{{/usePlay24WS}} {{operationId}}({{^allParams}});{{/allParams}} {{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}} );{{/hasMore}}{{/allParams}} From 9d6022d657c0056695185ed429c0634532209562 Mon Sep 17 00:00:00 2001 From: raffael Date: Fri, 29 Sep 2017 16:45:22 +0200 Subject: [PATCH 2/3] Add the option packageContext for nancyFx which allows a better adjustment of the namespace. --- .../io/swagger/codegen/languages/NancyFXServerCodegen.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java index 3d21bed182a..5e577b4c3de 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java @@ -45,6 +45,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { private static final String MODEL_NAMESPACE = "Models"; private static final String IMMUTABLE_OPTION = "immutable"; private static final String USE_BASE_PATH = "writeModulePath"; + private static final String PACKAGE_CONTEXT = "packageContext"; private static final Map> propertyToSwaggerTypeMapping = createPropertyToSwaggerTypeMapping(); @@ -76,6 +77,7 @@ public NancyFXServerCodegen() { addOption(SOURCE_FOLDER, SOURCE_FOLDER_DESC, sourceFolder); addOption(INTERFACE_PREFIX, INTERFACE_PREFIX_DESC, interfacePrefix); addOption(OPTIONAL_PROJECT_GUID,OPTIONAL_PROJECT_GUID_DESC, null); + addOption(PACKAGE_CONTEXT, "Optionally overrides the PackageContext which determines the namespace (namespace=packageName.packageContext). If not set, packageContext will default to basePath.", null); // CLI Switches addSwitch(SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_BY_REQUIRED_FLAG_DESC, sortParamsByRequiredFlag); @@ -335,7 +337,8 @@ public String toModelName(final String name) { @Override public void preprocessSwagger(final Swagger swagger) { - additionalProperties.put("packageContext", sanitizeName(swagger.getBasePath())); + final String packageContextOption = (String) additionalProperties.get(PACKAGE_CONTEXT); + additionalProperties.put("packageContext", packageContextOption == null ? sanitizeName(swagger.getBasePath()) : packageContextOption); final Object basePathOption = additionalProperties.get(USE_BASE_PATH); additionalProperties.put("baseContext", basePathOption == null ? swagger.getBasePath() : "/"); } From f7a34a641e91aae55c88a47ee10d56bb7aefbc52 Mon Sep 17 00:00:00 2001 From: raffael Date: Fri, 29 Sep 2017 16:50:29 +0200 Subject: [PATCH 3/3] run nancyfx-petstore-server.bat --- samples/server/petstore/nancyfx/IO.Swagger.sln | 10 +++++----- .../petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/server/petstore/nancyfx/IO.Swagger.sln b/samples/server/petstore/nancyfx/IO.Swagger.sln index 1e40deb1a14..234aa6fb01c 100644 --- a/samples/server/petstore/nancyfx/IO.Swagger.sln +++ b/samples/server/petstore/nancyfx/IO.Swagger.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{768B8DC6-54EE-4D40-9B20-7857E1D742A4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{DFBD27E3-36EF-45CB-9D6D-EF500915B5CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -10,10 +10,10 @@ Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution -{768B8DC6-54EE-4D40-9B20-7857E1D742A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU -{768B8DC6-54EE-4D40-9B20-7857E1D742A4}.Debug|Any CPU.Build.0 = Debug|Any CPU -{768B8DC6-54EE-4D40-9B20-7857E1D742A4}.Release|Any CPU.ActiveCfg = Release|Any CPU -{768B8DC6-54EE-4D40-9B20-7857E1D742A4}.Release|Any CPU.Build.0 = Release|Any CPU +{DFBD27E3-36EF-45CB-9D6D-EF500915B5CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU +{DFBD27E3-36EF-45CB-9D6D-EF500915B5CF}.Debug|Any CPU.Build.0 = Debug|Any CPU +{DFBD27E3-36EF-45CB-9D6D-EF500915B5CF}.Release|Any CPU.ActiveCfg = Release|Any CPU +{DFBD27E3-36EF-45CB-9D6D-EF500915B5CF}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj index e1577197b6f..6c13d64b402 100644 --- a/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/server/petstore/nancyfx/src/IO.Swagger/IO.Swagger.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - {768B8DC6-54EE-4D40-9B20-7857E1D742A4} + {DFBD27E3-36EF-45CB-9D6D-EF500915B5CF} Library Properties IO.Swagger.v2