[NancyFx] provide option to override package context (#6593)

* 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.

* Add the option packageContext for nancyFx which allows a better adjustment of the namespace.

* run nancyfx-petstore-server.bat
This commit is contained in:
craffael
2017-10-02 05:10:09 +02:00
committed by wing328
parent 6e7ad13e1b
commit 1f4013e7f1
3 changed files with 10 additions and 7 deletions

View File

@@ -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<String, Predicate<Property>> propertyToSwaggerTypeMapping =
createPropertyToSwaggerTypeMapping();
@@ -76,6 +77,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
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 class NancyFXServerCodegen extends AbstractCSharpCodegen {
@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() : "/");
}