Skip to content

Commit 358e5a4

Browse files
committed
Merge remote-tracking branch '9845/master' into 9845
2 parents 5d00b34 + 621dfc0 commit 358e5a4

File tree

116 files changed

+8295
-223
lines changed

Some content is hidden

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

116 files changed

+8295
-223
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
928928
- [Mporium](http://mporium.com/)
929929
- [Neverfail](https://neverfail.com/)
930930
- [NexCap](http://www.nexess-solutions.com/fr/plateforme-iot/)
931+
- [Norwegian Air Shuttle](https://www.norwegian.com/)
931932
- [NTT DATA](http://www.nttdata.com/)
932933
- [nViso](http://www.nviso.ch/)
933934
- [Okiok](https://www.okiok.com)
@@ -992,6 +993,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
992993
- [Zalando](https://tech.zalando.com)
993994
- [ZEEF.com](https://zeef.com/)
994995
- [zooplus](https://www.zooplus.com/)
996+
- [Trifork](https://www.trifork.com/)
995997

996998
Presentations/Videos/Tutorials/Books
997999
----------------------------------------
@@ -1177,7 +1179,7 @@ Who is eligible? Those who want to join must have at least 3 PRs merged into a g
11771179
| Android | |
11781180
| Apex | |
11791181
| Bash | @kenjones-cisco (2017/09) |
1180-
| C++ | @fvarose (2017/11) |
1182+
| C++ | |
11811183
| C# | @mandrean (2017/08) |
11821184
| Clojure | |
11831185
| Dart | @ircecho (2017/07) |

bin/security/ue4cpp-petstore.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/ue4cpp -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l ue4cpp -o samples/client/petstore-security-test/ue4cpp"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/ue4cpp-petstore.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -t modules/swagger-codegen/src/main/resources/ue4cpp -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l ue4cpp -o samples/client/petstore/ue4cpp"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/windows/ue4cpp-petstore.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l ue4cpp -o samples\client\petstore\ue4cpp
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

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.14</version>
6+
<version>2.4.15-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>

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.14</version>
7+
<version>2.4.15-SNAPSHOT</version>
88
<relativePath>../..</relativePath>
99
</parent>
1010
<artifactId>swagger-codegen-maven-plugin</artifactId>

modules/swagger-codegen/pom.xml

Lines changed: 3 additions & 3 deletions
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.14</version>
6+
<version>2.4.15-SNAPSHOT</version>
77
<relativePath>../..</relativePath>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
@@ -74,8 +74,8 @@
7474
<artifactId>maven-compiler-plugin</artifactId>
7575
<version>3.5.1</version>
7676
<configuration>
77-
<source>1.7</source>
78-
<target>1.7</target>
77+
<source>1.8</source>
78+
<target>1.8</target>
7979
</configuration>
8080
</plugin>
8181
<plugin>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public interface CodegenConfig {
163163

164164
String apiFilename(String templateName, String tag);
165165

166+
String modelFilename(String templateName, String modelName);
167+
166168
String apiTestFilename(String templateName, String tag);
167169

168170
String apiDocFilename(String templateName, String tag);

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

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -190,43 +190,48 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
190190
allModels.put(modelName, cm);
191191
}
192192
}
193-
// Fix up all parent and interface CodegenModel references.
194-
for (CodegenModel cm : allModels.values()) {
195-
if (cm.parent != null) {
196-
cm.parentModel = allModels.get(cm.parent);
197-
}
198-
if (cm.interfaces != null && !cm.interfaces.isEmpty()) {
199-
cm.interfaceModels = new ArrayList<CodegenModel>(cm.interfaces.size());
200-
for (String intf : cm.interfaces) {
201-
CodegenModel intfModel = allModels.get(intf);
202-
if (intfModel != null) {
203-
cm.interfaceModels.add(intfModel);
204-
}
205-
}
206-
}
207-
}
208-
// Let parent know about all its children
193+
209194
for (String name : allModels.keySet()) {
210-
CodegenModel cm = allModels.get(name);
211-
CodegenModel parent = allModels.get(cm.parent);
212-
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
213-
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
214-
while (parent != null) {
215-
if (parent.children == null) {
216-
parent.children = new ArrayList<CodegenModel>();
217-
}
218-
parent.children.add(cm);
219-
if (parent.discriminator == null) {
220-
parent = allModels.get(parent.parent);
221-
} else {
222-
parent = null;
223-
}
224-
}
195+
CodegenModel codegenModel = allModels.get(name);
196+
fixUpParentAndInterfaces(codegenModel, allModels);
225197
}
226198
}
227199
return objs;
228200
}
229201

202+
/**
203+
* Fix up all parent and interface CodegenModel references.
204+
* @param allModels
205+
*/
206+
protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String, CodegenModel> allModels) {
207+
if (codegenModel.parent != null) {
208+
codegenModel.parentModel = allModels.get(codegenModel.parent);
209+
}
210+
if (codegenModel.interfaces != null && !codegenModel.interfaces.isEmpty()) {
211+
codegenModel.interfaceModels = new ArrayList<CodegenModel>(codegenModel.interfaces.size());
212+
for (String intf : codegenModel.interfaces) {
213+
CodegenModel intfModel = allModels.get(intf);
214+
if (intfModel != null) {
215+
codegenModel.interfaceModels.add(intfModel);
216+
}
217+
}
218+
}
219+
CodegenModel parent = codegenModel.parentModel;
220+
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
221+
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
222+
while (parent != null) {
223+
if (parent.children == null) {
224+
parent.children = new ArrayList<CodegenModel>();
225+
}
226+
parent.children.add(codegenModel);
227+
if (parent.discriminator == null) {
228+
parent = allModels.get(parent.parent);
229+
} else {
230+
parent = null;
231+
}
232+
}
233+
}
234+
230235
// override with any special post-processing
231236
@SuppressWarnings("static-method")
232237
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
@@ -3445,6 +3450,11 @@ public String apiFilename(String templateName, String tag) {
34453450
return apiFileFolder() + File.separator + toApiFilename(tag) + suffix;
34463451
}
34473452

3453+
public String modelFilename(String templateName, String modelName) {
3454+
String suffix = modelTemplateFiles().get(templateName);
3455+
return modelFileFolder() + File.separator + toModelFilename(modelName) + suffix;
3456+
}
3457+
34483458
/**
34493459
* Return the full path and API documentation file
34503460
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ private Model getParent(Model model) {
424424
}
425425
allModels.add(modelTemplate);
426426
for (String templateName : config.modelTemplateFiles().keySet()) {
427-
String suffix = config.modelTemplateFiles().get(templateName);
428-
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(modelName) + suffix;
427+
String filename = config.modelFilename(templateName, modelName);
429428
if (!config.shouldOverwrite(filename)) {
430429
LOGGER.info("Skipped overwriting " + filename);
431430
continue;

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111
import java.util.regex.Pattern;
1212

13+
import io.swagger.codegen.languages.features.NotNullAnnotationFeatures;
1314
import org.apache.commons.lang3.BooleanUtils;
1415
import org.apache.commons.lang3.StringUtils;
1516

@@ -43,6 +44,7 @@
4344
import io.swagger.models.properties.Property;
4445
import io.swagger.models.properties.StringProperty;
4546

47+
import static io.swagger.codegen.languages.features.NotNullAnnotationFeatures.NOT_NULL_JACKSON_ANNOTATION;
4648

4749
public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig {
4850

@@ -88,6 +90,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
8890
protected String modelDocPath = "docs/";
8991
protected boolean supportJava6= false;
9092
protected boolean disableHtmlEscaping = false;
93+
private NotNullAnnotationFeatures notNullOption;
9194

9295
public AbstractJavaCodegen() {
9396
super();
@@ -161,7 +164,9 @@ public AbstractJavaCodegen() {
161164
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util. This option only works for Java API client"));
162165
cliOptions.add(new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));
163166
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
164-
167+
if(this instanceof NotNullAnnotationFeatures){
168+
cliOptions.add(CliOption.newBoolean(NOT_NULL_JACKSON_ANNOTATION, "adds @JsonInclude(JsonInclude.Include.NON_NULL) annotation to model classes"));
169+
}
165170
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
166171
Map<String, String> dateOptions = new HashMap<String, String>();
167172
dateOptions.put("java8", "Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets \"" + JAVA8_MODE + "\" to true");
@@ -338,6 +343,17 @@ public void processOpts() {
338343
this.setFullJavaUtil(Boolean.valueOf(additionalProperties.get(FULL_JAVA_UTIL).toString()));
339344
}
340345

346+
if (this instanceof NotNullAnnotationFeatures) {
347+
notNullOption = (NotNullAnnotationFeatures)this;
348+
if (additionalProperties.containsKey(NOT_NULL_JACKSON_ANNOTATION)) {
349+
notNullOption.setNotNullJacksonAnnotation(convertPropertyToBoolean(NOT_NULL_JACKSON_ANNOTATION));
350+
writePropertyBack(NOT_NULL_JACKSON_ANNOTATION, notNullOption.isNotNullJacksonAnnotation());
351+
if (notNullOption.isNotNullJacksonAnnotation()) {
352+
importMapping.put("JsonInclude", "com.fasterxml.jackson.annotation.JsonInclude");
353+
}
354+
}
355+
}
356+
341357
if (fullJavaUtil) {
342358
javaUtilPrefix = "java.util.";
343359
}
@@ -907,6 +923,16 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
907923
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
908924
codegenModel = AbstractJavaCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
909925
}
926+
if (this instanceof NotNullAnnotationFeatures) {
927+
if (this instanceof NotNullAnnotationFeatures) {
928+
notNullOption = (NotNullAnnotationFeatures)this;
929+
if (additionalProperties.containsKey(NOT_NULL_JACKSON_ANNOTATION)) {
930+
if (notNullOption.isNotNullJacksonAnnotation()) {
931+
codegenModel.imports.add("JsonInclude");
932+
}
933+
}
934+
}
935+
}
910936
return codegenModel;
911937
}
912938

@@ -938,6 +964,33 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
938964
}
939965
}
940966

967+
@Override
968+
protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String, CodegenModel> allModels) {
969+
super.fixUpParentAndInterfaces(codegenModel, allModels);
970+
if (codegenModel.vars == null || codegenModel.vars.isEmpty() || codegenModel.parentModel == null) {
971+
return;
972+
}
973+
CodegenModel parentModel = codegenModel.parentModel;
974+
975+
for (CodegenProperty codegenProperty : codegenModel.vars) {
976+
while (parentModel != null) {
977+
if (parentModel.vars == null || parentModel.vars.isEmpty()) {
978+
parentModel = parentModel.parentModel;
979+
continue;
980+
}
981+
boolean hasConflict = parentModel.vars.stream()
982+
.anyMatch(parentProperty -> parentProperty.name.equals(codegenProperty.name) && !parentProperty.datatype.equals(codegenProperty.datatype));
983+
if (hasConflict) {
984+
codegenProperty.name = toVarName(codegenModel.name + "_" + codegenProperty.name);
985+
codegenProperty.getter = toGetter(codegenProperty.name);
986+
codegenProperty.setter = toGetter(codegenProperty.name);
987+
break;
988+
}
989+
parentModel = parentModel.parentModel;
990+
}
991+
}
992+
}
993+
941994
@Override
942995
public void postProcessParameter(CodegenParameter parameter) { }
943996

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.swagger.codegen.*;
77
import io.swagger.codegen.languages.features.BeanValidationFeatures;
88
import io.swagger.codegen.languages.features.GzipFeatures;
9+
import io.swagger.codegen.languages.features.NotNullAnnotationFeatures;
910
import io.swagger.codegen.languages.features.PerformBeanValidationFeatures;
1011

1112
import org.apache.commons.lang3.BooleanUtils;
@@ -19,7 +20,7 @@
1920

2021
public class JavaClientCodegen extends AbstractJavaCodegen
2122
implements BeanValidationFeatures, PerformBeanValidationFeatures,
22-
GzipFeatures
23+
GzipFeatures, NotNullAnnotationFeatures
2324
{
2425
static final String MEDIA_TYPE = "mediaType";
2526

@@ -52,7 +53,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
5253
protected boolean performBeanValidation = false;
5354
protected boolean useGzipFeature = false;
5455
protected boolean useRuntimeException = false;
55-
56+
private boolean notNullJacksonAnnotation;
5657

5758
public JavaClientCodegen() {
5859
super();
@@ -611,4 +612,13 @@ static boolean isJsonVendorMimeType(String mime) {
611612
return mime != null && JSON_VENDOR_MIME_PATTERN.matcher(mime).matches();
612613
}
613614

615+
@Override
616+
public void setNotNullJacksonAnnotation(boolean notNullJacksonAnnotation) {
617+
this.notNullJacksonAnnotation = notNullJacksonAnnotation;
618+
}
619+
620+
@Override
621+
public boolean isNotNullJacksonAnnotation() {
622+
return notNullJacksonAnnotation;
623+
}
614624
}

0 commit comments

Comments
 (0)