forked from loafle/openapi-generator-original
[html2] Fix import statements for most languages (#4243)
* [html2] Clean up namespace issues in code samples * pull c# and php package namespace from --additional-properties arg phpInvokerPackage arg now sets the PHP namespace and packageName sets the CSharp namespace. invokerPackage still works for Java and Android namespace.
This commit is contained in:
@@ -16,6 +16,9 @@ public class CodegenConstants {
|
||||
public static final String INVOKER_PACKAGE = "invokerPackage";
|
||||
public static final String INVOKER_PACKAGE_DESC = "root package for generated code";
|
||||
|
||||
public static final String PHP_INVOKER_PACKAGE = "phpInvokerPackage";
|
||||
public static final String PHP_INVOKER_PACKAGE_DESC = "root package for generated php code";
|
||||
|
||||
public static final String GROUP_ID = "groupId";
|
||||
public static final String GROUP_ID_DESC = "groupId in generated pom.xml";
|
||||
|
||||
|
||||
@@ -7,17 +7,23 @@ import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.Info;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String invokerPackage = "io.swagger.client"; // default for Java and Android
|
||||
protected String phpInvokerPackage = "Swagger\\Client"; // default for PHP
|
||||
protected String packageName = "IO.Swagger"; // default for C#
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String jsProjectName;
|
||||
protected String jsModuleName;
|
||||
|
||||
public StaticHtml2Generator() {
|
||||
super();
|
||||
@@ -33,6 +39,8 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
cliOptions.add(new CliOption("licenseInfo", "a short description of the license"));
|
||||
cliOptions.add(new CliOption("licenseUrl", "a URL pointing to the full license"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PHP_INVOKER_PACKAGE, CodegenConstants.PHP_INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "C# package name"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
@@ -44,6 +52,8 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
additionalProperties.put("licenseInfo", "All rights reserved");
|
||||
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
additionalProperties.put(CodegenConstants.PHP_INVOKER_PACKAGE, phpInvokerPackage);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
@@ -101,6 +111,29 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
super.preprocessSwagger(swagger);
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (StringUtils.isBlank(jsProjectName) && info.getTitle() != null) {
|
||||
// when jsProjectName is not specified, generate it from info.title
|
||||
jsProjectName = sanitizeName(dashize(info.getTitle()));
|
||||
}
|
||||
}
|
||||
|
||||
// default values
|
||||
if (StringUtils.isBlank(jsProjectName)) {
|
||||
jsProjectName = "swagger-js-client";
|
||||
}
|
||||
if (StringUtils.isBlank(jsModuleName)) {
|
||||
jsModuleName = camelize(underscore(jsProjectName));
|
||||
}
|
||||
|
||||
additionalProperties.put("jsProjectName", jsProjectName);
|
||||
additionalProperties.put("jsModuleName", jsModuleName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
|
||||
Reference in New Issue
Block a user