diff --git a/pom.xml b/pom.xml index 97ee3a0602..1c2286b80d 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.swagger.codegen.v3 swagger-codegen-generators - 1.0.27-SNAPSHOT + 1.0.28-SNAPSHOT jar @@ -252,10 +252,10 @@ - 3.0.27-SNAPSHOT - 2.0.26 - 2.1.9 - 2.11.4 + 3.0.28-SNAPSHOT + 2.0.27 + 2.1.10 + 2.12.1 2.11.1 3.3.0 2.4 diff --git a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java index 3273c05a07..326fb5d306 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java +++ b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java @@ -1358,12 +1358,7 @@ public CodegenModel fromModel(String name, Schema schema, Map al addParentContainer(codegenModel, name, schema); } else if (schema instanceof MapSchema) { - codegenModel.getVendorExtensions().put(CodegenConstants.IS_MAP_CONTAINER_EXT_NAME, Boolean.TRUE); - codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE); - addParentContainer(codegenModel, name, schema); - if (hasSchemaProperties(schema) || hasTrueAdditionalProperties(schema)) { - addAdditionPropertiesToCodeGenModel(codegenModel, schema); - } + processMapSchema(codegenModel, name, schema); } else if (schema instanceof ComposedSchema) { @@ -1493,6 +1488,15 @@ else if (schema instanceof ComposedSchema) { return codegenModel; } + protected void processMapSchema(CodegenModel codegenModel, String name, Schema schema) { + codegenModel.getVendorExtensions().put(CodegenConstants.IS_MAP_CONTAINER_EXT_NAME, Boolean.TRUE); + codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE); + addParentContainer(codegenModel, name, schema); + if (hasSchemaProperties(schema) || hasTrueAdditionalProperties(schema)) { + addAdditionPropertiesToCodeGenModel(codegenModel, schema); + } + } + /** * Recursively look for a discriminator in the interface tree */ diff --git a/src/main/java/io/swagger/codegen/v3/generators/examples/ExampleGenerator.java b/src/main/java/io/swagger/codegen/v3/generators/examples/ExampleGenerator.java index c90c599d34..ea1358a14d 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/examples/ExampleGenerator.java +++ b/src/main/java/io/swagger/codegen/v3/generators/examples/ExampleGenerator.java @@ -195,6 +195,10 @@ private Object resolveSchemaToExample(String propertyName, String mediaType, Sch Schema innerType = ((ArraySchema) schema).getItems(); if (innerType != null) { int arrayLength = schema.getMaxItems() != null ? schema.getMaxItems() : 2; + if (arrayLength > 10) { + logger.warn("value of maxItems of property {} is {}; limiting to 10 examples", schema, arrayLength); + arrayLength = 10; + } Object[] objectProperties = new Object[arrayLength]; Object objProperty = resolveSchemaToExample(propertyName, mediaType, innerType, processedModels); for(int i=0; i < arrayLength; i++) { diff --git a/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java index cad0c19ddf..c77711db1a 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java @@ -876,6 +876,11 @@ protected List> modelInheritanceSupport(List allModels) { Map parent = new HashMap<>(); parent.put("classname", parentModel.classname); List childrenModels = byParent.get(parentModel); + + if (childrenModels == null || childrenModels.isEmpty()) { + continue; + } + for (CodegenModel model : childrenModels) { Map child = new HashMap<>(); child.put("name", model.name); diff --git a/src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java index fb5937edef..f37df9ccb1 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java @@ -11,6 +11,8 @@ import io.swagger.v3.oas.models.media.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.github.jknack.handlebars.helper.StringHelpers; +import com.github.jknack.handlebars.Handlebars; import java.io.File; import java.util.Arrays; @@ -506,6 +508,12 @@ public String toVarName(String name) { return super.toVarName(sanitizeKotlinSpecificNames(name)); } + @Override + public void addHandlebarHelpers(Handlebars handlebars) { + super.addHandlebarHelpers(handlebars); + handlebars.registerHelpers(StringHelpers.class); + } + /** * Provides a strongly typed declaration for simple arrays of some type and arrays of arrays of some type. * diff --git a/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinServerCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinServerCodegen.java index 414166b90c..7d8800b51e 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinServerCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinServerCodegen.java @@ -18,8 +18,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import com.github.jknack.handlebars.helper.StringHelpers; -import com.github.jknack.handlebars.Handlebars; import org.apache.commons.lang3.StringUtils; import static java.util.Collections.singletonMap; @@ -228,12 +226,6 @@ public void processOpts() { supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt")); } - @Override - public void addHandlebarHelpers(Handlebars handlebars) { - super.addHandlebarHelpers(handlebars); - handlebars.registerHelpers(StringHelpers.class); - } - @Override public String getDefaultTemplateDir() { return "kotlin-server"; diff --git a/src/main/java/io/swagger/codegen/v3/generators/php/PhpClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/php/PhpClientCodegen.java index 682e6cb869..b0cb199fa3 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/php/PhpClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/php/PhpClientCodegen.java @@ -2,6 +2,7 @@ import io.swagger.codegen.v3.CliOption; import io.swagger.codegen.v3.CodegenConstants; +import io.swagger.codegen.v3.CodegenModel; import io.swagger.codegen.v3.CodegenOperation; import io.swagger.codegen.v3.CodegenParameter; import io.swagger.codegen.v3.CodegenProperty; @@ -9,25 +10,32 @@ import io.swagger.codegen.v3.CodegenType; import io.swagger.codegen.v3.SupportingFile; import io.swagger.codegen.v3.generators.DefaultCodegenConfig; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.MapSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.parser.util.SchemaTypeUtil; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; -import java.util.Arrays; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.HashSet; import java.util.regex.Matcher; -import io.swagger.v3.oas.models.media.*; -import io.swagger.v3.oas.models.security.SecurityScheme; -import io.swagger.v3.parser.util.SchemaTypeUtil; -import org.apache.commons.lang3.StringUtils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import static io.swagger.codegen.v3.generators.handlebars.ExtensionHelper.getBooleanValue; public class PhpClientCodegen extends DefaultCodegenConfig { @@ -444,6 +452,12 @@ public void setComposerProjectName(String composerProjectName) { this.composerProjectName = composerProjectName; } + @Override + protected void processMapSchema(CodegenModel codegenModel, String name, Schema schema) { + super.processMapSchema(codegenModel, name, schema); + addVars(codegenModel, schema.getProperties(), schema.getRequired()); + } + @Override public String toVarName(String name) { // sanitize name diff --git a/src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java index b11e964150..2eadf6071e 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java @@ -174,7 +174,8 @@ public void processOpts() { } if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) { - setProjectName((String) additionalProperties.get(CodegenConstants.PROJECT_NAME)); + String projectName = (String) additionalProperties.get(CodegenConstants.PROJECT_NAME); + setProjectName(projectName.replaceAll("[^a-zA-Z0-9\\s\\-_]","")); } else { // default: set project based on package name @@ -470,6 +471,10 @@ public String toParamName(String name) { @Override public String toModelName(String name) { + if (name == null) { + // sanitizeName will return "Object" for null, but this is called "object" in python + return "object"; + } name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // remove dollar sign name = name.replaceAll("$", ""); diff --git a/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java index ff3598be8e..b0b329a1cf 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java @@ -45,10 +45,12 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode public static final String NG_VERSION = "ngVersion"; public static final String NG_PACKAGR = "useNgPackagr"; public static final String PROVIDED_IN_ROOT ="providedInRoot"; + public static final String KEBAB_FILE_NAME ="kebab-file-name"; protected String npmName = null; protected String npmVersion = "1.0.0"; protected String npmRepository = null; + protected boolean kebabFileNaming; public TypeScriptAngularClientCodegen() { super(); @@ -121,20 +123,6 @@ public void processOpts() { additionalProperties.put(NG_PACKAGR, true); } - // Set the typescript version compatible to the Angular version - if (ngVersion.atLeast("8.0.0")) { - additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0"); - } else if (ngVersion.atLeast("7.0.0")) { - additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0"); - } else if (ngVersion.atLeast("6.0.0")) { - additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0"); - } else if (ngVersion.atLeast("5.0.0")) { - additionalProperties.put("tsVersion", ">=2.1.5 <2.7.0"); - } else { - // Angular v2-v4 requires typescript ">=2.1.5 <2.8" - additionalProperties.put("tsVersion", ">=2.1.5 <2.8.0"); - } - // Set the rxJS version compatible to the Angular version if (ngVersion.atLeast("8.0.0")) { additionalProperties.put("rxjsVersion", "6.5.0"); @@ -153,6 +141,11 @@ public void processOpts() { supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts")); } + // Version after Angular 10 require ModuleWithProviders to be generic. Compatible from version 7. + if (ngVersion.atLeast("7.0.0")) { + additionalProperties.put("genericModuleWithProviders", true); + } + // for Angular 2 AOT support we will use good-old ngc, // Angular Package format wasn't invented at this time and building was much more easier if (!ngVersion.atLeast("4.0.0")) { @@ -167,50 +160,6 @@ public void processOpts() { // Libraries generated with v2.x of ng-packagr will ship with AoT metadata in v4, which is intended for Angular v5 (and Angular v6). additionalProperties.put("useOldNgPackagr", !ngVersion.atLeast("5.0.0")); - // Specific ng-packagr configuration - if (ngVersion.atLeast("8.0.0")) { - additionalProperties.put("ngPackagrVersion", "5.4.0"); - additionalProperties.put("tsickleVersion", "0.35.0"); - } else if (ngVersion.atLeast("7.0.0")) { - // compatible versions with typescript version - additionalProperties.put("ngPackagrVersion", "5.1.0"); - additionalProperties.put("tsickleVersion", "0.34.0"); - } else if (ngVersion.atLeast("6.0.0")) { - // compatible versions with typescript version - additionalProperties.put("ngPackagrVersion", "3.0.6"); - additionalProperties.put("tsickleVersion", "0.32.1"); - } else if (ngVersion.atLeast("5.0.0")) { - // compatible versions with typescript version - additionalProperties.put("ngPackagrVersion", "2.4.5"); - additionalProperties.put("tsickleVersion", "0.27.5"); - } else { - // Angular versions prior to v5 - additionalProperties.put("ngPackagrVersion", "1.6.0"); - } - - // set zone.js version - if (ngVersion.atLeast("8.0.0")) { - additionalProperties.put("zonejsVersion", "0.9.1"); - } else if (ngVersion.atLeast("5.0.0")) { - // compatible versions to Angular 5+ - additionalProperties.put("zonejsVersion", "0.8.26"); - } else { - // Angular versions prior to v5 - additionalProperties.put("zonejsVersion", "0.7.6"); - } - - // set http client usage - if (ngVersion.atLeast("8.0.0")) { - additionalProperties.put("useHttpClient", true); - additionalProperties.put("useHttpClientPackage", false); - } else if (ngVersion.atLeast("4.3.0")) { - additionalProperties.put("useHttpClient", true); - additionalProperties.put("useHttpClientPackage", true); - } else { - additionalProperties.put("useHttpClient", false); - additionalProperties.put("useHttpClientPackage", false); - } - if (additionalProperties.containsKey(PROVIDED_IN_ROOT) && !ngVersion.atLeast("6.0.0")) { additionalProperties.put(PROVIDED_IN_ROOT,false); } @@ -219,7 +168,7 @@ public void processOpts() { additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0")); if (additionalProperties.containsKey(NPM_NAME)) { - addNpmPackageGeneration(); + addNpmPackageGeneration(ngVersion); } if (additionalProperties.containsKey(WITH_INTERFACES)) { @@ -229,6 +178,8 @@ public void processOpts() { } } + kebabFileNaming = Boolean.parseBoolean(String.valueOf(additionalProperties.get(KEBAB_FILE_NAME))); + } private SemVer determineNgVersion() { @@ -243,7 +194,7 @@ private SemVer determineNgVersion() { return ngVersion; } - private void addNpmPackageGeneration() { + private void addNpmPackageGeneration(SemVer ngVersion) { if (additionalProperties.containsKey(NPM_NAME)) { this.setNpmName(additionalProperties.get(NPM_NAME).toString()); } @@ -262,6 +213,60 @@ private void addNpmPackageGeneration() { this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString()); } + additionalProperties.put("useRxJS6", true); + additionalProperties.put("useHttpClient", true); + additionalProperties.put("useHttpClientPackage", false); + if (ngVersion.atLeast("11.0.0")) { + additionalProperties.put("tsVersion", ">=4.0.0 <4.1.0"); + additionalProperties.put("rxjsVersion", "6.6.0"); + additionalProperties.put("ngPackagrVersion", "11.0.2"); + additionalProperties.put("tsickleVersion", "0.39.1"); + additionalProperties.put("zonejsVersion", "0.11.3"); + } else if (ngVersion.atLeast("10.0.0")) { + additionalProperties.put("tsVersion", ">=3.9.2 <4.0.0"); + additionalProperties.put("rxjsVersion", "6.6.0"); + additionalProperties.put("ngPackagrVersion", "10.0.3"); + additionalProperties.put("tsickleVersion", "0.39.1"); + additionalProperties.put("zonejsVersion", "0.10.2"); + } else if (ngVersion.atLeast("9.0.0")) { + additionalProperties.put("tsVersion", ">=3.6.0 <3.8.0"); + additionalProperties.put("rxjsVersion", "6.5.3"); + additionalProperties.put("ngPackagrVersion", "9.0.1"); + additionalProperties.put("tsickleVersion", "0.38.0"); + additionalProperties.put("zonejsVersion", "0.10.2"); + } else if (ngVersion.atLeast("8.0.0")) { + additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0"); + additionalProperties.put("rxjsVersion", "6.5.0"); + additionalProperties.put("ngPackagrVersion", "5.4.0"); + additionalProperties.put("tsickleVersion", "0.35.0"); + additionalProperties.put("zonejsVersion", "0.9.1"); + } else if (ngVersion.atLeast("7.0.0")) { + additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0"); + additionalProperties.put("rxjsVersion", "6.3.0"); + additionalProperties.put("ngPackagrVersion", "5.1.0"); + additionalProperties.put("tsickleVersion", "0.34.0"); + additionalProperties.put("zonejsVersion", "0.8.26"); + + additionalProperties.put("useHttpClientPackage", true); + } else if (ngVersion.atLeast("6.0.0")) { + additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0"); + additionalProperties.put("rxjsVersion", "6.1.0"); + additionalProperties.put("ngPackagrVersion", "3.0.6"); + additionalProperties.put("tsickleVersion", "0.32.1"); + additionalProperties.put("zonejsVersion", "0.8.26"); + + additionalProperties.put("useHttpClientPackage", true); + } else { + additionalProperties.put("tsVersion", ">=2.1.5 and <2.8"); + additionalProperties.put("rxjsVersion", "6.1.0"); + additionalProperties.put("ngPackagrVersion", "3.0.6"); + additionalProperties.put("tsickleVersion", "0.32.1"); + additionalProperties.put("zonejsVersion", "0.8.26"); + + additionalProperties.put("useRxJS6", false); + additionalProperties.put("useHttpClientPackage", true); + } + //Files for building our lib supportingFiles.add(new SupportingFile("README.mustache", getIndexDirectory(), "README.md")); supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json")); @@ -496,6 +501,9 @@ public String toApiFilename(String name) { if (name.length() == 0) { return "default.service"; } + if (kebabFileNaming) { + return dashize(name); + } return camelize(name, true) + ".service"; } @@ -506,6 +514,9 @@ public String toApiImport(String name) { @Override public String toModelFilename(String name) { + if (kebabFileNaming) { + return dashize(name); + } return camelize(toModelName(name), true); } diff --git a/src/main/resources/handlebars/aspnetcore/model.mustache b/src/main/resources/handlebars/aspnetcore/model.mustache index 219a1e110a..b1fbc3722a 100644 --- a/src/main/resources/handlebars/aspnetcore/model.mustache +++ b/src/main/resources/handlebars/aspnetcore/model.mustache @@ -28,7 +28,12 @@ namespace {{packageName}}.Models {{/description}} {{#required}} [Required] - {{/required}} + {{/required}}{{#pattern}} + [RegularExpression("{{{pattern}}}")]{{/pattern}}{{#minLength}}{{#maxLength}} + [StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} + [MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} + [MaxLength({{maxLength}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}} + [Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}} [DataMember(Name="{{baseName}}")] {{#isEnum}} public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; } diff --git a/src/main/resources/handlebars/python/api_client.mustache b/src/main/resources/handlebars/python/api_client.mustache index e46230fd75..5c62fff24f 100644 --- a/src/main/resources/handlebars/python/api_client.mustache +++ b/src/main/resources/handlebars/python/api_client.mustache @@ -530,10 +530,14 @@ class ApiClient(object): filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition).group(1) path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - + response_data = response.data + with open(path, "wb") as f: + if isinstance(response_data, str): + # change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + else: + f.write(response_data) return path def __deserialize_primitive(self, data, klass): diff --git a/src/main/resources/handlebars/python/rest.mustache b/src/main/resources/handlebars/python/rest.mustache index 6c5dd3f2b6..af0603ace7 100644 --- a/src/main/resources/handlebars/python/rest.mustache +++ b/src/main/resources/handlebars/python/rest.mustache @@ -207,11 +207,6 @@ class RESTClientObject(object): if _preload_content: r = RESTResponse(r) - # In the python 3, the response.data is bytes. - # we need to decode it to string. - if six.PY3: - r.data = r.data.decode('utf8') - # log response body logger.debug("response body: %s", r.data) diff --git a/src/main/resources/handlebars/typescript-angular/api.module.mustache b/src/main/resources/handlebars/typescript-angular/api.module.mustache index 06dad036e6..2953814b3c 100644 --- a/src/main/resources/handlebars/typescript-angular/api.module.mustache +++ b/src/main/resources/handlebars/typescript-angular/api.module.mustache @@ -18,7 +18,7 @@ import { {{classname}} } from './{{importPath}}'; {{/hasMore}}{{/apis}}{{/apiInfo}} ] }) export class ApiModule { - public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders { + public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders{{#genericModuleWithProviders}}{{/genericModuleWithProviders}} { return { ngModule: ApiModule, providers: [ { provide: Configuration, useFactory: configurationFactory } ] diff --git a/src/main/resources/handlebars/typescript-angular/package.mustache b/src/main/resources/handlebars/typescript-angular/package.mustache index 5735880855..2b2a605a80 100644 --- a/src/main/resources/handlebars/typescript-angular/package.mustache +++ b/src/main/resources/handlebars/typescript-angular/package.mustache @@ -38,8 +38,7 @@ "@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}} "ng-packagr": "^{{ngPackagrVersion}}",{{/useNgPackagr}} "reflect-metadata": "^0.1.3", - "rxjs": "^{{rxjsVersion}}",{{#useNgPackagr}}{{^useOldNgPackagr}} - "tsickle": "^{{tsickleVersion}}",{{/useOldNgPackagr}}{{/useNgPackagr}} + "rxjs": "^{{rxjsVersion}}", "typescript": "{{{tsVersion}}}", "zone.js": "^{{zonejsVersion}}" }{{#npmRepository}},{{/npmRepository}} diff --git a/src/main/resources/handlebars/typescript-axios/package.mustache b/src/main/resources/handlebars/typescript-axios/package.mustache index da07d370fa..6c6114ebcf 100644 --- a/src/main/resources/handlebars/typescript-axios/package.mustache +++ b/src/main/resources/handlebars/typescript-axios/package.mustache @@ -18,7 +18,7 @@ "prepublishOnly": "npm run build" }, "dependencies": { - "axios": "^0.19.2" + "axios": "^0.21.1" }, "devDependencies": { "@types/node": "^12.11.5", diff --git a/src/test/java/io/swagger/codegen/v3/generators/python/PythonClientCodegenTest.java b/src/test/java/io/swagger/codegen/v3/generators/python/PythonClientCodegenTest.java new file mode 100644 index 0000000000..866f7ea714 --- /dev/null +++ b/src/test/java/io/swagger/codegen/v3/generators/python/PythonClientCodegenTest.java @@ -0,0 +1,41 @@ +package io.swagger.codegen.v3.generators.python; + +import io.swagger.codegen.v3.generators.AbstractCodegenTest; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class PythonClientCodegenTest extends AbstractCodegenTest { + @Test + public void testToModelName() { + PythonClientCodegen pythonClientCodegen = new PythonClientCodegen(); + + // no type - this is 'object' in Python + Assert.assertEquals(pythonClientCodegen.toModelName(null), "object"); + // assume this is a model type - "null" is not special in Python + Assert.assertEquals(pythonClientCodegen.toModelName("null"), "Null"); + // reserved word + Assert.assertEquals(pythonClientCodegen.toModelName("return"), "ModelReturn"); + Assert.assertEquals(pythonClientCodegen.toModelName("None"), "ModelNone"); + // $ + Assert.assertEquals(pythonClientCodegen.toModelName("my$result"), "Myresult"); + // Starts with number + Assert.assertEquals(pythonClientCodegen.toModelName("999Bad"), "Model999Bad"); + // Camel Case + Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "CamelCase"); + } + + @Test + public void testToModelNamePrefixSuffix() { + PythonClientCodegen pythonClientCodegen = new PythonClientCodegen(); + pythonClientCodegen.setModelNamePrefix("xprefixx"); + + // Camel Case + Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "XprefixxCamelCase"); + + pythonClientCodegen.setModelNamePrefix(null); + pythonClientCodegen.setModelNameSuffix("xsuffixx"); + + // Camel Case + Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "CamelCaseXsuffixx"); + } +}