forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for discriminator.mapping (OpenAPITools#536)
- Loading branch information
Showing
94 changed files
with
1,149 additions
and
307 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenDiscriminator.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,88 @@ | ||
package org.openapitools.codegen; | ||
|
||
import java.util.*; | ||
|
||
public class CodegenDiscriminator { | ||
private String propertyName; | ||
private Map<String, String> mapping; | ||
private Set<MappedModel> mappedModels = new LinkedHashSet<>(); | ||
|
||
public String getPropertyName() { | ||
return propertyName; | ||
} | ||
|
||
public void setPropertyName(String propertyName) { | ||
this.propertyName = propertyName; | ||
} | ||
|
||
public Map<String, String> getMapping() { | ||
return mapping; | ||
} | ||
|
||
public void setMapping(Map<String, String> mapping) { | ||
this.mapping = mapping; | ||
} | ||
|
||
public Set<MappedModel> getMappedModels() { | ||
return mappedModels; | ||
} | ||
|
||
public void setMappedModels(Set<MappedModel> mappedModels) { | ||
this.mappedModels = mappedModels; | ||
} | ||
|
||
public static class MappedModel { | ||
private String mappingName; | ||
private String modelName; | ||
|
||
public MappedModel(String mappingName, String modelName) { | ||
this.mappingName = mappingName; | ||
this.modelName = modelName; | ||
} | ||
|
||
public String getMappingName() { | ||
return mappingName; | ||
} | ||
|
||
public void setMappingName(String mappingName) { | ||
this.mappingName = mappingName; | ||
} | ||
|
||
public String getModelName() { | ||
return modelName; | ||
} | ||
|
||
public void setModelName(String modelName) { | ||
this.modelName = modelName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MappedModel that = (MappedModel) o; | ||
return Objects.equals(mappingName, that.mappingName) && | ||
Objects.equals(modelName, that.modelName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(mappingName, modelName); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
CodegenDiscriminator that = (CodegenDiscriminator) o; | ||
return Objects.equals(propertyName, that.propertyName) && | ||
Objects.equals(mapping, that.mapping) && | ||
Objects.equals(mappedModels, that.mappedModels); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(propertyName, mapping, mappedModels); | ||
} | ||
} |
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
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
9 changes: 5 additions & 4 deletions
9
modules/openapi-generator/src/main/resources/Java/typeInfoAnnotation.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,7 +1,8 @@ | ||
{{#jackson}} | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true ) | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true) | ||
@JsonSubTypes({ | ||
{{#children}} | ||
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), | ||
{{/children}} | ||
{{#discriminator.mappedModels}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), | ||
{{/discriminator.mappedModels}} | ||
}){{/jackson}} |
9 changes: 5 additions & 4 deletions
9
modules/openapi-generator/src/main/resources/JavaInflector/typeInfoAnnotation.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,7 +1,8 @@ | ||
{{#jackson}} | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true ) | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminatorName}}}", visible = true) | ||
@JsonSubTypes({ | ||
{{#children}} | ||
@JsonSubTypes.Type(value = {{classname}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), | ||
{{/children}} | ||
{{#discriminator.mappedModels}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{^vendorExtensions.x-discriminator-value}}{{mappingName}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}"), | ||
{{/discriminator.mappedModels}} | ||
}){{/jackson}} |
Oops, something went wrong.