mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Issue 4244 - Add x-discriminator-value (#4252)
* Fixes for issue 4226. Detects and warns about more than one inline object; sets discriminator on CodegenModel; Adds templates to other Java languages Changes to be committed: modified: modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java modified: modules/swagger-codegen/src/main/resources/Java/typeInfoAnnotation.mustache new file: modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache new file: modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache new file: modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache * Add vendor extension for x-discriminator-value Changes to be committed: modified: modules/swagger-codegen/src/main/resources/Java/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache * Add "visible = true" to @JsonTypeInfo jackson annotations for Java languages Changes to be committed: modified: modules/swagger-codegen/src/main/resources/Java/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaInflector/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaJaxRS/typeInfoAnnotation.mustache modified: modules/swagger-codegen/src/main/resources/JavaSpring/typeInfoAnnotation.mustache
This commit is contained in:
parent
26ead9b58f
commit
380bed15d3
@ -186,12 +186,18 @@ public class DefaultCodegen {
|
||||
for (String name : allModels.keySet()) {
|
||||
CodegenModel cm = allModels.get(name);
|
||||
CodegenModel parent = allModels.get(cm.parent);
|
||||
// if a discriminator exists on the parent, don't add this child to the inheritance heirarchy
|
||||
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
|
||||
while (parent != null) {
|
||||
if (parent.children == null) {
|
||||
parent.children = new ArrayList<CodegenModel>();
|
||||
parent.children = new ArrayList<CodegenModel>();
|
||||
}
|
||||
parent.children.add(cm);
|
||||
parent = allModels.get(parent.parent);
|
||||
if (parent.discriminator == null) {
|
||||
parent = allModels.get(parent.parent);
|
||||
} else {
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1270,6 +1276,18 @@ public class DefaultCodegen {
|
||||
allProperties = new LinkedHashMap<String, Property>();
|
||||
allRequired = new ArrayList<String>();
|
||||
m.allVars = new ArrayList<CodegenProperty>();
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Model innerModel: ((ComposedModel)model).getAllOf()) {
|
||||
if (innerModel instanceof ModelImpl) {
|
||||
if (m.discriminator == null) {
|
||||
m.discriminator = ((ModelImpl) innerModel).getDiscriminator();
|
||||
}
|
||||
if (modelImplCnt++ > 1) {
|
||||
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
|
||||
break; // only one ModelImpl with discriminator allowed in allOf
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allProperties = null;
|
||||
allRequired = null;
|
||||
|
@ -1,5 +1,7 @@
|
||||
{{#jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}" )
|
||||
@JsonSubTypes({
|
||||
{{#children}}@JsonSubTypes.Type(value = {{name}}.class, name = "{{name}}"),{{/children}}
|
||||
}){{/jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
|
||||
@JsonSubTypes({
|
||||
{{#children}}
|
||||
@JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{/children}}
|
||||
}){{/jackson}}
|
||||
|
@ -0,0 +1,7 @@
|
||||
{{#jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
|
||||
@JsonSubTypes({
|
||||
{{#children}}
|
||||
@JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{/children}}
|
||||
}){{/jackson}}
|
@ -0,0 +1,7 @@
|
||||
{{#jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
|
||||
@JsonSubTypes({
|
||||
{{#children}}
|
||||
@JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{/children}}
|
||||
}){{/jackson}}
|
@ -0,0 +1,7 @@
|
||||
{{#jackson}}
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{discriminator}}", visible = true )
|
||||
@JsonSubTypes({
|
||||
{{#children}}
|
||||
@JsonSubTypes.Type(value = {{name}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"),
|
||||
{{/children}}
|
||||
}){{/jackson}}
|
Loading…
Reference in New Issue
Block a user