Skip to content

Commit 5c85257

Browse files
authored
Merge branch 'master' into dart-double-cast
2 parents d52168f + aa1f65d commit 5c85257

File tree

603 files changed

+11399
-4901
lines changed

Some content is hidden

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

603 files changed

+11399
-4901
lines changed

.travis.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ before_install:
3939
- gem install bundler -v '< 2'
4040
- gem update --system 2.7.8
4141
- gem --version
42+
# install node version 10.x
43+
- nvm install 10.22.0
44+
- nvm use 10.22.0
45+
# install typescript
4246
- npm install -g typescript
4347
- npm install -g npm
4448
- npm config set registry http://registry.npmjs.org/
@@ -64,7 +68,18 @@ before_install:
6468
- cat /etc/hosts
6569
# show java version
6670
- java -version
67-
71+
# show node version
72+
- node -v
73+
# show node executable
74+
- which node
75+
# show npm version
76+
- npm -v
77+
# show npm executable
78+
- which npm
79+
# show typescript version
80+
- tsc -v
81+
# show tsc executable
82+
- which tsc
6883
install:
6984
# Add Godeps dependencies to GOPATH and PATH
7085
- eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=1.4 bash)"

.whitesource

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"scanSettings": {
3+
"configMode": "AUTO",
4+
"configExternalURL": "",
5+
"projectToken": "",
6+
"baseBranches": []
7+
},
8+
"checkRunSettings": {
9+
"vulnerableCheckRunConclusionLevel": "failure",
10+
"displayMode": "diff"
11+
},
12+
"issueSettings": {
13+
"minSeverityLevel": "LOW"
14+
}
15+
}

README.md

Lines changed: 60 additions & 51 deletions
Large diffs are not rendered by default.

modules/swagger-codegen-cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-codegen-project</artifactId>
6-
<version>2.4.15-SNAPSHOT</version>
6+
<version>2.4.18-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-codegen-maven-plugin/examples/java-client.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@
123123
<jackson-version>2.10.1</jackson-version>
124124
<jodatime-version>2.7</jodatime-version>
125125
<maven-plugin-version>1.0.0</maven-plugin-version>
126-
<junit-version>4.8.1</junit-version>
126+
<junit-version>4.13.1</junit-version>
127127
</properties>
128128
</project>

modules/swagger-codegen-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.swagger</groupId>
66
<artifactId>swagger-codegen-project</artifactId>
7-
<version>2.4.15-SNAPSHOT</version>
7+
<version>2.4.18-SNAPSHOT</version>
88
<relativePath>../..</relativePath>
99
</parent>
1010
<artifactId>swagger-codegen-maven-plugin</artifactId>

modules/swagger-codegen/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>io.swagger</groupId>
55
<artifactId>swagger-codegen-project</artifactId>
6-
<version>2.4.15-SNAPSHOT</version>
6+
<version>2.4.18-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public class CodegenModel {
5656
allMandatory = mandatory;
5757
}
5858

59+
public boolean getIsInteger() {
60+
return "Integer".equalsIgnoreCase(this.dataType);
61+
}
62+
63+
public boolean getIsNumber() {
64+
return "BigDecimal".equalsIgnoreCase(this.dataType);
65+
}
66+
5967
@Override
6068
public String toString() {
6169
return String.format("%s(%s)", name, classname);

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.regex.Pattern;
1212

1313
import io.swagger.models.properties.UntypedProperty;
14+
import io.swagger.util.Yaml;
1415
import org.apache.commons.lang3.ObjectUtils;
1516
import org.apache.commons.lang3.StringEscapeUtils;
1617
import org.apache.commons.lang3.StringUtils;
@@ -293,8 +294,8 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
293294
}
294295

295296
/**
296-
* Returns the common prefix of variables for enum naming if
297-
* two or more variables are present
297+
* Returns the common prefix of variables for enum naming if
298+
* two or more variables are present.
298299
*
299300
* @param vars List of variable names
300301
* @return the common prefix for naming
@@ -347,7 +348,7 @@ public String toEnumDefaultValue(String value, String datatype) {
347348
* @return the sanitized value for enum
348349
*/
349350
public String toEnumValue(String value, String datatype) {
350-
if ("number".equalsIgnoreCase(datatype)) {
351+
if (isPrimivite(datatype)) {
351352
return value;
352353
} else {
353354
return "\"" + escapeText(value) + "\"";
@@ -374,6 +375,12 @@ public String toEnumVarName(String value, String datatype) {
374375
}
375376
}
376377

378+
public boolean isPrimivite(String datatype) {
379+
return "number".equalsIgnoreCase(datatype)
380+
|| "integer".equalsIgnoreCase(datatype)
381+
|| "boolean".equalsIgnoreCase(datatype);
382+
}
383+
377384
// override with any special post-processing
378385
@SuppressWarnings("static-method")
379386
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
@@ -1500,6 +1507,10 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
15001507
properties.putAll(model.getProperties());
15011508
}
15021509

1510+
if (composed.getRequired() != null) {
1511+
required.addAll(composed.getRequired());
1512+
}
1513+
15031514
// child model (properties owned by the model itself)
15041515
Model child = composed.getChild();
15051516
if (child != null && child instanceof RefModel && allDefinitions != null) {
@@ -1525,6 +1536,9 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
15251536
// comment out below as allowableValues is not set in post processing model enum
15261537
m.allowableValues = new HashMap<String, Object>();
15271538
m.allowableValues.put("values", impl.getEnum());
1539+
if (m.dataType.equals("BigDecimal")) {
1540+
addImport(m, "BigDecimal");
1541+
}
15281542
}
15291543
if (impl.getAdditionalProperties() != null) {
15301544
addAdditionPropertiesToCodeGenModel(m, impl);
@@ -2762,6 +2776,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
27622776
p.isPrimitiveType = cp.isPrimitiveType;
27632777
p.isContainer = true;
27642778
p.isListContainer = true;
2779+
p.uniqueItems = impl.getUniqueItems() == null ? false : impl.getUniqueItems();
27652780

27662781
// set boolean flag (e.g. isString)
27672782
setParameterBooleanFlagWithCodegenProperty(p, cp);

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ protected void configureSwaggerInfo() {
261261
if (info.getTermsOfService() != null) {
262262
config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService()));
263263
}
264+
if (info.getVendorExtensions() != null && !info.getVendorExtensions().isEmpty()) {
265+
config.additionalProperties().put("info-extensions", info.getVendorExtensions());
266+
}
264267
}
265268

266269
protected void generateModelTests(List<File> files, Map<String, Object> models, String modelName) throws IOException {

modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,22 @@ public void flattenProperties(Map<String, Property> properties, String path) {
355355
}
356356
}
357357
}
358+
} else if (property instanceof ComposedProperty) {
359+
ComposedProperty composedProperty = (ComposedProperty) property;
360+
String modelName = resolveModelName(composedProperty.getTitle(), path + "_" + key);
361+
Model model = modelFromProperty(composedProperty, modelName);
362+
String existing = matchGenerated(model);
363+
if (existing != null) {
364+
RefProperty refProperty = new RefProperty(existing);
365+
refProperty.setRequired(composedProperty.getRequired());
366+
propsToUpdate.put(key, refProperty);
367+
} else {
368+
RefProperty refProperty = new RefProperty(modelName);
369+
refProperty.setRequired(composedProperty.getRequired());
370+
propsToUpdate.put(key, refProperty);
371+
addGenerated(modelName, model);
372+
swagger.addDefinition(modelName, model);
373+
}
358374
}
359375
}
360376
if (propsToUpdate.size() > 0) {
@@ -428,6 +444,30 @@ public Model modelFromProperty(ObjectProperty object, String path) {
428444
return model;
429445
}
430446

447+
public Model modelFromProperty(ComposedProperty composedProperty, String path) {
448+
String description = composedProperty.getDescription();
449+
String example = null;
450+
451+
Object obj = composedProperty.getExample();
452+
if (obj != null) {
453+
example = obj.toString();
454+
}
455+
Xml xml = composedProperty.getXml();
456+
457+
ModelImpl model = new ModelImpl();
458+
model.type(composedProperty.getType());
459+
model.setDescription(description);
460+
model.setExample(example);
461+
model.setName(path);
462+
model.setXml(xml);
463+
if (composedProperty.getVendorExtensions() != null) {
464+
for (String key : composedProperty.getVendorExtensions().keySet()) {
465+
model.setVendorExtension(key, composedProperty.getVendorExtensions().get(key));
466+
}
467+
}
468+
return model;
469+
}
470+
431471
@SuppressWarnings("static-method")
432472
public Model modelFromProperty(MapProperty object, @SuppressWarnings("unused") String path) {
433473
String description = object.getDescription();

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.regex.Pattern;
1212

1313
import io.swagger.codegen.languages.features.NotNullAnnotationFeatures;
14+
import io.swagger.models.RefModel;
15+
import io.swagger.models.properties.RefProperty;
1416
import org.apache.commons.lang3.BooleanUtils;
1517
import org.apache.commons.lang3.StringUtils;
1618

@@ -58,6 +60,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
5860
public static final String SUPPORT_JAVA6 = "supportJava6";
5961
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
6062
public static final String ERROR_ON_UNKNOWN_ENUM = "errorOnUnknownEnum";
63+
public static final String CHECK_DUPLICATED_MODEL_NAME = "checkDuplicatedModelName";
6164

6265
protected String dateLibrary = "threetenbp";
6366
protected boolean supportAsync = false;
@@ -119,7 +122,7 @@ public AbstractJavaCodegen() {
119122
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
120123
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
121124
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
122-
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
125+
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "list",
123126
"native", "super", "while", "null")
124127
);
125128

@@ -187,6 +190,7 @@ public AbstractJavaCodegen() {
187190
cliOptions.add(java8Mode);
188191

189192
cliOptions.add(CliOption.newBoolean(DISABLE_HTML_ESCAPING, "Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)"));
193+
cliOptions.add(CliOption.newBoolean(CHECK_DUPLICATED_MODEL_NAME, "Check if there are duplicated model names (ignoring case)"));
190194
}
191195

192196
@Override
@@ -1042,6 +1046,10 @@ public void preprocessSwagger(Swagger swagger) {
10421046
if (swagger == null || swagger.getPaths() == null){
10431047
return;
10441048
}
1049+
boolean checkDuplicatedModelName = Boolean.parseBoolean(additionalProperties.get(CHECK_DUPLICATED_MODEL_NAME) != null ? additionalProperties.get(CHECK_DUPLICATED_MODEL_NAME).toString() : "");
1050+
if (checkDuplicatedModelName) {
1051+
this.checkDuplicatedModelNameIgnoringCase(swagger);
1052+
}
10451053
for (String pathname : swagger.getPaths().keySet()) {
10461054
Path path = swagger.getPath(pathname);
10471055
if (path.getOperations() == null){
@@ -1099,6 +1107,84 @@ private static String getAccept(Operation operation) {
10991107
protected boolean needToImport(String type) {
11001108
return super.needToImport(type) && type.indexOf(".") < 0;
11011109
}
1110+
1111+
protected void checkDuplicatedModelNameIgnoringCase(Swagger swagger) {
1112+
final Map<String, Model> definitions = swagger.getDefinitions();
1113+
final Map<String, Map<String, Model>> definitionsRepeated = new HashMap<>();
1114+
1115+
for (String definitionKey : definitions.keySet()) {
1116+
final Model model = definitions.get(definitionKey);
1117+
final String lowerKeyDefinition = definitionKey.toLowerCase();
1118+
1119+
if (definitionsRepeated.containsKey(lowerKeyDefinition)) {
1120+
Map<String, Model> modelMap = definitionsRepeated.get(lowerKeyDefinition);
1121+
if (modelMap == null) {
1122+
modelMap = new HashMap<>();
1123+
definitionsRepeated.put(lowerKeyDefinition, modelMap);
1124+
}
1125+
modelMap.put(definitionKey, model);
1126+
} else {
1127+
definitionsRepeated.put(lowerKeyDefinition, null);
1128+
}
1129+
}
1130+
for (String lowerKeyDefinition : definitionsRepeated.keySet()) {
1131+
final Map<String, Model> modelMap = definitionsRepeated.get(lowerKeyDefinition);
1132+
if (modelMap == null) {
1133+
continue;
1134+
}
1135+
int index = 1;
1136+
for (String name : modelMap.keySet()) {
1137+
final Model model = modelMap.get(name);
1138+
final String newModelName = name + index;
1139+
definitions.put(newModelName, model);
1140+
replaceDuplicatedInPaths(swagger.getPaths(), name, newModelName);
1141+
replaceDuplicatedInModelProperties(definitions, name, newModelName);
1142+
definitions.remove(name);
1143+
index++;
1144+
}
1145+
}
1146+
}
1147+
1148+
protected void replaceDuplicatedInPaths(Map<String, Path> paths, String modelName, String newModelName) {
1149+
if (paths == null || paths.isEmpty()) {
1150+
return;
1151+
}
1152+
paths.values().stream()
1153+
.flatMap(path -> path.getOperations().stream())
1154+
.flatMap(operation -> operation.getParameters().stream())
1155+
.filter(parameter -> parameter instanceof BodyParameter
1156+
&& ((BodyParameter)parameter).getSchema() != null
1157+
&& ((BodyParameter)parameter).getSchema() instanceof RefModel
1158+
)
1159+
.forEach(parameter -> {
1160+
final RefModel refModel = (RefModel) ((BodyParameter)parameter).getSchema();
1161+
if (refModel.getSimpleRef().equals(modelName)) {
1162+
refModel.set$ref(refModel.get$ref().replace(modelName, newModelName));
1163+
}
1164+
});
1165+
paths.values().stream()
1166+
.flatMap(path -> path.getOperations().stream())
1167+
.flatMap(operation -> operation.getResponses().values().stream())
1168+
.filter(response -> response.getResponseSchema() != null && response.getResponseSchema() instanceof RefModel)
1169+
.forEach(response -> {
1170+
final RefModel refModel = (RefModel) response.getResponseSchema();
1171+
if (refModel.getSimpleRef().equals(modelName)) {
1172+
refModel.set$ref(refModel.get$ref().replace(modelName, newModelName));
1173+
}
1174+
});
1175+
}
1176+
1177+
protected void replaceDuplicatedInModelProperties(Map<String, Model> definitions, String modelName, String newModelName) {
1178+
definitions.values().stream()
1179+
.flatMap(model -> model.getProperties().values().stream())
1180+
.filter(property -> property instanceof RefProperty)
1181+
.forEach(property -> {
1182+
final RefProperty refProperty = (RefProperty) property;
1183+
if (refProperty.getSimpleRef().equals(modelName)) {
1184+
refProperty.set$ref(refProperty.get$ref().replace(modelName, newModelName));
1185+
}
1186+
});
1187+
}
11021188
/*
11031189
@Override
11041190
public String findCommonPrefixOfVars(List<String> vars) {
@@ -1126,8 +1212,7 @@ public String toEnumVarName(String value, String datatype) {
11261212
}
11271213

11281214
// number
1129-
if ("Integer".equals(datatype) || "Long".equals(datatype) ||
1130-
"Float".equals(datatype) || "Double".equals(datatype)) {
1215+
if ("Integer".equals(datatype) || "Long".equals(datatype) || "Float".equals(datatype) || "Double".equals(datatype) || "BigDecimal".equals(datatype)) {
11311216
String varName = "NUMBER_" + value;
11321217
varName = varName.replaceAll("-", "MINUS_");
11331218
varName = varName.replaceAll("\\+", "PLUS_");
@@ -1146,14 +1231,16 @@ public String toEnumVarName(String value, String datatype) {
11461231

11471232
@Override
11481233
public String toEnumValue(String value, String datatype) {
1149-
if ("Integer".equals(datatype) || "Double".equals(datatype)) {
1234+
if ("Integer".equals(datatype) || "Double".equals(datatype) || "Boolean".equals(datatype)) {
11501235
return value;
11511236
} else if ("Long".equals(datatype)) {
11521237
// add l to number, e.g. 2048 => 2048l
11531238
return value + "l";
11541239
} else if ("Float".equals(datatype)) {
11551240
// add f to number, e.g. 3.14 => 3.14f
11561241
return value + "f";
1242+
} else if ("BigDecimal".equals(datatype)) {
1243+
return "new BigDecimal(" + escapeText(value) + ")";
11571244
} else {
11581245
return "\"" + escapeText(value) + "\"";
11591246
}

0 commit comments

Comments
 (0)