From 6e4ee605ee5a8436f52fe0e7af8abea8277f98d4 Mon Sep 17 00:00:00 2001 From: bezineb5 Date: Sat, 18 Jul 2020 14:49:10 -0400 Subject: [PATCH 01/16] Templatized ModuleWithProviders in typescript-angular The call ModuleWithProviders requires a template: https://angular.io/api/core/ModuleWithProviders Apparently, in Angular 10, this is strictly enforced --- .../resources/handlebars/typescript-angular/api.module.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/handlebars/typescript-angular/api.module.mustache b/src/main/resources/handlebars/typescript-angular/api.module.mustache index 06dad036e6..3e77ae57c8 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 { return { ngModule: ApiModule, providers: [ { provide: Configuration, useFactory: configurationFactory } ] From 3c0177b356da8e7de8ecded9408016264a675c02 Mon Sep 17 00:00:00 2001 From: bezineb5 Date: Sun, 6 Dec 2020 12:56:15 -0500 Subject: [PATCH 02/16] Keep compatibility with angular <10 --- .../resources/handlebars/typescript-angular/api.module.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/handlebars/typescript-angular/api.module.mustache b/src/main/resources/handlebars/typescript-angular/api.module.mustache index 3e77ae57c8..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 } ] From 94aab1232dd47f28bd3e21db411302d858370176 Mon Sep 17 00:00:00 2001 From: bezineb5 Date: Sun, 6 Dec 2020 13:02:14 -0500 Subject: [PATCH 03/16] Automatically add templating if version is at least 7 --- .../typescript/TypeScriptAngularClientCodegen.java | 5 +++++ 1 file changed, 5 insertions(+) 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..702045a3c1 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 @@ -152,6 +152,11 @@ public void processOpts() { if (!ngVersion.atLeast("4.3.0")) { 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 From ab0abe51300b51e4797a877860fa4e0fb9bd5427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Pucu=C5=82ek?= Date: Mon, 8 Mar 2021 14:38:10 +0100 Subject: [PATCH 04/16] Register StringHelpers Handlebars in AbstractKotlinCodegen.java --- .../v3/generators/kotlin/AbstractKotlinCodegen.java | 8 ++++++++ .../codegen/v3/generators/kotlin/KotlinClientCodegen.java | 1 + .../codegen/v3/generators/kotlin/KotlinServerCodegen.java | 8 -------- 3 files changed, 9 insertions(+), 8 deletions(-) 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/KotlinClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java index b55c430108..8ca2cb1c0d 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java @@ -1,6 +1,7 @@ package io.swagger.codegen.v3.generators.kotlin; import com.github.jknack.handlebars.Handlebars; +import com.github.jknack.handlebars.helper.StringHelpers; import com.github.jknack.handlebars.helper.ConditionalHelpers; import io.swagger.codegen.v3.CliOption; import io.swagger.codegen.v3.CodegenType; 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"; From 7f85e59604b8680d8f6d16b21bd794b9d969e89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Pucu=C5=82ek?= Date: Tue, 9 Mar 2021 16:20:21 +0100 Subject: [PATCH 05/16] Remove unused import --- .../codegen/v3/generators/kotlin/KotlinClientCodegen.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java index 8ca2cb1c0d..b55c430108 100644 --- a/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java +++ b/src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java @@ -1,7 +1,6 @@ package io.swagger.codegen.v3.generators.kotlin; import com.github.jknack.handlebars.Handlebars; -import com.github.jknack.handlebars.helper.StringHelpers; import com.github.jknack.handlebars.helper.ConditionalHelpers; import io.swagger.codegen.v3.CliOption; import io.swagger.codegen.v3.CodegenType; From 2ab0ebcfcf7de0e5e19b8e9ffbe4253eded46734 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Wed, 23 Jun 2021 10:57:42 -0500 Subject: [PATCH 06/16] updated swager parser and core versions --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 84b9b9ce96..a0378ed871 100644 --- a/pom.xml +++ b/pom.xml @@ -253,8 +253,8 @@ 3.0.27-SNAPSHOT - 2.0.26 - 2.1.9 + 2.0.27-SNAPSHOT + 2.1.10-SNAPSHOT 2.12.1 2.11.1 3.3.0 From 7f6e7ee96af966c12a510d3b168f83206926ca43 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Fri, 25 Jun 2021 00:18:22 -0500 Subject: [PATCH 07/16] added data annotations on model properties. --- src/main/resources/handlebars/aspnetcore/model.mustache | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; } From 47bfec11de842873e2525b942c957d56a7cc918f Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Fri, 25 Jun 2021 22:32:12 -0500 Subject: [PATCH 08/16] removed all non valid characters for project name on python generated code --- .../codegen/v3/generators/python/PythonClientCodegen.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 08c4541a36..f7e5a894e9 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 From 05fb521c814e51efac2efc6f60daa82adf5305ea Mon Sep 17 00:00:00 2001 From: frantuma Date: Mon, 28 Jun 2021 14:46:57 +0200 Subject: [PATCH 09/16] prepare release 1.0.27 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index a0378ed871..e411b1f5ed 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.swagger.codegen.v3 swagger-codegen-generators - 1.0.27-SNAPSHOT + 1.0.27 jar @@ -252,9 +252,9 @@ - 3.0.27-SNAPSHOT - 2.0.27-SNAPSHOT - 2.1.10-SNAPSHOT + 3.0.27 + 2.0.27 + 2.1.10 2.12.1 2.11.1 3.3.0 From 75b57beea3494140cbc99f868b7a731f138d1478 Mon Sep 17 00:00:00 2001 From: frantuma Date: Mon, 28 Jun 2021 15:21:33 +0200 Subject: [PATCH 10/16] next snapshot 1.0.28-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e411b1f5ed..282bcba354 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.swagger.codegen.v3 swagger-codegen-generators - 1.0.27 + 1.0.28-SNAPSHOT jar From 0a2ac90d7f6cb23f079b8e76bf1cb3fdef8d050c Mon Sep 17 00:00:00 2001 From: frantuma Date: Mon, 28 Jun 2021 15:46:52 +0200 Subject: [PATCH 11/16] next codegen 3.0.28-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 282bcba354..1c2286b80d 100644 --- a/pom.xml +++ b/pom.xml @@ -252,7 +252,7 @@ - 3.0.27 + 3.0.28-SNAPSHOT 2.0.27 2.1.10 2.12.1 From a0294796db27080874ab3a6cb2f68e6caf66f2d2 Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Tue, 29 Jun 2021 11:15:49 -0500 Subject: [PATCH 12/16] fixed NPE on spring generator when using discriminator mapping --- .../io/swagger/codegen/v3/generators/java/SpringCodegen.java | 5 +++++ 1 file changed, 5 insertions(+) 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); From d0d1b55e890ca35bd925b0bbac97b241d7b6130b Mon Sep 17 00:00:00 2001 From: Ben Kelley Date: Tue, 6 Jul 2021 14:06:19 +1000 Subject: [PATCH 13/16] Fixed #10129 for swagger-codegen where python was getting the type "Object" when it should be "object" --- .../python/PythonClientCodegen.java | 4 ++ .../python/PythonClientCodegenTest.java | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/test/java/io/swagger/codegen/v3/generators/python/PythonClientCodegenTest.java 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 f7e5a894e9..eb7ba3b64a 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 @@ -469,6 +469,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/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"); + } +} From 8357c3e60f9a539f877526d81d04146dbbb6e196 Mon Sep 17 00:00:00 2001 From: Agossi <87424373+Agossi@users.noreply.github.com> Date: Wed, 14 Jul 2021 13:26:35 +0200 Subject: [PATCH 14/16] Fix for Issue #931 Fix for issue #931 , please review --- .../resources/handlebars/python/api_client.mustache | 12 ++++++++---- src/main/resources/handlebars/python/rest.mustache | 5 ----- 2 files changed, 8 insertions(+), 9 deletions(-) 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) From 28f68e4377c6cd349ce3d1b0d354e23b6fcc77bd Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Thu, 22 Jul 2021 22:31:06 -0500 Subject: [PATCH 15/16] added support for angular 8 to 11 versions --- .../TypeScriptAngularClientCodegen.java | 118 +++++++++--------- .../typescript-angular/package.mustache | 3 +- 2 files changed, 58 insertions(+), 63 deletions(-) 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 03ed083d69..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 @@ -123,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"); @@ -154,7 +140,7 @@ public void processOpts() { if (!ngVersion.atLeast("4.3.0")) { 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); @@ -174,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); } @@ -226,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)) { @@ -252,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()); } @@ -271,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")); 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}} From 6e128472b896e6eeb079efb7775f8ec5e8b1b04a Mon Sep 17 00:00:00 2001 From: Hugo Mercado Date: Wed, 28 Jul 2021 00:04:54 -0500 Subject: [PATCH 16/16] fixed missed properties --- .../v3/generators/DefaultCodegenConfig.java | 16 +++++---- .../v3/generators/php/PhpClientCodegen.java | 34 +++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) 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/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