-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[Spring][server] oneOf Polymorphism support for spring boot #5661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 12 commits
6a8769e
049359c
49f13eb
1a5a484
66a09d2
48a1a4a
a811330
299cdb3
461cbc8
dd0118d
26a95f6
9af7db6
fbfd57d
bfab304
29003d8
d864831
6d54799
fe7fd56
9b586fa
07df40c
15b362a
f0aeb8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ | |
| import io.swagger.v3.oas.models.OpenAPI; | ||
| import io.swagger.v3.oas.models.Operation; | ||
| import io.swagger.v3.oas.models.PathItem; | ||
| import io.swagger.v3.oas.models.media.ComposedSchema; | ||
| import io.swagger.v3.oas.models.media.Schema; | ||
| import java.util.Map.Entry; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
| import org.openapitools.codegen.*; | ||
| import org.openapitools.codegen.languages.features.BeanValidationFeatures; | ||
|
|
@@ -233,7 +236,7 @@ public void processOpts() { | |
| } | ||
|
|
||
| super.processOpts(); | ||
|
|
||
| useOneOfInterfaces = true; | ||
| // clear model and api doc template as this codegen | ||
| // does not support auto-generated markdown doc at the moment | ||
| //TODO: add doc templates | ||
|
|
@@ -581,6 +584,34 @@ public void preprocessOpenAPI(OpenAPI openAPI) { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void addOneOfForComposedSchema(Entry<String, Schema> stringSchemaEntry, String modelName, ComposedSchema composedSchema, | ||
| String nOneOf){ | ||
| if (useOneOfInterfaces) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useOneOfInterfaces is always true?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, you are right useOneOfInterfaces is always true, i will change the code, that there is no if cases anymore.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Scorpioncik please review this pull request again. |
||
| // if this is property schema, we also need to generate the oneOf interface model | ||
| addOneOfNameExtension(composedSchema, nOneOf); | ||
| addOneOfInterfaceModel(composedSchema, nOneOf); | ||
| } else { | ||
| super.addOneOfForComposedSchema(stringSchemaEntry, modelName, composedSchema, nOneOf); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected String getCodegenModelName(CodegenProperty codegenProperty) { | ||
| if (useOneOfInterfaces){ | ||
| return codegenProperty.getComplexType(); | ||
| } else { | ||
| return super.getCodegenModelName(codegenProperty); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void addAdditionalImports(Set<String> imports, String complexType) { | ||
| if (!useOneOfInterfaces){ | ||
| super.addAdditionalImports(imports, complexType); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) { | ||
| Map<String, Object> operations = (Map<String, Object>) objs.get("operations"); | ||
|
|
@@ -898,4 +929,16 @@ public void postProcessParameter(CodegenParameter p) { | |
| } | ||
| } | ||
|
|
||
| } | ||
| @Override | ||
| public void addImportsToOneOfInterface(List<Map<String, String>> imports) { | ||
| for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) { | ||
| Map<String, String> oneImport = new HashMap<String, String>() {{ | ||
| put("import", importMapping.get(i)); | ||
| }}; | ||
| if (!imports.contains(oneImport)) { | ||
| imports.add(oneImport); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| {{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}} | ||
| public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { | ||
|
alexsuperdev marked this conversation as resolved.
|
||
| {{#discriminator}} | ||
| public {{propertyType}} {{propertyGetter}}(); | ||
| {{/discriminator}} | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.