-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade to openapi generator 7.11 (#2517)
Upgraded to openapi generator version 7.11. One of our issues was fixed in this version but we got two new issues back for which I added workarounds.. It looks like both are caused by the new support for JSON-B polymorphism type annotations introduced by OpenAPITools/openapi-generator#20164: Solves PZ-5160
- Loading branch information
Showing
9 changed files
with
217 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
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
64 changes: 0 additions & 64 deletions
64
src/main/resources/openapi-generator-templates/model.mustache
This file was deleted.
Oops, something went wrong.
166 changes: 166 additions & 0 deletions
166
src/main/resources/openapi-generator-templates/pojo.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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
{{! Lifely/INFO temporary workaround for the issue where the OpenAPI Generator Gradle plugin }} | ||
{{! incorrectly generates '@JsonbTransient' annotations for certain 'type' fields in polymorphic model classes }} | ||
{{! which has the result that these fields are not serialized and deserialized leading to errors in the various APIs we use. }} | ||
{{! For example in the generated BRP 'PersonenQuery.java' class the 'type' String field was given the '@JsonbTransient' annotation }} | ||
{{! which breaks the ZAC BRP API integration because this is mandatory field in the BRP API. }} | ||
{{! This was most likely introduced by: https://github.com/OpenAPITools/openapi-generator/pull/20164 }} | ||
{{! It may also be that the BRP OpenAPI spec does not use the discriminator keyword correctly since these 'type' fields are simple strings. }} | ||
{{! and not polymorphic structures. Also see: https://apidog.com/blog/openapi-discriminator-guide/ }} | ||
|
||
{{! This template is based on a copy of the Java Mustache model template of the main branch of https://github.com/OpenAPITools/openapi-generator }} | ||
{{! This workaround can be removed once we have migrated to a version of the OpenAPI Generator Gradle plugin that has solved this issue. }} | ||
|
||
{{#withXml}} | ||
{{#hasVars}}@XmlType(name = "{{classname}}", propOrder = | ||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}} } | ||
){{/hasVars}} | ||
{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}} | ||
{{> xmlAnnotation }} | ||
{{/withXml}} | ||
{{#jackson}} | ||
@JsonPropertyOrder({ | ||
{{#vars}} | ||
{{classname}}.JSON_PROPERTY_{{nameInSnakeCase}}{{^-last}},{{/-last}} | ||
{{/vars}} | ||
}) | ||
{{#isClassnameSanitized}} | ||
{{^hasDiscriminatorWithNonEmptyMapping}} | ||
@JsonTypeName("{{name}}") | ||
{{/hasDiscriminatorWithNonEmptyMapping}} | ||
{{/isClassnameSanitized}} | ||
{{/jackson}} | ||
{{#description}} | ||
/** | ||
* {{{.}}} | ||
*/ | ||
{{/description}} | ||
{{>additionalModelTypeAnnotations}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}} | ||
{{#vendorExtensions.x-class-extra-annotation}} | ||
{{{vendorExtensions.x-class-extra-annotation}}} | ||
{{/vendorExtensions.x-class-extra-annotation}} | ||
public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { | ||
{{#vars}}{{#isEnum}}{{^isContainer}} | ||
{{>enumClass}}{{/isContainer}}{{#isContainer}}{{#mostInnerItems}} | ||
{{>enumClass}}{{/mostInnerItems}}{{/isContainer}}{{/isEnum}} | ||
{{#jackson}} | ||
public static final String JSON_PROPERTY_{{nameInSnakeCase}} = "{{baseName}}"; | ||
{{/jackson}} | ||
{{#withXml}} | ||
@Xml{{#isXmlAttribute}}Attribute{{/isXmlAttribute}}{{^isXmlAttribute}}Element{{/isXmlAttribute}}(name = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) | ||
{{#isXmlWrapped}} | ||
@XmlElementWrapper(name = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}"{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) | ||
{{/isXmlWrapped}} | ||
{{/withXml}} | ||
{{#description}} | ||
/** | ||
* {{{.}}} | ||
*/ | ||
{{/description}} | ||
{{^withXml}} | ||
{{! Lifely/INFO. Changed this line to prevent the generation of the @JsonbTransient annotation for polymorphism. See reasons above. }} | ||
{{#jsonb}}@JsonbProperty("{{baseName}}"){{/jsonb}} | ||
{{! Lifely/INFO. End of change. }} | ||
{{/withXml}} | ||
{{#vendorExtensions.x-field-extra-annotation}} | ||
{{{vendorExtensions.x-field-extra-annotation}}} | ||
{{/vendorExtensions.x-field-extra-annotation}} | ||
{{#isContainer}} | ||
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}}; | ||
{{/isContainer}} | ||
{{^isContainer}} | ||
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}; | ||
{{/isContainer}} | ||
{{/vars}} | ||
{{#vendorExtensions.x-has-readonly-properties}}{{^withXml}} | ||
public {{classname}}() { | ||
} | ||
|
||
{{#jsonb}}@JsonbCreator{{/jsonb}}{{#jackson}}@JsonCreator{{/jackson}} | ||
public {{classname}}( | ||
{{#readOnlyVars}} | ||
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nillable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}{{#required}}, required = true{{/required}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}} | ||
{{/readOnlyVars}} | ||
) { | ||
{{#readOnlyVars}} | ||
this.{{name}} = {{name}}; | ||
{{/readOnlyVars}} | ||
} | ||
{{/withXml}}{{/vendorExtensions.x-has-readonly-properties}} | ||
{{#vars}} | ||
/** | ||
{{#description}} | ||
* {{.}} | ||
{{/description}} | ||
{{^description}} | ||
* Get {{name}} | ||
{{/description}} | ||
{{#minimum}} | ||
* minimum: {{.}} | ||
{{/minimum}} | ||
{{#maximum}} | ||
* maximum: {{.}} | ||
{{/maximum}} | ||
* @return {{name}} | ||
{{#deprecated}} | ||
* @deprecated | ||
{{/deprecated}} | ||
**/ | ||
{{#deprecated}} | ||
@Deprecated | ||
{{/deprecated}} | ||
{{#vendorExtensions.x-extra-annotation}} | ||
{{{vendorExtensions.x-extra-annotation}}} | ||
{{/vendorExtensions.x-extra-annotation}} | ||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}{{#jackson}}{{> jackson_annotations}}{{/jackson}} {{#withXml}}{{#isEnum}}{{^isArray}}{{^isMap}} public {{dataType}} {{getter}}() { | ||
if ({{name}} == null) { | ||
return null; | ||
} | ||
return {{name}}.value(); | ||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{^withXml}}{{#isEnum}}{{^isArray}}{{^isMap}}public {{datatypeWithEnum}} {{getter}}() { | ||
return {{name}}; | ||
}{{/isMap}}{{/isArray}}{{/isEnum}}{{/withXml}}{{#isEnum}}{{#isArray}}public {{{datatypeWithEnum}}} {{getter}}() { | ||
return {{name}}; | ||
}{{/isArray}}{{/isEnum}}{{#isEnum}}{{#isMap}}public {{{datatypeWithEnum}}} {{getter}}() { | ||
return {{name}}; | ||
}{{/isMap}}{{/isEnum}}{{^isEnum}}public {{{datatypeWithEnum}}} {{getter}}() { | ||
return {{name}}; | ||
}{{/isEnum}} | ||
|
||
{{^isReadOnly}} | ||
/** | ||
* Set {{name}} | ||
*/ | ||
{{#vendorExtensions.x-setter-extra-annotation}} {{{vendorExtensions.x-setter-extra-annotation}}} | ||
{{/vendorExtensions.x-setter-extra-annotation}}{{#jackson}}{{> jackson_annotations}}{{/jackson}} public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { | ||
this.{{name}} = {{name}}; | ||
} | ||
|
||
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { | ||
this.{{name}} = {{name}}; | ||
return this; | ||
} | ||
{{#isArray}} | ||
|
||
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { | ||
if (this.{{name}} == null) { | ||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}; | ||
} | ||
this.{{name}}.add({{name}}Item); | ||
return this; | ||
} | ||
{{/isArray}} | ||
{{#isMap}} | ||
|
||
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { | ||
if (this.{{name}} == null) { | ||
this.{{name}} = {{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}; | ||
} | ||
this.{{name}}.put(key, {{name}}Item); | ||
return this; | ||
} | ||
{{/isMap}} | ||
{{/isReadOnly}} | ||
|
||
{{/vars}} | ||
{{>pojoOverrides}} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/resources/openapi-generator-templates/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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{! Lifely/INFO temporary workaround for the issue where the OpenAPI Generator Gradle plugin }} | ||
{{! generates '@JsonbTypeInfo(key = "type")' annotations in the generated model classes both for }} | ||
{{! parent and child polymorphic classes resulting in errors such as: }} | ||
{{! "Caused by: jakarta.json.bind.JsonbException: One polymorphic chain cannot have two conflicting property names. }} | ||
{{! Polymorphic type defined on the type net.atos.client.bag.model.generated.Standplaats }} | ||
{{! and net.atos.client.bag.model.generated.AdresseerbaarObject have conflicting property name" }} | ||
{{! This was most likely introduced by: https://github.com/OpenAPITools/openapi-generator/pull/20164 }} | ||
|
||
{{! This template is based on a copy of the Java Mustache model template of the main branch of https://github.com/OpenAPITools/openapi-generator }} | ||
{{! This workaround can be removed once we have migrated to a version of the OpenAPI Generator Gradle plugin that has solved this issue. }} | ||
|
||
{{#jackson}} | ||
|
||
@JsonIgnoreProperties( | ||
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization | ||
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization | ||
) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true) | ||
{{#discriminator.mappedModels}} | ||
{{#-first}} | ||
@JsonSubTypes({ | ||
{{/-first}} | ||
@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}}"), | ||
{{#-last}} | ||
}) | ||
{{/-last}} | ||
{{/discriminator.mappedModels}} | ||
{{/jackson}} | ||
{{#jsonbPolymorphism}} | ||
{{! Workaround Lifely/INFO: the original code has been removed for reasons see above }} | ||
{{/jsonbPolymorphism}} |
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.