Skip to content

Commit 87216b2

Browse files
authored
Merge branch 'master' into ft/js-es6-default-export
2 parents 05c1df0 + 8799694 commit 87216b2

File tree

13 files changed

+156
-87
lines changed

13 files changed

+156
-87
lines changed

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>io.swagger.codegen.v3</groupId>
1414
<artifactId>swagger-codegen-generators</artifactId>
15-
<version>1.0.27-SNAPSHOT</version>
15+
<version>1.0.28-SNAPSHOT</version>
1616
<packaging>jar</packaging>
1717

1818
<build>
@@ -252,10 +252,10 @@
252252
</dependency>
253253
</dependencies>
254254
<properties>
255-
<swagger-codegen-version>3.0.27-SNAPSHOT</swagger-codegen-version>
256-
<swagger-parser-version>2.0.26</swagger-parser-version>
257-
<swagger-core-version>2.1.9</swagger-core-version>
258-
<jackson-version>2.11.4</jackson-version>
255+
<swagger-codegen-version>3.0.28-SNAPSHOT</swagger-codegen-version>
256+
<swagger-parser-version>2.0.27</swagger-parser-version>
257+
<swagger-core-version>2.1.10</swagger-core-version>
258+
<jackson-version>2.12.1</jackson-version>
259259
<scala-version>2.11.1</scala-version>
260260
<felix-version>3.3.0</felix-version>
261261
<commons-io-version>2.4</commons-io-version>

src/main/java/io/swagger/codegen/v3/generators/examples/ExampleGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ private Object resolveSchemaToExample(String propertyName, String mediaType, Sch
195195
Schema innerType = ((ArraySchema) schema).getItems();
196196
if (innerType != null) {
197197
int arrayLength = schema.getMaxItems() != null ? schema.getMaxItems() : 2;
198+
if (arrayLength > 10) {
199+
logger.warn("value of maxItems of property {} is {}; limiting to 10 examples", schema, arrayLength);
200+
arrayLength = 10;
201+
}
198202
Object[] objectProperties = new Object[arrayLength];
199203
Object objProperty = resolveSchemaToExample(propertyName, mediaType, innerType, processedModels);
200204
for(int i=0; i < arrayLength; i++) {

src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,11 @@ protected List<Map<String, Object>> modelInheritanceSupport(List<?> allModels) {
876876
Map<String, Object> parent = new HashMap<>();
877877
parent.put("classname", parentModel.classname);
878878
List<CodegenModel> childrenModels = byParent.get(parentModel);
879+
880+
if (childrenModels == null || childrenModels.isEmpty()) {
881+
continue;
882+
}
883+
879884
for (CodegenModel model : childrenModels) {
880885
Map<String, Object> child = new HashMap<>();
881886
child.put("name", model.name);

src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import io.swagger.v3.oas.models.media.Schema;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
14+
import com.github.jknack.handlebars.helper.StringHelpers;
15+
import com.github.jknack.handlebars.Handlebars;
1416

1517
import java.io.File;
1618
import java.util.Arrays;
@@ -506,6 +508,12 @@ public String toVarName(String name) {
506508
return super.toVarName(sanitizeKotlinSpecificNames(name));
507509
}
508510

511+
@Override
512+
public void addHandlebarHelpers(Handlebars handlebars) {
513+
super.addHandlebarHelpers(handlebars);
514+
handlebars.registerHelpers(StringHelpers.class);
515+
}
516+
509517
/**
510518
* Provides a strongly typed declaration for simple arrays of some type and arrays of arrays of some type.
511519
*

src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinServerCodegen.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import java.util.Arrays;
1919
import java.util.List;
2020
import java.util.Map;
21-
import com.github.jknack.handlebars.helper.StringHelpers;
22-
import com.github.jknack.handlebars.Handlebars;
2321
import org.apache.commons.lang3.StringUtils;
2422

2523
import static java.util.Collections.singletonMap;
@@ -228,12 +226,6 @@ public void processOpts() {
228226
supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt"));
229227
}
230228

231-
@Override
232-
public void addHandlebarHelpers(Handlebars handlebars) {
233-
super.addHandlebarHelpers(handlebars);
234-
handlebars.registerHelpers(StringHelpers.class);
235-
}
236-
237229
@Override
238230
public String getDefaultTemplateDir() {
239231
return "kotlin-server";

src/main/java/io/swagger/codegen/v3/generators/python/PythonClientCodegen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ public void processOpts() {
174174
}
175175

176176
if (additionalProperties.containsKey(CodegenConstants.PROJECT_NAME)) {
177-
setProjectName((String) additionalProperties.get(CodegenConstants.PROJECT_NAME));
177+
String projectName = (String) additionalProperties.get(CodegenConstants.PROJECT_NAME);
178+
setProjectName(projectName.replaceAll("[^a-zA-Z0-9\\s\\-_]",""));
178179
}
179180
else {
180181
// default: set project based on package name
@@ -468,6 +469,10 @@ public String toParamName(String name) {
468469

469470
@Override
470471
public String toModelName(String name) {
472+
if (name == null) {
473+
// sanitizeName will return "Object" for null, but this is called "object" in python
474+
return "object";
475+
}
471476
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
472477
// remove dollar sign
473478
name = name.replaceAll("$", "");

src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptAngularClientCodegen.java

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
4545
public static final String NG_VERSION = "ngVersion";
4646
public static final String NG_PACKAGR = "useNgPackagr";
4747
public static final String PROVIDED_IN_ROOT ="providedInRoot";
48+
public static final String KEBAB_FILE_NAME ="kebab-file-name";
4849

4950
protected String npmName = null;
5051
protected String npmVersion = "1.0.0";
5152
protected String npmRepository = null;
53+
protected boolean kebabFileNaming;
5254

5355
public TypeScriptAngularClientCodegen() {
5456
super();
@@ -121,20 +123,6 @@ public void processOpts() {
121123
additionalProperties.put(NG_PACKAGR, true);
122124
}
123125

124-
// Set the typescript version compatible to the Angular version
125-
if (ngVersion.atLeast("8.0.0")) {
126-
additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0");
127-
} else if (ngVersion.atLeast("7.0.0")) {
128-
additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0");
129-
} else if (ngVersion.atLeast("6.0.0")) {
130-
additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0");
131-
} else if (ngVersion.atLeast("5.0.0")) {
132-
additionalProperties.put("tsVersion", ">=2.1.5 <2.7.0");
133-
} else {
134-
// Angular v2-v4 requires typescript ">=2.1.5 <2.8"
135-
additionalProperties.put("tsVersion", ">=2.1.5 <2.8.0");
136-
}
137-
138126
// Set the rxJS version compatible to the Angular version
139127
if (ngVersion.atLeast("8.0.0")) {
140128
additionalProperties.put("rxjsVersion", "6.5.0");
@@ -153,6 +141,11 @@ public void processOpts() {
153141
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
154142
}
155143

144+
// Version after Angular 10 require ModuleWithProviders to be generic. Compatible from version 7.
145+
if (ngVersion.atLeast("7.0.0")) {
146+
additionalProperties.put("genericModuleWithProviders", true);
147+
}
148+
156149
// for Angular 2 AOT support we will use good-old ngc,
157150
// Angular Package format wasn't invented at this time and building was much more easier
158151
if (!ngVersion.atLeast("4.0.0")) {
@@ -167,50 +160,6 @@ public void processOpts() {
167160
// Libraries generated with v2.x of ng-packagr will ship with AoT metadata in v4, which is intended for Angular v5 (and Angular v6).
168161
additionalProperties.put("useOldNgPackagr", !ngVersion.atLeast("5.0.0"));
169162

170-
// Specific ng-packagr configuration
171-
if (ngVersion.atLeast("8.0.0")) {
172-
additionalProperties.put("ngPackagrVersion", "5.4.0");
173-
additionalProperties.put("tsickleVersion", "0.35.0");
174-
} else if (ngVersion.atLeast("7.0.0")) {
175-
// compatible versions with typescript version
176-
additionalProperties.put("ngPackagrVersion", "5.1.0");
177-
additionalProperties.put("tsickleVersion", "0.34.0");
178-
} else if (ngVersion.atLeast("6.0.0")) {
179-
// compatible versions with typescript version
180-
additionalProperties.put("ngPackagrVersion", "3.0.6");
181-
additionalProperties.put("tsickleVersion", "0.32.1");
182-
} else if (ngVersion.atLeast("5.0.0")) {
183-
// compatible versions with typescript version
184-
additionalProperties.put("ngPackagrVersion", "2.4.5");
185-
additionalProperties.put("tsickleVersion", "0.27.5");
186-
} else {
187-
// Angular versions prior to v5
188-
additionalProperties.put("ngPackagrVersion", "1.6.0");
189-
}
190-
191-
// set zone.js version
192-
if (ngVersion.atLeast("8.0.0")) {
193-
additionalProperties.put("zonejsVersion", "0.9.1");
194-
} else if (ngVersion.atLeast("5.0.0")) {
195-
// compatible versions to Angular 5+
196-
additionalProperties.put("zonejsVersion", "0.8.26");
197-
} else {
198-
// Angular versions prior to v5
199-
additionalProperties.put("zonejsVersion", "0.7.6");
200-
}
201-
202-
// set http client usage
203-
if (ngVersion.atLeast("8.0.0")) {
204-
additionalProperties.put("useHttpClient", true);
205-
additionalProperties.put("useHttpClientPackage", false);
206-
} else if (ngVersion.atLeast("4.3.0")) {
207-
additionalProperties.put("useHttpClient", true);
208-
additionalProperties.put("useHttpClientPackage", true);
209-
} else {
210-
additionalProperties.put("useHttpClient", false);
211-
additionalProperties.put("useHttpClientPackage", false);
212-
}
213-
214163
if (additionalProperties.containsKey(PROVIDED_IN_ROOT) && !ngVersion.atLeast("6.0.0")) {
215164
additionalProperties.put(PROVIDED_IN_ROOT,false);
216165
}
@@ -219,7 +168,7 @@ public void processOpts() {
219168
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
220169

221170
if (additionalProperties.containsKey(NPM_NAME)) {
222-
addNpmPackageGeneration();
171+
addNpmPackageGeneration(ngVersion);
223172
}
224173

225174
if (additionalProperties.containsKey(WITH_INTERFACES)) {
@@ -229,6 +178,8 @@ public void processOpts() {
229178
}
230179
}
231180

181+
kebabFileNaming = Boolean.parseBoolean(String.valueOf(additionalProperties.get(KEBAB_FILE_NAME)));
182+
232183
}
233184

234185
private SemVer determineNgVersion() {
@@ -243,7 +194,7 @@ private SemVer determineNgVersion() {
243194
return ngVersion;
244195
}
245196

246-
private void addNpmPackageGeneration() {
197+
private void addNpmPackageGeneration(SemVer ngVersion) {
247198
if (additionalProperties.containsKey(NPM_NAME)) {
248199
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
249200
}
@@ -262,6 +213,60 @@ private void addNpmPackageGeneration() {
262213
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
263214
}
264215

216+
additionalProperties.put("useRxJS6", true);
217+
additionalProperties.put("useHttpClient", true);
218+
additionalProperties.put("useHttpClientPackage", false);
219+
if (ngVersion.atLeast("11.0.0")) {
220+
additionalProperties.put("tsVersion", ">=4.0.0 <4.1.0");
221+
additionalProperties.put("rxjsVersion", "6.6.0");
222+
additionalProperties.put("ngPackagrVersion", "11.0.2");
223+
additionalProperties.put("tsickleVersion", "0.39.1");
224+
additionalProperties.put("zonejsVersion", "0.11.3");
225+
} else if (ngVersion.atLeast("10.0.0")) {
226+
additionalProperties.put("tsVersion", ">=3.9.2 <4.0.0");
227+
additionalProperties.put("rxjsVersion", "6.6.0");
228+
additionalProperties.put("ngPackagrVersion", "10.0.3");
229+
additionalProperties.put("tsickleVersion", "0.39.1");
230+
additionalProperties.put("zonejsVersion", "0.10.2");
231+
} else if (ngVersion.atLeast("9.0.0")) {
232+
additionalProperties.put("tsVersion", ">=3.6.0 <3.8.0");
233+
additionalProperties.put("rxjsVersion", "6.5.3");
234+
additionalProperties.put("ngPackagrVersion", "9.0.1");
235+
additionalProperties.put("tsickleVersion", "0.38.0");
236+
additionalProperties.put("zonejsVersion", "0.10.2");
237+
} else if (ngVersion.atLeast("8.0.0")) {
238+
additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0");
239+
additionalProperties.put("rxjsVersion", "6.5.0");
240+
additionalProperties.put("ngPackagrVersion", "5.4.0");
241+
additionalProperties.put("tsickleVersion", "0.35.0");
242+
additionalProperties.put("zonejsVersion", "0.9.1");
243+
} else if (ngVersion.atLeast("7.0.0")) {
244+
additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0");
245+
additionalProperties.put("rxjsVersion", "6.3.0");
246+
additionalProperties.put("ngPackagrVersion", "5.1.0");
247+
additionalProperties.put("tsickleVersion", "0.34.0");
248+
additionalProperties.put("zonejsVersion", "0.8.26");
249+
250+
additionalProperties.put("useHttpClientPackage", true);
251+
} else if (ngVersion.atLeast("6.0.0")) {
252+
additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0");
253+
additionalProperties.put("rxjsVersion", "6.1.0");
254+
additionalProperties.put("ngPackagrVersion", "3.0.6");
255+
additionalProperties.put("tsickleVersion", "0.32.1");
256+
additionalProperties.put("zonejsVersion", "0.8.26");
257+
258+
additionalProperties.put("useHttpClientPackage", true);
259+
} else {
260+
additionalProperties.put("tsVersion", ">=2.1.5 and <2.8");
261+
additionalProperties.put("rxjsVersion", "6.1.0");
262+
additionalProperties.put("ngPackagrVersion", "3.0.6");
263+
additionalProperties.put("tsickleVersion", "0.32.1");
264+
additionalProperties.put("zonejsVersion", "0.8.26");
265+
266+
additionalProperties.put("useRxJS6", false);
267+
additionalProperties.put("useHttpClientPackage", true);
268+
}
269+
265270
//Files for building our lib
266271
supportingFiles.add(new SupportingFile("README.mustache", getIndexDirectory(), "README.md"));
267272
supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json"));
@@ -496,6 +501,9 @@ public String toApiFilename(String name) {
496501
if (name.length() == 0) {
497502
return "default.service";
498503
}
504+
if (kebabFileNaming) {
505+
return dashize(name);
506+
}
499507
return camelize(name, true) + ".service";
500508
}
501509

@@ -506,6 +514,9 @@ public String toApiImport(String name) {
506514

507515
@Override
508516
public String toModelFilename(String name) {
517+
if (kebabFileNaming) {
518+
return dashize(name);
519+
}
509520
return camelize(toModelName(name), true);
510521
}
511522

src/main/resources/handlebars/aspnetcore/model.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ namespace {{packageName}}.Models
2828
{{/description}}
2929
{{#required}}
3030
[Required]
31-
{{/required}}
31+
{{/required}}{{#pattern}}
32+
[RegularExpression("{{{pattern}}}")]{{/pattern}}{{#minLength}}{{#maxLength}}
33+
[StringLength({{maxLength}}, MinimumLength={{minLength}})]{{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}}
34+
[MinLength({{minLength}})]{{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}}
35+
[MaxLength({{maxLength}})]{{/maxLength}}{{/minLength}}{{#minimum}}{{#maximum}}
36+
[Range({{minimum}}, {{maximum}})]{{/maximum}}{{/minimum}}
3237
[DataMember(Name="{{baseName}}")]
3338
{{#isEnum}}
3439
public {{{datatypeWithEnum}}}{{#isEnum}}{{^isContainer}}?{{/isContainer}}{{/isEnum}} {{name}} { get; set; }

src/main/resources/handlebars/python/api_client.mustache

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,14 @@ class ApiClient(object):
530530
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
531531
content_disposition).group(1)
532532
path = os.path.join(os.path.dirname(path), filename)
533-
534-
with open(path, "wb") as f:
535-
f.write(response.data)
536-
533+
response_data = response.data
534+
with open(path, "wb") as f:
535+
if isinstance(response_data, str):
536+
# change str to bytes so we can write it
537+
response_data = response_data.encode('utf-8')
538+
f.write(response_data)
539+
else:
540+
f.write(response_data)
537541
return path
538542

539543
def __deserialize_primitive(self, data, klass):

src/main/resources/handlebars/python/rest.mustache

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ class RESTClientObject(object):
207207
if _preload_content:
208208
r = RESTResponse(r)
209209

210-
# In the python 3, the response.data is bytes.
211-
# we need to decode it to string.
212-
if six.PY3:
213-
r.data = r.data.decode('utf8')
214-
215210
# log response body
216211
logger.debug("response body: %s", r.data)
217212

0 commit comments

Comments
 (0)