For erlang-server. add two options: packageName and openAPISpecName (#1303)

* Implement the ability to read packageName and openAPISpecName from a json file

* Replace '{{openAPISpecName}}' with '{{{openAPISpecName}}}'

* Update erlang-petstore-server
This commit is contained in:
feihongmeilian 2018-10-24 16:29:53 +08:00 committed by William Cheng
parent 76aedca6b2
commit 24ea88495b
6 changed files with 33 additions and 11 deletions

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -t modules\openapi-generator\src\main\resources\erlang-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g erlang-server -o samples\client\petstore\erlang-server set ags=generate -t modules\openapi-generator\src\main\resources\erlang-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g erlang-server -o samples\server\petstore\erlang-server
java %JAVA_OPTS% -jar %executable% %ags% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -278,4 +278,5 @@ public class CodegenConstants {
public static final String ENABLE_POST_PROCESS_FILE = "enablePostProcessFile"; public static final String ENABLE_POST_PROCESS_FILE = "enablePostProcessFile";
public static final String ENABLE_POST_PROCESS_FILE_DESC = "Enable post-processing file using environment variables."; public static final String ENABLE_POST_PROCESS_FILE_DESC = "Enable post-processing file using environment variables.";
public static final String OPEN_API_SPEC_NAME = "openAPISpecName";
} }

View File

@ -40,6 +40,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
protected String apiVersion = "1.0.0"; protected String apiVersion = "1.0.0";
protected String apiPath = "src"; protected String apiPath = "src";
protected String packageName = "openapi"; protected String packageName = "openapi";
protected String openApiSpecName = "openapi";
public ErlangServerCodegen() { public ErlangServerCodegen() {
super(); super();
@ -47,13 +48,6 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
// set the output folder here // set the output folder here
outputFolder = "generated-code/erlang-server"; outputFolder = "generated-code/erlang-server";
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
}
;
/** /**
* Models. You can write model files using the modelTemplateFiles map. * Models. You can write model files using the modelTemplateFiles map.
* if you want to create one template for file, you can do so here. * if you want to create one template for file, you can do so here.
@ -117,6 +111,27 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
cliOptions.clear(); cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).") cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).")
.defaultValue(this.packageName)); .defaultValue(this.packageName));
cliOptions.add(new CliOption(CodegenConstants.OPEN_API_SPEC_NAME, "Openapi Spec Name.")
.defaultValue(this.openApiSpecName));
}
@Override
public void processOpts() {
super.processOpts();
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
}
if (additionalProperties.containsKey(CodegenConstants.OPEN_API_SPEC_NAME)) {
setOpenApiSpecName((String) additionalProperties.get(CodegenConstants.OPEN_API_SPEC_NAME));
} else {
additionalProperties.put(CodegenConstants.OPEN_API_SPEC_NAME, openApiSpecName);
}
/** /**
* Additional Properties. These values can be passed to the templates and * Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files * are available in models, apis, and supporting files
@ -135,7 +150,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl"))); supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl"))); supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl"))); supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath("openapi", "json"))); supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath(this.openApiSpecName, "json")));
supportingFiles.add(new SupportingFile("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl"))); supportingFiles.add(new SupportingFile("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl")));
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl"))); supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
@ -254,6 +269,10 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
this.packageName = packageName; this.packageName = packageName;
} }
public void setOpenApiSpecName(String openApiSpecName) {
this.openApiSpecName = openApiSpecName;
}
protected String toHandlerName(String name) { protected String toHandlerName(String name) {
return toModuleName(name) + "_handler"; return toModuleName(name) + "_handler";
} }

View File

@ -69,6 +69,6 @@ prepare_validator() ->
get_openapi_path() -> get_openapi_path() ->
{ok, AppName} = application:get_application(?MODULE), {ok, AppName} = application:get_application(?MODULE),
filename:join({{packageName}}_utils:priv_dir(AppName), "openapi.json"). filename:join({{packageName}}_utils:priv_dir(AppName), "{{{openAPISpecName}}}.json").

View File

@ -1 +1 @@
3.0.0-SNAPSHOT 3.3.2-SNAPSHOT

View File

@ -104,6 +104,7 @@
"in" : "query", "in" : "query",
"description" : "Status values that need to be considered for filter", "description" : "Status values that need to be considered for filter",
"required" : true, "required" : true,
"style" : "form",
"explode" : false, "explode" : false,
"schema" : { "schema" : {
"type" : "array", "type" : "array",
@ -157,6 +158,7 @@
"in" : "query", "in" : "query",
"description" : "Tags to filter by", "description" : "Tags to filter by",
"required" : true, "required" : true,
"style" : "form",
"explode" : false, "explode" : false,
"schema" : { "schema" : {
"type" : "array", "type" : "array",