Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario authored Jul 28, 2021
2 parents 55eb1f5 + d39f4ae commit 5c00898
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 102 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.0.28-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -252,9 +252,9 @@
</dependency>
</dependencies>
<properties>
<swagger-codegen-version>3.0.27-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.26</swagger-parser-version>
<swagger-core-version>2.1.9</swagger-core-version>
<swagger-codegen-version>3.0.28-SNAPSHOT</swagger-codegen-version>
<swagger-parser-version>2.0.27</swagger-parser-version>
<swagger-core-version>2.1.10</swagger-core-version>
<jackson-version>2.12.1</jackson-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,12 +1358,7 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> 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) {
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ protected List<Map<String, Object>> modelInheritanceSupport(List<?> allModels) {
Map<String, Object> parent = new HashMap<>();
parent.put("classname", parentModel.classname);
List<CodegenModel> childrenModels = byParent.get(parentModel);

if (childrenModels == null || childrenModels.isEmpty()) {
continue;
}

for (CodegenModel model : childrenModels) {
Map<String, Object> child = new HashMap<>();
child.put("name", model.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,40 @@

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;
import io.swagger.codegen.v3.CodegenSecurity;
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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -468,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("$", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -155,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")) {
Expand All @@ -169,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);
}
Expand All @@ -221,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)) {
Expand All @@ -247,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());
}
Expand All @@ -266,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"));
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/handlebars/aspnetcore/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/handlebars/python/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading

0 comments on commit 5c00898

Please sign in to comment.