-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
227 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/main/java/io/swagger/codegen/v3/generators/html/HtmlSchemaHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package io.swagger.codegen.v3.generators.html; | ||
|
||
import io.swagger.codegen.v3.CodegenModel; | ||
import io.swagger.codegen.v3.CodegenModelFactory; | ||
import io.swagger.codegen.v3.CodegenModelType; | ||
import io.swagger.codegen.v3.CodegenProperty; | ||
import io.swagger.codegen.v3.generators.DefaultCodegenConfig; | ||
import io.swagger.codegen.v3.generators.SchemaHandler; | ||
import io.swagger.codegen.v3.generators.util.OpenAPIUtil; | ||
import io.swagger.v3.oas.models.media.ComposedSchema; | ||
import io.swagger.v3.oas.models.media.Schema; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class HtmlSchemaHandler extends SchemaHandler { | ||
|
||
public HtmlSchemaHandler(DefaultCodegenConfig codegenConfig) { | ||
super(codegenConfig); | ||
} | ||
|
||
|
||
public void createCodegenModel(ComposedSchema composedProperty, CodegenProperty codegenProperty) { | ||
final List<Schema> oneOf = composedProperty.getOneOf(); | ||
final List<Schema> anyOf = composedProperty.getAnyOf(); | ||
|
||
if (oneOf != null && !oneOf.isEmpty()) { | ||
if (!hasNonObjectSchema(oneOf)) { | ||
final CodegenModel oneOfModel = createFromOneOfSchemas(oneOf); | ||
codegenProperty.vendorExtensions.put("oneOf-model", oneOfModel); | ||
} | ||
} | ||
if (anyOf != null && !anyOf.isEmpty()) { | ||
if (!hasNonObjectSchema(anyOf)) { | ||
final CodegenModel anyOfModel = createFromOneOfSchemas(anyOf); | ||
codegenProperty.vendorExtensions.put("anyOf-model", anyOfModel); | ||
} | ||
} | ||
|
||
} | ||
|
||
public void configureComposedModelFromSchemaItems(CodegenModel codegenModel, ComposedSchema items) { | ||
List<Schema> oneOfList = items.getOneOf(); | ||
if (oneOfList != null && !oneOfList.isEmpty()){ | ||
String name = "OneOf" + codegenModel.name + "Items"; | ||
final CodegenModel oneOfModel = createComposedModel(name); | ||
// setting name to be used as instance type on composed model. | ||
items.addExtension("x-model-name", codegenConfig.toModelName(name)); | ||
|
||
final List<String> modelNames = new ArrayList<>(); | ||
for (Schema interfaceSchema : oneOfList) { | ||
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) { | ||
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref()); | ||
modelNames.add(codegenConfig.toModelName(schemaName)); | ||
} | ||
} | ||
oneOfModel.vendorExtensions.put("x-model-names", modelNames); | ||
if (!modelNames.isEmpty()) { | ||
codegenModel.vendorExtensions.put("oneOf-model", oneOfModel); | ||
} | ||
} | ||
List<Schema> anyOfList = items.getAnyOf(); | ||
if (anyOfList != null && !anyOfList.isEmpty()){ | ||
String name = "AnyOf" + codegenModel.name + "Items"; | ||
final CodegenModel anyOfModel = createComposedModel(name); | ||
items.addExtension("x-model-name", codegenConfig.toModelName(name)); | ||
|
||
final List<String> modelNames = new ArrayList<>(); | ||
for (Schema interfaceSchema : anyOfList) { | ||
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) { | ||
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref()); | ||
modelNames.add(codegenConfig.toModelName(schemaName)); | ||
} | ||
} | ||
anyOfModel.vendorExtensions.put("x-model-names", modelNames); | ||
if (!modelNames.isEmpty()) { | ||
codegenModel.vendorExtensions.put("anyOf-model", anyOfModel); | ||
} | ||
} | ||
} | ||
|
||
public void configureOneOfModel(CodegenModel codegenModel, List<Schema> oneOf) { | ||
// no ops for html generator | ||
} | ||
|
||
public void configureAnyOfModel(CodegenModel codegenModel, List<Schema> anyOf) { | ||
// no ops for html generator | ||
} | ||
|
||
public void configureOneOfModelFromProperty(CodegenProperty codegenProperty, CodegenModel codegenModel) { | ||
// no ops for html generator | ||
} | ||
|
||
public void configureAnyOfModelFromProperty(CodegenProperty codegenProperty, CodegenModel codegenModel) { | ||
// no ops for html generator | ||
} | ||
|
||
private CodegenModel createFromOneOfSchemas(List<Schema> schemas) { | ||
final CodegenModel codegenModel = CodegenModelFactory.newInstance(CodegenModelType.MODEL); | ||
final List<String> modelNames = new ArrayList<>(); | ||
|
||
for (Schema interfaceSchema : schemas) { | ||
if (StringUtils.isNotBlank(interfaceSchema.get$ref())) { | ||
String schemaName = OpenAPIUtil.getSimpleRef(interfaceSchema.get$ref()); | ||
modelNames.add(codegenConfig.toModelName(schemaName)); | ||
} | ||
} | ||
codegenModel.vendorExtensions.put("x-model-names", modelNames); | ||
return codegenModel; | ||
} | ||
|
||
private CodegenModel createComposedModel(String name) { | ||
final CodegenModel composedModel = CodegenModelFactory.newInstance(CodegenModelType.MODEL); | ||
this.configureModel(composedModel, name); | ||
return composedModel; | ||
} | ||
|
||
private void configureModel(CodegenModel codegenModel, String name) { | ||
codegenModel.name = name; | ||
codegenModel.classname = codegenConfig.toModelName(name); | ||
codegenModel.classVarName = codegenConfig.toVarName(name); | ||
codegenModel.classFilename = codegenConfig.toModelFilename(name); | ||
codegenModel.vendorExtensions.put("x-is-composed-model", Boolean.TRUE); | ||
} | ||
|
||
private boolean hasNonObjectSchema(List<Schema> schemas) { | ||
for (Schema schema : schemas) { | ||
if (!codegenConfig.isObjectSchema(schema)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/Java/libraries/retrofit/formParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} | ||
{{~#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}} |
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/Java/libraries/retrofit2/formParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} | ||
{{#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}} |
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/JavaInflector/formParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#is this 'form-param'}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#is this 'file'}}FormDataContentDisposition fileDetail{{/is}}{{/is}} | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}}FormDataContentDisposition fileDetail{{/is}}{{/is}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/JavaJaxRS/cxf-cdi/formParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#is this 'form-param'}}{{#isNot this 'file'}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}} @Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) InputStream {{paramName}}InputStream, @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}} @Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) InputStream {{paramName}}InputStream, @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} |
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/JavaJaxRS/cxf-cdi/serviceFormParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#is this 'form-param'}}{{#isNot this 'file'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}}InputStream {{paramName}}InputStream, Attachment {{paramName}}Detail{{/is}}{{/is}} | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}}InputStream {{paramName}}InputStream, Attachment {{paramName}}Detail{{/is}}{{/is}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/JavaJaxRS/cxf/formParams.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#is this 'form-param'}}{{#isNot this 'file'}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}} @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}@Multipart(value = "{{baseName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}} @Multipart(value = "{{baseName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/is}}{{/is}} |
2 changes: 1 addition & 1 deletion
2
src/main/resources/handlebars/JavaJaxRS/cxf/formParamsImpl.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{{#is this 'form-param'}}{{#isNot this 'file'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'file'}} Attachment {{paramName}}Detail{{/is}}{{/is}} | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{{dataType}}} {{paramName}}{{/isNot}}{{#is this 'binary'}} Attachment {{paramName}}Detail{{/is}}{{/is}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
{{#is this 'form-param'}}{{#isNot this 'file'}}{{#useOas2}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/useOas2}}{{^useOas2}}@Parameter(description = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/useOas2}}{{/isNot}}{{#is this 'file'}}@FormDataParam("{{baseName}}") InputStream {{paramName}}InputStream, | ||
{{#is this 'form-param'}}{{#isNot this 'binary'}}{{#useOas2}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/useOas2}}{{^useOas2}}@Parameter(description = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}} {{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @FormParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/useOas2}}{{/isNot}}{{#is this 'binary'}}@FormDataParam("{{baseName}}") InputStream {{paramName}}InputStream, | ||
@FormDataParam("{{baseName}}") FormDataContentDisposition {{paramName}}Detail{{/is}}{{/is}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.