diff --git a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache index 3b1d6ec136..ebaea14fb3 100644 --- a/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache +++ b/openapi-generator/src/main/resources/templates/java-micronaut/common/model/enum.mustache @@ -25,7 +25,7 @@ {{#additionalEnumTypeAnnotations}} {{{.}}} {{/additionalEnumTypeAnnotations}} -{{#formatSingleLine}}public enum {{>common/model/enumName}}{{/formatSingleLine}} { +{{#formatSingleLine}}public enum {{>common/model/enumName}}{{#vendorExtensions.x-implements}}{{#-first}} implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}}{{/formatSingleLine}} { {{#allowableValues}} {{#enumVars}} diff --git a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache index 054432b630..06e97dad32 100644 --- a/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache +++ b/openapi-generator/src/main/resources/templates/kotlin-micronaut/common/model/enum.mustache @@ -25,7 +25,7 @@ {{/additionalEnumTypeAnnotations}} {{#nonPublicApi}}internal {{/nonPublicApi}}{{#formatSingleLine}}enum class {{>common/model/enumName}}{{/formatSingleLine}}( @get:JsonValue val value: {{{dataType}}}, -) { +){{#vendorExtensions.x-implements}}{{#-first}} : {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { {{#allowableValues}} {{#enumVars}} diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java index f6d5c282bc..050bdaab36 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/JavaMicronautClientCodegenTest.java @@ -1611,6 +1611,16 @@ public void sealedScenarios(String apiFile, Map definitions) { assertFileContains(path + file, check)); } + @Test + void testEnumXimplements() { + + var codegen = new JavaMicronautClientCodegen(); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/enum-implements.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/java/org/openapitools/"; + + assertFileContains(path + "model/Type.java", "public enum Type implements java.io.Serializable {"); + } + @Test void testPascalCaseInMethodName() { @@ -1630,7 +1640,8 @@ public EmployeeWithMapOfEnum putProjectRoleItem(String key, EmployeeWithMapOfEnu """ ); } - + + @Test void testDateTimeFormat() { var codegen = new JavaMicronautClientCodegen(); codegen.additionalProperties().put("dateTimeFormat", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"); diff --git a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java index 333568837d..2b7da9f33f 100644 --- a/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java +++ b/openapi-generator/src/test/java/io/micronaut/openapi/generator/KotlinMicronautClientCodegenTest.java @@ -1559,34 +1559,34 @@ static Stream sealedScenarios() { arguments("oneOf_polymorphismAndInheritance.yml", Map.of( "Bar.kt", """ class Bar( - + @Nullable @JsonProperty(JSON_PROPERTY_ID) id: String? = null, - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_BAR_PROP_A) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var barPropA: String? = null, - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_FOO_PROP_B) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var fooPropB: String? = null, - + @field:Nullable @field:Valid @field:JsonProperty(JSON_PROPERTY_FOO) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var foo: FooRefOrValue? = null, - + /** * When sub-classing, this defines the sub-class Extensible name */ @Nullable @JsonProperty(JSON_PROPERTY_AT_TYPE) atType: String? = null, - + /** * Hyperlink reference */ @@ -1594,7 +1594,7 @@ class Bar( @JsonProperty(JSON_PROPERTY_HREF) @JsonInclude(JsonInclude.Include.USE_DEFAULTS) href: String? = null, - + /** * A URI to a JSON-Schema file that defines additional attributes and relationships */ @@ -1602,7 +1602,7 @@ class Bar( @JsonProperty(JSON_PROPERTY_AT_SCHEMA_LOCATION) @JsonInclude(JsonInclude.Include.USE_DEFAULTS) atSchemaLocation: String? = null, - + /** * When sub-classing, this defines the super-class */ @@ -1614,11 +1614,11 @@ class Bar( """, "Banana.kt", """ data class Banana( - + @field:NotNull @field:JsonProperty(JSON_PROPERTY_LENGTH) var length: Int, - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_FRUIT_TYPE) override var fruitType: FruitType? = null, @@ -1626,14 +1626,14 @@ data class Banana( """, "Entity.kt", """ open class Entity( - + /** * When sub-classing, this defines the sub-class Extensible name */ @field:NotNull @field:JsonProperty(JSON_PROPERTY_AT_TYPE) open var atType: String? = null, - + /** * Hyperlink reference */ @@ -1641,7 +1641,7 @@ open class Entity( @field:JsonProperty(JSON_PROPERTY_HREF) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) open var href: String? = null, - + /** * unique identifier */ @@ -1649,7 +1649,7 @@ open class Entity( @field:JsonProperty(JSON_PROPERTY_ID) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) open var id: String? = null, - + /** * A URI to a JSON-Schema file that defines additional attributes and relationships */ @@ -1657,7 +1657,7 @@ open class Entity( @field:JsonProperty(JSON_PROPERTY_AT_SCHEMA_LOCATION) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) open var atSchemaLocation: String? = null, - + /** * When sub-classing, this defines the super-class */ @@ -1670,7 +1670,7 @@ open class Entity( arguments("oneOf_additionalProperties.yml", Map.of( "SchemaA.kt", """ data class SchemaA( - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_PROP_A) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) @@ -1687,7 +1687,7 @@ data class SchemaA( arguments("oneOf_primitive.yml", Map.of( "Child.kt", """ data class Child( - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_NAME) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) @@ -1701,12 +1701,12 @@ data class Child( "Fruit.kt", "interface Fruit {", "Banana.kt", """ data class Banana( - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_LENGTH_CM) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var lengthCm: BigDecimal? = null, - + @Nullable @JsonProperty(JSON_PROPERTY_FRUIT_TYPE) override var fruitType: String? = null, @@ -1714,19 +1714,19 @@ data class Banana( """, "Apple.kt", """ data class Apple( - + @field:Nullable @field:Pattern(regexp = "^[a-zA-Z\\\\s]*$") @field:JsonProperty(JSON_PROPERTY_CULTIVAR) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var cultivar: String? = null, - + @field:Nullable @field:Pattern(regexp = "/^[A-Z\\\\s]*$/i") @field:JsonProperty(JSON_PROPERTY_ORIGIN) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) var origin: String? = null, - + @Nullable @JsonProperty(JSON_PROPERTY_FRUIT_TYPE) override var fruitType: String? = null, @@ -1738,7 +1738,7 @@ data class Apple( "Fruit.kt", "interface Fruit", "Grape.kt", """ data class Grape( - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_COLOR) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) @@ -1747,7 +1747,7 @@ data class Grape( """, "Apple.kt", """ data class Apple( - + @field:Nullable @field:JsonProperty(JSON_PROPERTY_KIND) @field:JsonInclude(JsonInclude.Include.USE_DEFAULTS) @@ -1795,4 +1795,20 @@ suspend fun browseSearchOrders( """ ); } + + @Test + void testEnumXimplements() { + + var codegen = new KotlinMicronautClientCodegen(); + String outputPath = generateFiles(codegen, "src/test/resources/3_0/enum-implements.yml", CodegenConstants.APIS, CodegenConstants.MODELS); + String path = outputPath + "src/main/kotlin/org/openapitools/"; + + assertFileContains(path + "model/Type.kt", + """ + enum class Type( + @get:JsonValue val value: String, + ) : java.io.Serializable { + """ + ); + } } diff --git a/openapi-generator/src/test/resources/3_0/enum-implements.yml b/openapi-generator/src/test/resources/3_0/enum-implements.yml new file mode 100644 index 0000000000..98f6de72ec --- /dev/null +++ b/openapi-generator/src/test/resources/3_0/enum-implements.yml @@ -0,0 +1,33 @@ +openapi: 3.0.0 +info: + title: Sample API + description: API description in Markdown. + version: 1.0.0 +paths: + /ponies: + get: + summary: Returns all animals. + description: Optional extended description in Markdown. + responses: + 200: + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pony' +components: + schemas: + Pony: + type: object + properties: + type: + $ref: '#/components/schemas/Type' + Type: + type: string + x-implements: java.io.Serializable + enum: + - Earth + - Pegasi + - Unicorn \ No newline at end of file