Skip to content

Commit 7eb1e9c

Browse files
authored
Merge branch 'master' into master
2 parents 422780d + d466104 commit 7eb1e9c

Some content is hidden

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

45 files changed

+227
-82
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ private static String getTypeOfSchema(Schema schema) {
10771077
} else if (schema instanceof BinarySchema) {
10781078
return SchemaTypeUtil.BINARY_FORMAT;
10791079
} else if (schema instanceof FileSchema) {
1080-
return "file"; // FIXME: this type does not exist in the OpenAPI 3.0 specification
1080+
return SchemaTypeUtil.BINARY_FORMAT;
10811081
} else if (schema instanceof BooleanSchema) {
10821082
return SchemaTypeUtil.BOOLEAN_TYPE;
10831083
} else if (schema instanceof DateSchema) {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package io.swagger.codegen.v3.generators.html;
2+
3+
import io.swagger.codegen.v3.CodegenModel;
4+
import io.swagger.codegen.v3.CodegenModelFactory;
5+
import io.swagger.codegen.v3.CodegenModelType;
6+
import io.swagger.codegen.v3.CodegenProperty;
7+
import io.swagger.codegen.v3.generators.DefaultCodegenConfig;
8+
import io.swagger.codegen.v3.generators.SchemaHandler;
9+
import io.swagger.codegen.v3.generators.util.OpenAPIUtil;
10+
import io.swagger.v3.oas.models.media.ComposedSchema;
11+
import io.swagger.v3.oas.models.media.Schema;
12+
import org.apache.commons.lang3.StringUtils;
13+
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
public class HtmlSchemaHandler extends SchemaHandler {
18+
19+
public HtmlSchemaHandler(DefaultCodegenConfig codegenConfig) {
20+
super(codegenConfig);
21+
}
22+
23+
24+
public void createCodegenModel(ComposedSchema composedProperty, CodegenProperty codegenProperty) {
25+
final List<Schema> oneOf = composedProperty.getOneOf();
26+
final List<Schema> anyOf = composedProperty.getAnyOf();
27+
28+
if (oneOf != null && !oneOf.isEmpty()) {
29+
if (!hasNonObjectSchema(oneOf)) {
30+
final CodegenModel oneOfModel = createFromOneOfSchemas(oneOf);
31+
codegenProperty.vendorExtensions.put("oneOf-model", oneOfModel);
32+
}
33+
}
34+
if (anyOf != null && !anyOf.isEmpty()) {
35+
if (!hasNonObjectSchema(anyOf)) {
36+
final CodegenModel anyOfModel = createFromOneOfSchemas(anyOf);
37+
codegenProperty.vendorExtensions.put("anyOf-model", anyOfModel);
38+
}
39+
}
40+
41+
}
42+
43+
public void configureComposedModelFromSchemaItems(CodegenModel codegenModel, ComposedSchema items) {
44+
List<Schema> oneOfList = items.getOneOf();
45+
if (oneOfList != null && !oneOfList.isEmpty()){
46+
String name = "OneOf" + codegenModel.name + "Items";
47+
final CodegenModel oneOfModel = createComposedModel(name);
48+
// setting name to be used as instance type on composed model.
49+
items.addExtension("x-model-name", codegenConfig.toModelName(name));
50+
51+
final List<String> modelNames = new ArrayList<>();
52+
for (Schema interfaceSchema : oneOfList) {
53+
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) {
54+
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref());
55+
modelNames.add(codegenConfig.toModelName(schemaName));
56+
}
57+
}
58+
oneOfModel.vendorExtensions.put("x-model-names", modelNames);
59+
if (!modelNames.isEmpty()) {
60+
codegenModel.vendorExtensions.put("oneOf-model", oneOfModel);
61+
}
62+
}
63+
List<Schema> anyOfList = items.getAnyOf();
64+
if (anyOfList != null && !anyOfList.isEmpty()){
65+
String name = "AnyOf" + codegenModel.name + "Items";
66+
final CodegenModel anyOfModel = createComposedModel(name);
67+
items.addExtension("x-model-name", codegenConfig.toModelName(name));
68+
69+
final List<String> modelNames = new ArrayList<>();
70+
for (Schema interfaceSchema : anyOfList) {
71+
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) {
72+
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref());
73+
modelNames.add(codegenConfig.toModelName(schemaName));
74+
}
75+
}
76+
anyOfModel.vendorExtensions.put("x-model-names", modelNames);
77+
if (!modelNames.isEmpty()) {
78+
codegenModel.vendorExtensions.put("anyOf-model", anyOfModel);
79+
}
80+
}
81+
}
82+
83+
public void configureOneOfModel(CodegenModel codegenModel, List<Schema> oneOf) {
84+
// no ops for html generator
85+
}
86+
87+
public void configureAnyOfModel(CodegenModel codegenModel, List<Schema> anyOf) {
88+
// no ops for html generator
89+
}
90+
91+
public void configureOneOfModelFromProperty(CodegenProperty codegenProperty, CodegenModel codegenModel) {
92+
// no ops for html generator
93+
}
94+
95+
public void configureAnyOfModelFromProperty(CodegenProperty codegenProperty, CodegenModel codegenModel) {
96+
// no ops for html generator
97+
}
98+
99+
private CodegenModel createFromOneOfSchemas(List<Schema> schemas) {
100+
final CodegenModel codegenModel = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
101+
final List<String> modelNames = new ArrayList<>();
102+
103+
for (Schema interfaceSchema : schemas) {
104+
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) {
105+
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref());
106+
modelNames.add(codegenConfig.toModelName(schemaName));
107+
}
108+
}
109+
codegenModel.vendorExtensions.put("x-model-names", modelNames);
110+
return codegenModel;
111+
}
112+
113+
private CodegenModel createComposedModel(String name) {
114+
final CodegenModel composedModel = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
115+
this.configureModel(composedModel, name);
116+
return composedModel;
117+
}
118+
119+
private void configureModel(CodegenModel codegenModel, String name) {
120+
codegenModel.name = name;
121+
codegenModel.classname = codegenConfig.toModelName(name);
122+
codegenModel.classVarName = codegenConfig.toVarName(name);
123+
codegenModel.classFilename = codegenConfig.toModelFilename(name);
124+
codegenModel.vendorExtensions.put("x-is-composed-model", Boolean.TRUE);
125+
}
126+
127+
private boolean hasNonObjectSchema(List<Schema> schemas) {
128+
for (Schema schema : schemas) {
129+
if (!codegenConfig.isObjectSchema(schema)) {
130+
return true;
131+
}
132+
}
133+
return false;
134+
}
135+
}

src/main/java/io/swagger/codegen/v3/generators/html/StaticHtmlCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class StaticHtmlCodegen extends DefaultCodegenConfig {
3232

3333
public StaticHtmlCodegen() {
3434
super();
35+
schemaHandler = new HtmlSchemaHandler(this);
3536
outputFolder = "docs";
3637

3738
defaultIncludes = new HashSet<String>();
@@ -155,7 +156,7 @@ public String escapeUnsafeCharacters(String input) {
155156

156157
/**
157158
* Convert Markdown text to HTML
158-
*
159+
*
159160
* @param input
160161
* text in Markdown; may be null.
161162
* @return the text, converted to Markdown. For null input, "" is returned.

src/main/resources/handlebars/Java/api_doc.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ try {
6363
{{^parameters}}This endpoint does not need any parameter.{{/parameters}}{{#parameters}}{{#@last}}
6464
Name | Type | Description | Notes
6565
------------- | ------------- | ------------- | -------------{{/@last}}{{/parameters}}
66-
{{#parameters}} **{{paramName}}** | {{#is this 'primitive-type'}}**{{dataType}}**{{/is}}{{#isNot this 'primitive-type'}}{{#is this 'file'}}**{{dataType}}**{{/is}}{{#isNot this 'file'}}[**{{dataType}}**]({{baseType}}.md){{/isNot}}{{/isNot}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}]{{/allowableValues}}
66+
{{#parameters}} **{{paramName}}** | {{#is this 'primitive-type'}}**{{dataType}}**{{/is}}{{#isNot this 'primitive-type'}}{{#isBinary}}**{{dataType}}**{{/isBinary}}{{^isBinary}}[**{{dataType}}**]({{baseType}}.md){{/isBinary}}{{/isNot}}| {{description}} |{{^required}} [optional]{{/required}}{{#defaultValue}} [default to {{defaultValue}}]{{/defaultValue}}{{#allowableValues}} [enum: {{#values}}{{{.}}}{{^@last}}, {{/@last}}{{/values}}]{{/allowableValues}}
6767
{{/parameters}}
6868

6969
### Return type

src/main/resources/handlebars/Java/libraries/resttemplate/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class {{classname}} {
103103
{{#hasFormParams}}
104104
{{#formParams}}
105105
if ({{paramName}} != null)
106-
{{localVariablePrefix}}formParams.add("{{baseName}}", {{#is this 'file'}}new FileSystemResource({{paramName}}){{/is}}{{#isNot this 'file'}}{{paramName}}{{/isNot}});
106+
{{localVariablePrefix}}formParams.add("{{baseName}}", {{#is this 'binary'}}new FileSystemResource({{paramName}}){{/is}}{{#isNot this 'binary'}}{{paramName}}{{/isNot}});
107107
{{/formParams}}
108108
{{/hasFormParams}}
109109

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{~#is this 'form-param'}}{{#isNot this 'file'}}{{#is ../this 'multipart'}}@retrofit.http.Part{{/is}}{{#isNot ../this 'multipart'}}@retrofit.http.Field{{/isNot}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}}{{#is ../this 'multipart'}}@retrofit.http.Part{{/is}}{{#isNot ../this 'multipart'}}@retrofit.http.Field{{/isNot}}("{{baseName}}") TypedFile {{paramName}}{{/is}}{{/is}}
1+
{{~#is this 'form-param'}}{{#isNot this 'binary'}}{{#is ../this 'multipart'}}@retrofit.http.Part{{/is}}{{#isNot ../this 'multipart'}}@retrofit.http.Field{{/isNot}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}}{{#is ../this 'multipart'}}@retrofit.http.Part{{/is}}{{#isNot ../this 'multipart'}}@retrofit.http.Field{{/isNot}}("{{baseName}}") TypedFile {{paramName}}{{/is}}{{/is}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#is this 'form-param'}}{{#isNot this 'file'}}{{#is this 'multipart'}}@retrofit2.http.Part{{/is}}{{#isNot this 'multipart'}}@retrofit2.http.Field{{/isNot}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}}{{#is this 'multipart'}}@retrofit2.http.Part{{/is}}{{#isNot this 'multipart'}}@retrofit2.http.Field{{/isNot}}{{#usePlayWS}} okhttp3.MultipartBody.Part {{/usePlayWS}}{{^usePlayWS}}("{{baseName}}\"; filename=\"{{baseName}}") RequestBody {{/usePlayWS}}{{paramName}}{{/is}}{{/is}}
1+
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{#is this 'multipart'}}@retrofit2.http.Part{{/is}}{{#isNot this 'multipart'}}@retrofit2.http.Field{{/isNot}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}}{{#is this 'multipart'}}@retrofit2.http.Part{{/is}}{{#isNot this 'multipart'}}@retrofit2.http.Field{{/isNot}}{{#usePlayWS}} okhttp3.MultipartBody.Part {{/usePlayWS}}{{^usePlayWS}}("{{baseName}}\"; filename=\"{{baseName}}") RequestBody {{/usePlayWS}}{{paramName}}{{/is}}{{/is}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}FormDataContentDisposition fileDetail{{/is}}{{/is}}
1+
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}}FormDataContentDisposition fileDetail{{/is}}{{/is}}

src/main/resources/handlebars/JavaJaxRS/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class {{classname}} {
106106
{{/useOas2}}
107107
public Response {{nickname}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}},{{/parameters}}@Context SecurityContext securityContext)
108108
throws NotFoundException {
109-
return delegate.{{nickname}}({{#parameters}}{{#isFile}}{{paramName}}InputStream, {{paramName}}Detail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}},{{/parameters}}securityContext);
109+
return delegate.{{nickname}}({{#parameters}}{{#isBinary}}{{paramName}}InputStream, {{paramName}}Detail{{/isBinary}}{{^isBinary}}{{paramName}}{{/isBinary}},{{/parameters}}securityContext);
110110
}
111111
{{/contents}}
112112
{{/operation}}

src/main/resources/handlebars/JavaJaxRS/cxf-cdi/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class {{classname}} {
7979
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{^vendorExtensions.x-java-is-response-void}}, content = @Content({{^containerType}}schema = @Schema(implementation = {{{baseType}}}.class)){{/containerType}}{{#containerType}}array = @ArraySchema(schema = @Schema(implementation = {{{baseType}}}.class))){{/containerType}}{{/vendorExtensions.x-java-is-response-void}}){{#hasMore}},{{/hasMore}}{{/responses}} })
8080
{{/useOas2}}
8181
public Response {{nickname}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) {
82-
return delegate.{{nickname}}({{#parameters}}{{#isFile}}{{paramName}}InputStream, {{paramName}}Detail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}, {{/parameters}}securityContext);
82+
return delegate.{{nickname}}({{#parameters}}{{#isBinary}}{{paramName}}InputStream, {{paramName}}Detail{{/isBinary}}{{^isBinary}}{{paramName}}{{/isBinary}}, {{/parameters}}securityContext);
8383
}
8484
{{/contents}}
8585
{{/operation}}

0 commit comments

Comments
 (0)