From b4bc0be0cbf7c47b0ff94ffc9acaf4bbc8b9eba1 Mon Sep 17 00:00:00 2001 From: Guo Huang Date: Tue, 12 Apr 2016 17:05:01 -0700 Subject: [PATCH] fixed all model test errors --- .../codegen/languages/GoClientCodegen.java | 96 ++++++++++++++++++- .../codegen/go/GoClientOptionsTest.java | 36 +++---- .../options/GoClientOptionsProvider.java | 9 +- 3 files changed, 122 insertions(+), 19 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java index 9af98555ff8..3cf8cb7133e 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/GoClientCodegen.java @@ -24,6 +24,15 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { protected String packageName = "swagger"; protected String packageVersion = "1.0.0"; + protected String invokerPackage = "Swagger\\Client"; + protected String composerVendorName = "swagger"; + protected String composerProjectName = "swagger-client"; + protected String packagePath = "SwaggerClient-php"; + protected String artifactVersion = "1.0.0"; + protected String srcBasePath = "lib"; + protected String variableNamingConvention= "snake_case"; + protected String apiDocPath = "docs/"; + protected String modelDocPath = "docs/"; public CodegenType getTag() { return CodegenType.CLIENT; @@ -109,12 +118,70 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { .defaultValue("swagger")); cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.") .defaultValue("1.0.0")); + cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC)); + cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC)); + cliOptions.add(new CliOption(VARIABLE_NAMING_CONVENTION, "naming convention of variable name, e.g. camelCase.") + .defaultValue("snake_case")); + cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, "The main namespace to use for all classes. e.g. Yay\\Pets")); + cliOptions.add(new CliOption(PACKAGE_PATH, "The main package name for classes. e.g. GeneratedPetstore")); + cliOptions.add(new CliOption(SRC_BASE_PATH, "The directory under packagePath to serve as source root.")); + cliOptions.add(new CliOption(COMPOSER_VENDOR_NAME, "The vendor name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. yaypets. IMPORTANT NOTE (2016/03): composerVendorName will be deprecated and replaced by gitUserId in the next swagger-codegen release")); + cliOptions.add(new CliOption(COMPOSER_PROJECT_NAME, "The project name used in the composer package name. The template uses {{composerVendorName}}/{{composerProjectName}} for the composer package name. e.g. petstore-client. IMPORTANT NOTE (2016/03): composerProjectName will be deprecated and replaced by gitRepoId in the next swagger-codegen release")); + cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "The version to use in the composer package version field. e.g. 1.2.3")); } @Override public void processOpts() { - //super.processOpts(); + super.processOpts(); + + if (additionalProperties.containsKey(PACKAGE_PATH)) { + this.setPackagePath((String) additionalProperties.get(PACKAGE_PATH)); + } else { + additionalProperties.put(PACKAGE_PATH, packagePath); + } + + if (additionalProperties.containsKey(SRC_BASE_PATH)) { + this.setSrcBasePath((String) additionalProperties.get(SRC_BASE_PATH)); + } else { + additionalProperties.put(SRC_BASE_PATH, srcBasePath); + } + + if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) { + this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE)); + } else { + additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage); + } + + if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) { + additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); + } + + if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) { + additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); + } + + if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) { + this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME)); + } else { + additionalProperties.put(COMPOSER_PROJECT_NAME, composerProjectName); + } + + if (additionalProperties.containsKey(COMPOSER_VENDOR_NAME)) { + this.setComposerVendorName((String) additionalProperties.get(COMPOSER_VENDOR_NAME)); + } else { + additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName); + } + + if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) { + this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION)); + } else { + additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion); + } + + if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) { + this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION)); + } if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); @@ -342,4 +409,31 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig { this.packageVersion = packageVersion; } + public void setInvokerPackage(String invokerPackage) { + this.invokerPackage = invokerPackage; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public void setPackagePath(String packagePath) { + this.packagePath = packagePath; + } + + public void setSrcBasePath(String srcBasePath) { + this.srcBasePath = srcBasePath; + } + + public void setParameterNamingConvention(String variableNamingConvention) { + this.variableNamingConvention = variableNamingConvention; + } + + public void setComposerVendorName(String composerVendorName) { + this.composerVendorName = composerVendorName; + } + + public void setComposerProjectName(String composerProjectName) { + this.composerProjectName = composerProjectName; + } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/go/GoClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/go/GoClientOptionsTest.java index b5f051df6bc..e307ac3ca5c 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/go/GoClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/go/GoClientOptionsTest.java @@ -26,26 +26,30 @@ public class GoClientOptionsTest extends AbstractOptionsTest { @Override protected void setExpectations() { new Expectations(clientCodegen) {{ -/* clientCodegen.setModelPackage(GoClientOptionsProvider.MODEL_PACKAGE_VALUE); + clientCodegen.setModelPackage(GoClientOptionsProvider.MODEL_PACKAGE_VALUE); times = 1; clientCodegen.setApiPackage(GoClientOptionsProvider.API_PACKAGE_VALUE); times = 1; - clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(GoClientOptionsProvider.SORT_PARAMS_VALUE)); - times = 1;*/ - //clientCodegen.setParameterNamingConvention(GoClientOptionsProvider.VARIABLE_NAMING_CONVENTION_VALUE); + //clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(GoClientOptionsProvider.SORT_PARAMS_VALUE)); //times = 1; - //clientCodegen.setInvokerPackage(GoClientOptionsProvider.INVOKER_PACKAGE_VALUE); - //times = 1; - //clientCodegen.setPackagePath(GoClientOptionsProvider.PACKAGE_PATH_VALUE); - //times = 1; - //clientCodegen.setSrcBasePath(GoClientOptionsProvider.SRC_BASE_PATH_VALUE); - //times = 1; - // clientCodegen.setComposerVendorName(GoClientOptionsProvider.COMPOSER_VENDOR_NAME_VALUE); - // times = 1; - // clientCodegen.setComposerProjectName(GoClientOptionsProvider.COMPOSER_PROJECT_NAME_VALUE); - // times = 1; -/* clientCodegen.setArtifactVersion(GoClientOptionsProvider.ARTIFACT_VERSION_VALUE); - times = 1;*/ + clientCodegen.setParameterNamingConvention(GoClientOptionsProvider.VARIABLE_NAMING_CONVENTION_VALUE); + times = 1; + clientCodegen.setInvokerPackage(GoClientOptionsProvider.INVOKER_PACKAGE_VALUE); + times = 1; + clientCodegen.setPackagePath(GoClientOptionsProvider.PACKAGE_PATH_VALUE); + times = 1; + clientCodegen.setSrcBasePath(GoClientOptionsProvider.SRC_BASE_PATH_VALUE); + times = 1; + clientCodegen.setComposerVendorName(GoClientOptionsProvider.COMPOSER_VENDOR_NAME_VALUE); + times = 1; + clientCodegen.setComposerProjectName(GoClientOptionsProvider.COMPOSER_PROJECT_NAME_VALUE); + times = 1; + clientCodegen.setArtifactVersion(GoClientOptionsProvider.ARTIFACT_VERSION_VALUE); + times = 1; + clientCodegen.setPackageVersion(GoClientOptionsProvider.PACKAGE_VERSION_VALUE); + times = 1; + clientCodegen.setPackageName(GoClientOptionsProvider.PACKAGE_NAME_VALUE); + times = 1; }}; } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoClientOptionsProvider.java index cfc5f934cc8..7383043bc64 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/GoClientOptionsProvider.java @@ -20,6 +20,9 @@ public class GoClientOptionsProvider implements OptionsProvider { public static final String COMPOSER_PROJECT_NAME_VALUE = "swagger-client-go"; public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT"; + public static final String PACKAGE_VERSION_VALUE = "1.0.0-TEST"; + public static final String PACKAGE_NAME_VALUE = "TEST"; + @Override public String getLanguage() { return "go"; @@ -30,8 +33,8 @@ public class GoClientOptionsProvider implements OptionsProvider { ImmutableMap.Builder builder = new ImmutableMap.Builder(); return builder.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE) .put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE) - .put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) - .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) + //.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) + //.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) .put(GoClientCodegen.VARIABLE_NAMING_CONVENTION, VARIABLE_NAMING_CONVENTION_VALUE) .put(CodegenConstants.INVOKER_PACKAGE, INVOKER_PACKAGE_VALUE) .put(GoClientCodegen.PACKAGE_PATH, PACKAGE_PATH_VALUE) @@ -39,6 +42,8 @@ public class GoClientOptionsProvider implements OptionsProvider { .put(GoClientCodegen.COMPOSER_VENDOR_NAME, COMPOSER_VENDOR_NAME_VALUE) .put(GoClientCodegen.COMPOSER_PROJECT_NAME, COMPOSER_PROJECT_NAME_VALUE) .put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE) + .put(CodegenConstants.PACKAGE_VERSION, PACKAGE_VERSION_VALUE) + .put(CodegenConstants.PACKAGE_NAME, PACKAGE_NAME_VALUE) .build(); }