Skip to content

Commit d52168f

Browse files
Merge branch 'master' into dart-double-cast
2 parents ebd090c + 116344e commit d52168f

File tree

33 files changed

+231
-171
lines changed

33 files changed

+231
-171
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Check out [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) for addit
8989

9090
# Table of contents
9191

92-
- [Swagger Code Generator](#swagger-code-generator)
92+
- [Versioning](#versioning)
9393
- [Overview](#overview)
9494
- [Table of Contents](#table-of-contents)
9595
- Installation
@@ -982,6 +982,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
982982
- [Trexle](https://trexle.com/)
983983
- [Upwork](http://upwork.com/)
984984
- [uShip](https://www.uship.com/)
985+
- [Variograma](https://variograma.pt)
985986
- [VMware](https://vmware.com/)
986987
- [Viavi Solutions Inc.](https://www.viavisolutions.com)
987988
- [W.UP](http://wup.hu/?siteLang=en)
@@ -993,6 +994,7 @@ Here are some companies/projects using Swagger Codegen in production. To add you
993994
- [Zalando](https://tech.zalando.com)
994995
- [ZEEF.com](https://zeef.com/)
995996
- [zooplus](https://www.zooplus.com/)
997+
- [Trifork](https://www.trifork.com/)
996998

997999
Presentations/Videos/Tutorials/Books
9981000
----------------------------------------

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
/**
5151
* Goal which generates client/server code from a swagger json/yaml definition.
5252
*/
53-
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
53+
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
5454
public class CodeGenMojo extends AbstractMojo {
5555

5656
@Parameter(name = "verbose", required = false, defaultValue = "false")
@@ -315,6 +315,13 @@ public class CodeGenMojo extends AbstractMojo {
315315

316316
@Override
317317
public void execute() throws MojoExecutionException {
318+
// Using the naive approach for achieving thread safety
319+
synchronized (CodeGenMojo.class) {
320+
execute_();
321+
}
322+
}
323+
324+
protected void execute_() throws MojoExecutionException {
318325

319326
if (skip) {
320327
getLog().info("Code generation is skipped.");

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,12 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
13981398
List<String> required = new ArrayList<String>();
13991399
Map<String, Property> allProperties;
14001400
List<String> allRequired;
1401+
1402+
List<Model> allComponents = composed.getAllOf();
1403+
if (allComponents.size() > 0 && composed.getParent() == null) {
1404+
rebuildComponents(composed);
1405+
}
1406+
14011407
if (supportsInheritance || supportsMixins) {
14021408
allProperties = new LinkedHashMap<String, Property>();
14031409
allRequired = new ArrayList<String>();
@@ -1477,7 +1483,7 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
14771483

14781484
if(parentName != null) {
14791485
m.parentSchema = parentName;
1480-
m.parent = toModelName(parentName);
1486+
m.parent = typeMapping.containsKey(parentName) ? typeMapping.get(parentName): toModelName(parentName);
14811487
addImport(m, m.parent);
14821488
if (allDefinitions != null) {
14831489
final Model parentModel = allDefinitions.get(m.parentSchema);
@@ -1534,6 +1540,30 @@ public CodegenModel fromModel(String name, Model model, Map<String, Model> allDe
15341540
return m;
15351541
}
15361542

1543+
private void rebuildComponents(ComposedModel composedModel) {
1544+
List<Model> allComponents = composedModel.getAllOf();
1545+
if (allComponents.size() >= 1) {
1546+
composedModel.setParent(allComponents.get(0));
1547+
if (allComponents.size() >= 2) {
1548+
composedModel.setChild(allComponents.get(allComponents.size() - 1));
1549+
List<RefModel> interfaces = new ArrayList();
1550+
int size = allComponents.size();
1551+
Iterator modelIterator = allComponents.subList(1, size - 1).iterator();
1552+
1553+
while(modelIterator.hasNext()) {
1554+
Model model = (Model)modelIterator.next();
1555+
if (model instanceof RefModel) {
1556+
RefModel ref = (RefModel)model;
1557+
interfaces.add(ref);
1558+
}
1559+
}
1560+
composedModel.setInterfaces(interfaces);
1561+
} else {
1562+
composedModel.setChild(new ModelImpl());
1563+
}
1564+
}
1565+
}
1566+
15371567
/**
15381568
* Recursively look for a discriminator in the interface tree
15391569
*/

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
5757
public static final String WITH_XML = "withXml";
5858
public static final String SUPPORT_JAVA6 = "supportJava6";
5959
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
60+
public static final String ERROR_ON_UNKNOWN_ENUM = "errorOnUnknownEnum";
6061

6162
protected String dateLibrary = "threetenbp";
6263
protected boolean supportAsync = false;
@@ -365,6 +366,11 @@ public void processOpts() {
365366
}
366367
additionalProperties.put(WITH_XML, withXml);
367368

369+
if (additionalProperties.containsKey(ERROR_ON_UNKNOWN_ENUM)) {
370+
boolean errorOnUnknownEnum = Boolean.parseBoolean(additionalProperties.get(ERROR_ON_UNKNOWN_ENUM).toString());
371+
additionalProperties.put(ERROR_ON_UNKNOWN_ENUM, errorOnUnknownEnum);
372+
}
373+
368374
// make api and model doc path available in mustache template
369375
additionalProperties.put("apiDocPath", apiDocPath);
370376
additionalProperties.put("modelDocPath", modelDocPath);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
public class CsharpDotNet2ClientCodegen extends AbstractCSharpCodegen {
1111
public static final String CLIENT_PACKAGE = "clientPackage";
12+
public static final String USE_CSPROJ_FILE = "useCsProjFile";
1213
protected String clientPackage = "IO.Swagger.Client";
1314
protected String apiDocPath = "docs/";
1415
protected String modelDocPath = "docs/";
@@ -68,6 +69,9 @@ public void processOpts() {
6869
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor", "packages.config"));
6970
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
7071
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
72+
if (additionalProperties.containsKey(USE_CSPROJ_FILE) && Boolean.parseBoolean(additionalProperties.get(USE_CSPROJ_FILE).toString())) {
73+
supportingFiles.add(new SupportingFile("csproj.mustache", "", clientPackage + ".csproj"));
74+
}
7175

7276
}
7377

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class {{classname}} {
114114
{{localVariablePrefix}}localVarHeaderParams.put("Content-Type", {{localVariablePrefix}}localVarContentType);
115115

116116
if(progressListener != null) {
117-
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
117+
{{localVariablePrefix}}apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
118118
@Override
119119
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
120120
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
@@ -237,7 +237,7 @@ public class {{classname}} {
237237
{{#isDeprecated}}
238238
@Deprecated
239239
{{/isDeprecated}}
240-
public com.squareup.okhttp.Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException {
240+
public com.squareup.okhttp.Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> callback) throws ApiException {
241241
242242
ProgressResponseBody.ProgressListener progressListener = null;
243243
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@@ -260,9 +260,9 @@ public class {{classname}} {
260260

261261
com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
262262
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
263-
{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType, {{localVariablePrefix}}callback);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}callback);{{/returnType}}
263+
{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType, callback);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, callback);{{/returnType}}
264264
return {{localVariablePrefix}}call;
265265
}
266266
{{/operation}}
267267
}
268-
{{/operations}}
268+
{{/operations}}

modules/swagger-codegen/src/main/resources/Java/modelEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
4848
return b;
4949
}
5050
}
51-
return null;
51+
{{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}' enum.");{{/errorOnUnknownEnum}}
5252
}
5353
{{#gson}}
5454

modules/swagger-codegen/src/main/resources/Java/modelInnerEnum.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
return b;
4040
}
4141
}
42-
return null;
42+
{{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}' enum.");{{/errorOnUnknownEnum}}
4343
}
4444
{{#gson}}
4545

modules/swagger-codegen/src/main/resources/JavaInflector/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
return b;
4040
}
4141
}
42-
return null;
42+
{{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}' enum.");{{/errorOnUnknownEnum}}
4343
}
4444
}

modules/swagger-codegen/src/main/resources/JavaInflector/enumOuterClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
3737
return b;
3838
}
3939
}
40-
return null;
40+
{{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}' enum.");{{/errorOnUnknownEnum}}
4141
}
4242
}

0 commit comments

Comments
 (0)