From e4973dbad3352ec0fe021c96163746689b106840 Mon Sep 17 00:00:00 2001 From: Ignacio Vidal Date: Thu, 25 Jun 2026 23:59:30 +0100 Subject: [PATCH 1/2] [jaxrs-spec] add @JsonIgnoreProperties on discriminator to avoid duplicate key Models with a discriminator emitted @JsonTypeInfo(As.PROPERTY) but also declared the discriminator property as a regular @JsonProperty field, so Jackson serialized the discriminator twice, producing a duplicate key in the response body. Mirror the Spring generator by emitting @JsonIgnoreProperties(value = "", allowSetters = true) on the discriminator-carrying model. allowSetters = true preserves the field during deserialization. The JsonIgnoreProperties import was already added unconditionally by AbstractJavaCodegen, so no Java change is required. Regenerated the affected jaxrs-spec samples. --- .../spec/typeInfoAnnotation.mustache | 4 ++ .../jaxrs/JavaJAXRSSpecServerCodegenTest.java | 43 +++++++++++++++++++ .../java/org/openapitools/model/Animal.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ .../java/org/openapitools/model/Animal.java | 4 ++ .../model/ParentWithNullable.java | 4 ++ 15 files changed, 99 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/typeInfoAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/typeInfoAnnotation.mustache index 5b7bb5cd3294..a0f29337089f 100644 --- a/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/typeInfoAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/JavaJaxRS/spec/typeInfoAnnotation.mustache @@ -1,4 +1,8 @@ {{#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) @JsonSubTypes({ {{#discriminator.mappedModels}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java index 4a3d6b20bc22..c294d8c79065 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java @@ -1289,6 +1289,49 @@ public void testDiscriminatorMappingUsedInJsonTypeName() throws Exception { .fileDoesNotContain("@JsonTypeName(\"DogRequest\")"); } + /** + * A model with a discriminator must emit {@code @JsonIgnoreProperties} on the discriminator + * property so Jackson does not serialize that property twice (once for the manually declared + * field and once for the {@code @JsonTypeInfo} type id), which produces a duplicate key in the + * response body. {@code allowSetters = true} preserves the field during deserialization. + */ + @Test + public void testDiscriminatorEmitsJsonIgnorePropertiesToAvoidDuplicateKey() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/jaxrs/petstore.yaml", null, new ParseOptions()).getOpenAPI(); + + codegen.setOutputDir(output.getAbsolutePath()); + + ClientOptInput input = new ClientOptInput() + .openAPI(openAPI) + .config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + Map files = generator.opts(input).generate().stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + // The parent model (which carries the discriminator) must ignore the manually declared + // discriminator property during serialization while still allowing it to be set during + // deserialization. The discriminator property in this spec is "petType". + JavaFileAssert.assertThat(files.get("PetRequest.java")) + .hasImports("com.fasterxml.jackson.annotation.JsonIgnoreProperties") + .fileContains( + "@JsonIgnoreProperties(", + "value = \"petType\"", + "allowSetters = true") + // @JsonIgnoreProperties must precede @JsonTypeInfo on the class declaration. + .fileContainsPattern("@JsonIgnoreProperties\\([\\s\\S]*?@JsonTypeInfo"); + + // Child models do not carry the discriminator, so they must not receive the annotation. + JavaFileAssert.assertThat(files.get("CatRequest.java")) + .fileDoesNotContain("@JsonIgnoreProperties"); + JavaFileAssert.assertThat(files.get("DogRequest.java")) + .fileDoesNotContain("@JsonIgnoreProperties"); + } + @Test public void testGenerateJsonNullableListFieldsHelperMethodReferences_issue23251() throws Exception { Map properties = new HashMap<>(); diff --git a/samples/server/petstore/jaxrs-spec-jakarta/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-jakarta/src/gen/java/org/openapitools/model/Animal.java index 56e987f44a5c..ed5a9361e5b7 100644 --- a/samples/server/petstore/jaxrs-spec-jakarta/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-jakarta/src/gen/java/org/openapitools/model/Animal.java @@ -17,6 +17,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = BigCat.class, name = "BigCat"), diff --git a/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/Animal.java index fed48bd0ca08..c228fe34e800 100644 --- a/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/Animal.java @@ -14,6 +14,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/ParentWithNullable.java index f0aa9e76c0a9..51ce7b322827 100644 --- a/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec-quarkus-mutiny/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -15,6 +15,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/Animal.java index 79a4d0c1abf4..5c27a3bd9ff1 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/Animal.java @@ -17,6 +17,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java index 8a09b97c58fa..ea7638f486cd 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec-swagger-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -18,6 +18,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/Animal.java index c27b53b746b9..fb0aed9ebeec 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/Animal.java @@ -15,6 +15,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/ParentWithNullable.java index d3f53a5ab92f..dd221a6761e3 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations-jakarta/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -16,6 +16,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/Animal.java index cdc8dd701534..fa53e7e0c72a 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/Animal.java @@ -15,6 +15,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java index 80c5db68d0e9..3ea6bf6d4071 100644 --- a/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec-swagger-v3-annotations/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -16,6 +16,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), diff --git a/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/Animal.java index 66794828b75f..7feae1cc3838 100644 --- a/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/Animal.java @@ -24,6 +24,10 @@ import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/ParentWithNullable.java index 98d0f9a8b9ff..3a51fdf6e633 100644 --- a/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec-withxml/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -25,6 +25,10 @@ import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/Animal.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/Animal.java index 79a4d0c1abf4..5c27a3bd9ff1 100644 --- a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/Animal.java +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/Animal.java @@ -17,6 +17,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "className", // ignore manually set className, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the className to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "className", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = Cat.class, name = "CAT"), diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/ParentWithNullable.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/ParentWithNullable.java index 8a09b97c58fa..ea7638f486cd 100644 --- a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/ParentWithNullable.java +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/ParentWithNullable.java @@ -18,6 +18,10 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import org.openapitools.jackson.nullable.JsonNullable; +@JsonIgnoreProperties( + value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the type to be set during deserialization +) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable"), From 3a48158086987f3588cea43e9d9896602438f724 Mon Sep 17 00:00:00 2001 From: Ignacio Vidal Date: Fri, 26 Jun 2026 00:01:28 +0100 Subject: [PATCH 2/2] [jaxrs-spec] test @JsonIgnoreProperties on discriminator children with legacyDiscriminatorBehavior=false Add a dedicated fixture (discriminator-mapping-children.yaml) and test asserting that when legacyDiscriminatorBehavior=false the discriminator is propagated onto the allOf children reachable via the discriminator mapping, so @JsonIgnoreProperties is emitted on the parent and every child, ensuring the discriminator property is not serialized twice in either case. --- .../jaxrs/JavaJAXRSSpecServerCodegenTest.java | 39 ++++++++++++++ .../discriminator-mapping-children.yaml | 53 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/discriminator-mapping-children.yaml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java index c294d8c79065..f56f80985667 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/jaxrs/JavaJAXRSSpecServerCodegenTest.java @@ -1332,6 +1332,45 @@ public void testDiscriminatorEmitsJsonIgnorePropertiesToAvoidDuplicateKey() thro .fileDoesNotContain("@JsonIgnoreProperties"); } + /** + * With {@code legacyDiscriminatorBehavior=false} the discriminator is propagated from the + * parent onto every child reachable through the discriminator mapping, so each child also + * emits {@code @JsonTypeInfo}. The {@code @JsonIgnoreProperties} fix must therefore apply to + * the children too, otherwise they would serialize the discriminator property twice. + */ + @Test + public void testDiscriminatorJsonIgnorePropertiesPropagatesToChildren_whenLegacyBehaviorDisabled() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + Map properties = new HashMap<>(); + properties.put("legacyDiscriminatorBehavior", "false"); + + final CodegenConfigurator configurator = new CodegenConfigurator() + .setGeneratorName("jaxrs-spec") + .setAdditionalProperties(properties) + .setInputSpec("src/test/resources/3_0/jaxrs-spec/discriminator-mapping-children.yaml") + .setOutputDir(output.getAbsolutePath().replace("\\", "/")); + + DefaultGenerator generator = new DefaultGenerator(); + Map files = generator.opts(configurator.toClientOptInput()).generate().stream() + .collect(Collectors.toMap(File::getName, Function.identity())); + + // The parent and every mapped child must ignore the manually declared discriminator + // property during serialization (it is written once by @JsonTypeInfo) while still + // allowing it to be set during deserialization. The discriminator property is "petType". + for (String modelFile : new String[]{"PetResponse.java", "CatResponse.java", "DogResponse.java"}) { + JavaFileAssert.assertThat(files.get(modelFile)) + .hasImports("com.fasterxml.jackson.annotation.JsonIgnoreProperties") + .fileContains( + "@JsonIgnoreProperties(", + "value = \"petType\"", + "allowSetters = true") + // @JsonIgnoreProperties must precede @JsonTypeInfo on the class declaration. + .fileContainsPattern("@JsonIgnoreProperties\\([\\s\\S]*?@JsonTypeInfo"); + } + } + @Test public void testGenerateJsonNullableListFieldsHelperMethodReferences_issue23251() throws Exception { Map properties = new HashMap<>(); diff --git a/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/discriminator-mapping-children.yaml b/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/discriminator-mapping-children.yaml new file mode 100644 index 000000000000..998b6933bb13 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/jaxrs-spec/discriminator-mapping-children.yaml @@ -0,0 +1,53 @@ +openapi: 3.0.3 +info: + title: Discriminator mapping with allOf children + description: > + Minimal spec reproducing a discriminated polymorphic response where the + discriminator declares an explicit mapping to child schemas. With + legacyDiscriminatorBehavior=false the discriminator is propagated onto the + mapped children, so the @JsonIgnoreProperties / @JsonTypeInfo annotations + must be emitted on both the parent and the children. + version: 1.0.0 +paths: + /pets: + get: + operationId: getPet + responses: + '200': + description: A pet + content: + application/json: + schema: + $ref: '#/components/schemas/PetResponse' +components: + schemas: + PetResponse: + type: object + required: + - petType + properties: + petType: + type: string + name: + type: string + discriminator: + propertyName: petType + mapping: + CAT: '#/components/schemas/CatResponse' + DOG: '#/components/schemas/DogResponse' + CatResponse: + description: Response payload for a cat resource + allOf: + - $ref: '#/components/schemas/PetResponse' + - type: object + properties: + declawed: + type: boolean + DogResponse: + description: Response payload for a dog resource + allOf: + - $ref: '#/components/schemas/PetResponse' + - type: object + properties: + bark: + type: boolean