diff --git a/.changeset/khaki-avocados-hammer.md b/.changeset/khaki-avocados-hammer.md new file mode 100644 index 00000000..9e497cf7 --- /dev/null +++ b/.changeset/khaki-avocados-hammer.md @@ -0,0 +1,6 @@ +--- +"@openapi-generator-plus/java-jaxrs-generator-common": minor +"@openapi-generator-plus/java-jaxrs-server-generator": minor +--- + +Add more metadata annotations to enums and improve `@Schema` annotations on models diff --git a/packages/java-jaxrs-common/templates/enum.hbs b/packages/java-jaxrs-common/templates/enum.hbs index 8b7f6054..8d75abd5 100644 --- a/packages/java-jaxrs-common/templates/enum.hbs +++ b/packages/java-jaxrs-common/templates/enum.hbs @@ -3,8 +3,7 @@ package {{modelPackage}}; {{#with enum}} {{>frag/pojoDocumentation}} {{>generatedAnnotation}} -@{{javax}}.xml.bind.annotation.XmlType(name = "{{className name}}") -@{{javax}}.xml.bind.annotation.XmlEnum({{enumValueNativeType}}.class) +{{>frag/enumHeader}} public enum {{className name}} { {{>enumContents}} } diff --git a/packages/java-jaxrs-common/templates/enumNested.hbs b/packages/java-jaxrs-common/templates/enumNested.hbs index 36871967..614c9125 100644 --- a/packages/java-jaxrs-common/templates/enumNested.hbs +++ b/packages/java-jaxrs-common/templates/enumNested.hbs @@ -1,5 +1,5 @@ -@{{javax}}.xml.bind.annotation.XmlType(name = "{{className name}}") -@{{javax}}.xml.bind.annotation.XmlEnum({{enumValueNativeType}}.class) +{{>frag/pojoDocumentation}} +{{>frag/enumHeader}} public enum {{className name}} { {{>enumContents}} } diff --git a/packages/java-jaxrs-common/templates/frag/enumHeader.hbs b/packages/java-jaxrs-common/templates/frag/enumHeader.hbs new file mode 100644 index 00000000..80a42325 --- /dev/null +++ b/packages/java-jaxrs-common/templates/frag/enumHeader.hbs @@ -0,0 +1,9 @@ +{{>hooks/enumHeaderAnnotations}} +{{#if serializedName}} +@{{javax}}.xml.bind.annotation.XmlRootElement(name = {{{stringLiteral serializedName}}}) +{{/if}} +@{{javax}}.xml.bind.annotation.XmlType(name = "{{className name}}") +@{{javax}}.xml.bind.annotation.XmlEnum({{enumValueNativeType}}.class) +{{#if deprecated}} +@java.lang.Deprecated +{{/if}} diff --git a/packages/java-jaxrs-common/templates/frag/pojoHeader.hbs b/packages/java-jaxrs-common/templates/frag/pojoHeader.hbs index bd8c4c63..cb8a8a5e 100644 --- a/packages/java-jaxrs-common/templates/frag/pojoHeader.hbs +++ b/packages/java-jaxrs-common/templates/frag/pojoHeader.hbs @@ -1,6 +1,6 @@ {{>hooks/pojoHeaderAnnotations}} {{#if serializedName}} -@{{javax}}.xml.bind.annotation.XmlRootElement(name = "{{{serializedName}}}") +@{{javax}}.xml.bind.annotation.XmlRootElement(name = {{{stringLiteral serializedName}}}) {{/if}} {{#if discriminator}} @com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include = com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.serializedName}}}") diff --git a/packages/java-jaxrs-common/templates/hooks/enumHeaderAnnotations.hbs b/packages/java-jaxrs-common/templates/hooks/enumHeaderAnnotations.hbs new file mode 100644 index 00000000..e69de29b diff --git a/packages/java-jaxrs-server/templates/hooks/enumHeaderAnnotations.hbs b/packages/java-jaxrs-server/templates/hooks/enumHeaderAnnotations.hbs new file mode 100644 index 00000000..ff5aa7c3 --- /dev/null +++ b/packages/java-jaxrs-server/templates/hooks/enumHeaderAnnotations.hbs @@ -0,0 +1,11 @@ +@io.swagger.v3.oas.annotations.media.Schema({{#join ', '}} +{{#if serializedName}} +name = {{{stringLiteral serializedName}}} +{{/if}} +{{#if description}} +description = {{{stringLiteral description}}} +{{/if}} +{{#if deprecated}} +deprecated = true +{{/if}} +{{/join}}) diff --git a/packages/java-jaxrs-server/templates/hooks/pojoHeaderAnnotations.hbs b/packages/java-jaxrs-server/templates/hooks/pojoHeaderAnnotations.hbs index 67537a13..10fe5b1a 100644 --- a/packages/java-jaxrs-server/templates/hooks/pojoHeaderAnnotations.hbs +++ b/packages/java-jaxrs-server/templates/hooks/pojoHeaderAnnotations.hbs @@ -1 +1,14 @@ -@io.swagger.v3.oas.annotations.media.Schema(name = "{{#if serializedName}}{{{serializedName}}}{{/if}}"{{#if description}}, description = {{{stringLiteral description}}}{{/if}}{{#if discriminator}}, discriminatorProperty = "{{{discriminator.serializedName}}}"{{/if}}) +@io.swagger.v3.oas.annotations.media.Schema({{#join ', '}} +{{#if serializedName}} +name = {{{stringLiteral serializedName}}} +{{/if}} +{{#if description}} +description = {{{stringLiteral description}}} +{{/if}} +{{#if discriminator}} +discriminatorProperty = {{{stringLiteral discriminator.serializedName}}} +{{/if}} +{{#if deprecated}} +deprecated = true +{{/if}} +{{/join}})