forked from loafle/openapi-generator-original
[NancyFx] Support Async (#6755)
* add support for async routes/endpoints you can now set --optional-properties async=true to generate a nancyfx server stub that uses asynchronous programming. (cherry picked from commit 126869cb0b967e8063417e11993cf6326ce8ffd4) * add nancyfx-petstore-server-async.sh to generate sample of async nancyfx. * Rename async => asyncServer * update bin/nancyfx-petstore-server-async.sh * rename async => asyncServer in api.mustache + small bugfix * run ./bin/nancyfx-petstore-server.sh and ./bin/nancyfx-petstore-server-async.sh * remove additional new line in api.mustache + add space after if * run ./bin/nancyfx-petstore-server.sh and ./bin/nancyfx-petstore-server-async.sh
This commit is contained in:
@@ -46,6 +46,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
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 String ASYNC_SERVER = "asyncServer";
|
||||
|
||||
private static final Map<String, Predicate<Property>> propertyToSwaggerTypeMapping =
|
||||
createPropertyToSwaggerTypeMapping();
|
||||
@@ -57,6 +58,9 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
private final Multimap<String, CodegenModel> childrenByParent = ArrayListMultimap.create();
|
||||
private final BiMap<String, String> modelNameMapping = HashBiMap.create();
|
||||
|
||||
/** If set to true, we will generate c# async endpoints and service interfaces */
|
||||
private boolean asyncServer = false;
|
||||
|
||||
public NancyFXServerCodegen() {
|
||||
outputFolder = "generated-code" + File.separator + getName();
|
||||
apiTemplateFiles.put("api.mustache", ".cs");
|
||||
@@ -87,6 +91,7 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
addSwitch(RETURN_ICOLLECTION, RETURN_ICOLLECTION_DESC, returnICollection);
|
||||
addSwitch(IMMUTABLE_OPTION, "Enabled by default. If disabled generates model classes with setters", true);
|
||||
addSwitch(USE_BASE_PATH, "Enabled by default. If disabled, module paths will not mirror api base path", true);
|
||||
addSwitch(ASYNC_SERVER, "Set to true to enable the generation of async routes/endpoints.", false);
|
||||
typeMapping.putAll(nodaTimeTypesMappings());
|
||||
languageSpecificPrimitives.addAll(nodaTimePrimitiveTypes());
|
||||
|
||||
@@ -128,6 +133,10 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
setPackageGuid((String) additionalProperties.get(OPTIONAL_PROJECT_GUID));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(ASYNC_SERVER)) {
|
||||
setAsyncServer(Boolean.parseBoolean((String)additionalProperties.get(ASYNC_SERVER)));
|
||||
}
|
||||
|
||||
additionalProperties.put("packageGuid", packageGuid);
|
||||
|
||||
setupModelTemplate();
|
||||
@@ -199,7 +208,11 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
public void setPackageGuid(String packageGuid) {
|
||||
this.packageGuid = packageGuid;
|
||||
}
|
||||
|
||||
|
||||
public void setAsyncServer(boolean asyncServer) {
|
||||
this.asyncServer = asyncServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder() + File.separator + API_NAMESPACE;
|
||||
|
||||
Reference in New Issue
Block a user