forked from loafle/openapi-generator-original
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:
parent
76aedca6b2
commit
24ea88495b
@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
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%
|
||||
|
@ -278,4 +278,5 @@ public class CodegenConstants {
|
||||
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 OPEN_API_SPEC_NAME = "openAPISpecName";
|
||||
}
|
@ -40,6 +40,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected String apiPath = "src";
|
||||
protected String packageName = "openapi";
|
||||
protected String openApiSpecName = "openapi";
|
||||
|
||||
public ErlangServerCodegen() {
|
||||
super();
|
||||
@ -47,13 +48,6 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// set the output folder here
|
||||
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.
|
||||
* 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.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).")
|
||||
.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
|
||||
* 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("utils.mustache", "", toSourceFilePath("utils", "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("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
@ -254,6 +269,10 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setOpenApiSpecName(String openApiSpecName) {
|
||||
this.openApiSpecName = openApiSpecName;
|
||||
}
|
||||
|
||||
protected String toHandlerName(String name) {
|
||||
return toModuleName(name) + "_handler";
|
||||
}
|
||||
|
@ -69,6 +69,6 @@ prepare_validator() ->
|
||||
|
||||
get_openapi_path() ->
|
||||
{ok, AppName} = application:get_application(?MODULE),
|
||||
filename:join({{packageName}}_utils:priv_dir(AppName), "openapi.json").
|
||||
filename:join({{packageName}}_utils:priv_dir(AppName), "{{{openAPISpecName}}}.json").
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
3.0.0-SNAPSHOT
|
||||
3.3.2-SNAPSHOT
|
@ -104,6 +104,7 @@
|
||||
"in" : "query",
|
||||
"description" : "Status values that need to be considered for filter",
|
||||
"required" : true,
|
||||
"style" : "form",
|
||||
"explode" : false,
|
||||
"schema" : {
|
||||
"type" : "array",
|
||||
@ -157,6 +158,7 @@
|
||||
"in" : "query",
|
||||
"description" : "Tags to filter by",
|
||||
"required" : true,
|
||||
"style" : "form",
|
||||
"explode" : false,
|
||||
"schema" : {
|
||||
"type" : "array",
|
||||
|
Loading…
x
Reference in New Issue
Block a user