Skip to content

Commit 32bbd2c

Browse files
authored
Merge branch 'master' into handle-default-parameter-values
2 parents 0b68541 + 2b2f992 commit 32bbd2c

File tree

90 files changed

+1107
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1107
-468
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "{}"
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2020 SmartBear Software Inc.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <img src="https://raw.githubusercontent.com/swagger-api/swagger.io/wordpress/images/assets/SWC-logo-clr.png" height="80">
22

3-
- Master: [![Build Status](https://img.shields.io/jenkins/s/https/jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-generators-master-java-8.svg)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-generators-master-java-8)
3+
- Master: [![Build Status](https://img.shields.io/jenkins/build.svg?jobUrl=https://jenkins.swagger.io/job/oss-swagger-codegen-generators-master-java-8)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-generators-master-java-8)
44

55
[![Build Status](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-generators-master-java-8/badge/icon?subject=jenkins%20build%20-%20master)](https://jenkins.swagger.io/view/OSS%20-%20Java/job/oss-swagger-codegen-generators-master-java-8/)
66

@@ -35,20 +35,3 @@ The Swagger Codegen project is intended as a benefit for users of the Swagger /
3535
* Generated code is intentionally _not_ subject to the parent project license
3636

3737
When code is generated from this project, it shall be considered **AS IS** and owned by the user of the software. There are no warranties--expressed or implied--for generated code. You can do what you wish with it, and once generated, the code is your responsibility and subject to the licensing terms that you deem appropriate.
38-
39-
## License
40-
41-
```
42-
Copyright 2019 SmartBear Software
43-
44-
Licensed under the Apache License, Version 2.0 (the "License");
45-
you may not use this file except in compliance with the License.
46-
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
47-
48-
Unless required by applicable law or agreed to in writing, software
49-
distributed under the License is distributed on an "AS IS" BASIS,
50-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51-
See the License for the specific language governing permissions and
52-
limitations under the License.
53-
```
54-

pom.xml

Lines changed: 10 additions & 4 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.15-SNAPSHOT</version>
15+
<version>1.0.17-SNAPSHOT</version>
1616
<packaging>jar</packaging>
1717

1818
<build>
@@ -208,6 +208,12 @@
208208
<artifactId>testng</artifactId>
209209
<version>${testng-version}</version>
210210
<scope>test</scope>
211+
<exclusions>
212+
<exclusion>
213+
<artifactId>snakeyaml</artifactId>
214+
<groupId>org.yaml</groupId>
215+
</exclusion>
216+
</exclusions>
211217
</dependency>
212218
<dependency>
213219
<groupId>org.slf4j</groupId>
@@ -246,9 +252,9 @@
246252
</dependency>
247253
</dependencies>
248254
<properties>
249-
<swagger-codegen-version>3.0.15-SNAPSHOT</swagger-codegen-version>
250-
<swagger-parser-version>2.0.17-SNAPSHOT</swagger-parser-version>
251-
<swagger-core-version>2.1.1-SNAPSHOT</swagger-core-version>
255+
<swagger-codegen-version>3.0.17-SNAPSHOT</swagger-codegen-version>
256+
<swagger-parser-version>2.0.17</swagger-parser-version>
257+
<swagger-core-version>2.1.1</swagger-core-version>
252258
<jackson-version>2.10.1</jackson-version>
253259
<scala-version>2.11.1</scala-version>
254260
<felix-version>3.3.0</felix-version>

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

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.swagger.codegen.v3.CodegenProperty;
1717
import io.swagger.codegen.v3.CodegenResponse;
1818
import io.swagger.codegen.v3.CodegenSecurity;
19+
import io.swagger.codegen.v3.ISchemaHandler;
1920
import io.swagger.codegen.v3.SupportingFile;
2021
import io.swagger.codegen.v3.generators.examples.ExampleGenerator;
2122
import io.swagger.codegen.v3.generators.handlebars.BaseItemsHelper;
@@ -160,7 +161,6 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
160161
protected String httpUserAgent;
161162
protected Boolean hideGenerationTimestamp = true;
162163
protected TemplateEngine templateEngine = new HandlebarTemplateEngine(this);
163-
protected SchemaHandler schemaHandler = new SchemaHandler(this);
164164
// How to encode special characters like $
165165
// They are translated to words like "Dollar" and prefixed with '
166166
// Then translated back during JSON encoding and decoding
@@ -171,6 +171,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
171171
protected String ignoreFilePathOverride;
172172
protected boolean useOas2 = false;
173173
protected boolean copyFistAllOfProperties = false;
174+
protected boolean ignoreImportMapping;
174175

175176
public List<CliOption> cliOptions() {
176177
return cliOptions;
@@ -181,6 +182,12 @@ public void processOpts() {
181182
this.setTemplateDir((String) additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
182183
}
183184

185+
if (additionalProperties.get(CodegenConstants.IGNORE_IMPORT_MAPPING_OPTION) != null) {
186+
setIgnoreImportMapping(Boolean.parseBoolean( additionalProperties.get(CodegenConstants.IGNORE_IMPORT_MAPPING_OPTION).toString()));
187+
} else {
188+
setIgnoreImportMapping(defaultIgnoreImportMappingOption());
189+
}
190+
184191
if (additionalProperties.containsKey(CodegenConstants.TEMPLATE_VERSION)) {
185192
this.setTemplateVersion((String) additionalProperties.get(CodegenConstants.TEMPLATE_VERSION));
186193
}
@@ -260,28 +267,6 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> processedMod
260267
if (supportsInheritance) {
261268
processCodegenModels(allModels);
262269
}
263-
for (String modelName : allModels.keySet()) {
264-
final CodegenModel codegenModel = allModels.get(modelName);
265-
if (!codegenModel.vendorExtensions.containsKey("x-is-composed-model")) {
266-
continue;
267-
}
268-
List<String> modelNames = (List<String>) codegenModel.vendorExtensions.get("x-model-names");
269-
if (modelNames == null || modelNames.isEmpty()) {
270-
continue;
271-
}
272-
for (String name : modelNames) {
273-
final CodegenModel model = allModels.get(name);
274-
if (model == null) {
275-
continue;
276-
}
277-
if (model.interfaceModels == null) {
278-
model.interfaceModels = new ArrayList<>();
279-
}
280-
if (!model.interfaceModels.stream().anyMatch(value -> value.name.equalsIgnoreCase(modelName))) {
281-
model.interfaceModels.add(codegenModel);
282-
}
283-
}
284-
}
285270
return processedModels;
286271
}
287272

@@ -1077,7 +1062,7 @@ private static String getTypeOfSchema(Schema schema) {
10771062
} else if (schema instanceof BinarySchema) {
10781063
return SchemaTypeUtil.BINARY_FORMAT;
10791064
} else if (schema instanceof FileSchema) {
1080-
return "file"; // FIXME: this type does not exist in the OpenAPI 3.0 specification
1065+
return SchemaTypeUtil.BINARY_FORMAT;
10811066
} else if (schema instanceof BooleanSchema) {
10821067
return SchemaTypeUtil.BOOLEAN_TYPE;
10831068
} else if (schema instanceof DateSchema) {
@@ -1292,12 +1277,6 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
12921277
if (schema instanceof ArraySchema) {
12931278
codegenModel.getVendorExtensions().put(IS_ARRAY_MODEL_EXT_NAME, Boolean.TRUE);
12941279
codegenModel.getVendorExtensions().put(IS_CONTAINER_EXT_NAME, Boolean.TRUE);
1295-
1296-
final Schema items = ((ArraySchema) schema).getItems();
1297-
if (items != null && items instanceof ComposedSchema) {
1298-
schemaHandler.configureComposedModelFromSchemaItems(codegenModel, ((ComposedSchema) items));
1299-
}
1300-
13011280
codegenModel.arrayModelType = fromProperty(name, schema).complexType;
13021281
addParentContainer(codegenModel, name, schema);
13031282
}
@@ -1350,16 +1329,9 @@ else if (schema instanceof ComposedSchema) {
13501329
// parent model
13511330
final String parentName = getParentName(composed);
13521331
final Schema parent = StringUtils.isBlank(parentName) ? null : allDefinitions.get(parentName);
1353-
13541332
final List<Schema> allOf = composed.getAllOf();
1355-
final List<Schema> oneOf = composed.getOneOf();
1356-
final List<Schema> anyOf = composed.getAnyOf();
1357-
13581333
// interfaces (intermediate models)
13591334
if (allOf != null && !allOf.isEmpty()) {
1360-
if (codegenModel.interfaces == null) {
1361-
codegenModel.interfaces = new ArrayList<String>();
1362-
}
13631335
for (int i = 0; i < allOf.size(); i++) {
13641336
if (i == 0 && !copyFistAllOfProperties) {
13651337
continue;
@@ -1374,7 +1346,6 @@ else if (schema instanceof ComposedSchema) {
13741346
refSchema = allDefinitions.get(ref);
13751347
}
13761348
final String modelName = toModelName(ref);
1377-
codegenModel.interfaces.add(modelName);
13781349
addImport(codegenModel, modelName);
13791350
if (allDefinitions != null && refSchema != null) {
13801351
if (!supportsMixins) {
@@ -1386,14 +1357,6 @@ else if (schema instanceof ComposedSchema) {
13861357
}
13871358
}
13881359
}
1389-
if (oneOf != null && !oneOf.isEmpty()) {
1390-
codegenModel.dataType = getSchemaType(composed);
1391-
this.schemaHandler.configureOneOfModel(codegenModel, oneOf);
1392-
}
1393-
if (anyOf != null && !anyOf.isEmpty()) {
1394-
codegenModel.dataType = getSchemaType(composed);
1395-
this.schemaHandler.configureAnyOfModel(codegenModel, anyOf);
1396-
}
13971360
if (parent != null) {
13981361
codegenModel.parentSchema = parentName;
13991362
codegenModel.parent = toModelName(parentName);
@@ -1701,9 +1664,6 @@ public CodegenProperty fromProperty(String name, Schema propertySchema) {
17011664
// handle inner property
17021665
CodegenProperty cp = fromProperty("inner", (Schema) propertySchema.getAdditionalProperties());
17031666
updatePropertyForMap(codegenProperty, cp);
1704-
} else if (propertySchema instanceof ComposedSchema) {
1705-
ComposedSchema composedProperty = (ComposedSchema) propertySchema;
1706-
this.schemaHandler.createCodegenModel(composedProperty, codegenProperty);
17071667
} else if (propertySchema instanceof MapSchema && hasTrueAdditionalProperties(propertySchema)) {
17081668

17091669
codegenProperty.getVendorExtensions().put(CodegenConstants.IS_CONTAINER_EXT_NAME, Boolean.TRUE);
@@ -1717,6 +1677,9 @@ public CodegenProperty fromProperty(String name, Schema propertySchema) {
17171677
CodegenProperty cp = fromProperty("inner", new ObjectSchema());
17181678
updatePropertyForMap(codegenProperty, cp);
17191679
} else {
1680+
if (isObjectSchema(propertySchema)) {
1681+
codegenProperty.getVendorExtensions().put("x-is-object", Boolean.TRUE);
1682+
}
17201683
setNonArrayMapProperty(codegenProperty, type);
17211684
}
17221685
return codegenProperty;
@@ -3095,14 +3058,6 @@ private void addVars(CodegenModel codegenModel, List<CodegenProperty> vars, Map<
30953058
final CodegenProperty codegenProperty = fromProperty(key, propertySchema);
30963059
codegenProperty.required = mandatory.contains(key);
30973060

3098-
if (codegenProperty.vendorExtensions.containsKey("oneOf-model")) {
3099-
this.schemaHandler.configureOneOfModelFromProperty(codegenProperty, codegenModel);
3100-
}
3101-
3102-
if (codegenProperty.vendorExtensions.containsKey("anyOf-model")) {
3103-
this.schemaHandler.configureAnyOfModelFromProperty(codegenProperty, codegenModel);
3104-
}
3105-
31063061
if (propertySchema.get$ref() != null) {
31073062
if (this.openAPI == null) {
31083063
LOGGER.warn("open api utility object was not properly set.");
@@ -3164,6 +3119,29 @@ private void addVars(CodegenModel codegenModel, List<CodegenProperty> vars, Map<
31643119
codegenModel.readWriteVars.add(codegenProperty);
31653120
}
31663121
}
3122+
// check if one of the property is a object and has import mapping.
3123+
List<CodegenProperty> modelProperties = vars.stream()
3124+
.filter(codegenProperty -> getBooleanValue(codegenProperty, "x-is-object") && importMapping.containsKey(codegenProperty.baseType))
3125+
.collect(Collectors.toList());
3126+
if (modelProperties == null || modelProperties.isEmpty()) {
3127+
return;
3128+
}
3129+
3130+
for (CodegenProperty modelProperty : modelProperties) {
3131+
List<CodegenProperty> codegenProperties = vars.stream()
3132+
.filter(codegenProperty -> !getBooleanValue(codegenProperty, "x-is-object")
3133+
&& importMapping.containsKey(codegenProperty.baseType)
3134+
&& codegenProperty.baseType.equals(modelProperty.baseType))
3135+
.collect(Collectors.toList());
3136+
if (codegenProperties == null || codegenProperties.isEmpty()) {
3137+
continue;
3138+
}
3139+
for (CodegenProperty codegenProperty : codegenProperties) {
3140+
codegenModel.imports.remove(codegenProperty.baseType);
3141+
codegenProperty.datatype = importMapping.get(codegenProperty.baseType);
3142+
codegenProperty.datatypeWithEnum = codegenProperty.datatype;
3143+
}
3144+
}
31673145
}
31683146

31693147
/**
@@ -4163,7 +4141,10 @@ else if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle())) {
41634141
}
41644142

41654143
public boolean isObjectSchema (Schema schema) {
4166-
if (schema instanceof ObjectSchema ||schema instanceof ComposedSchema) {
4144+
if (schema == null) {
4145+
return false;
4146+
}
4147+
if (schema instanceof ObjectSchema || schema instanceof ComposedSchema) {
41674148
return true;
41684149
}
41694150
if (SchemaTypeUtil.OBJECT_TYPE.equalsIgnoreCase(schema.getType()) && !(schema instanceof MapSchema)) {
@@ -4257,4 +4238,20 @@ public boolean needsUnflattenedSpec() {
42574238
public void setUnflattenedOpenAPI(OpenAPI unflattenedOpenAPI) {
42584239
this.unflattenedOpenAPI = unflattenedOpenAPI;
42594240
}
4241+
4242+
public boolean getIgnoreImportMapping() {
4243+
return ignoreImportMapping;
4244+
}
4245+
4246+
public void setIgnoreImportMapping(boolean ignoreImportMapping) {
4247+
this.ignoreImportMapping = ignoreImportMapping;
4248+
}
4249+
4250+
public boolean defaultIgnoreImportMappingOption() {
4251+
return false;
4252+
}
4253+
4254+
public ISchemaHandler getSchemaHandler() {
4255+
return new SchemaHandler(this);
4256+
}
42604257
}

0 commit comments

Comments
 (0)