Skip to content

Commit 3ef45f1

Browse files
Discard mapped dmodels with matching explicit discriminator mappings (#20939)
1 parent 7e439fd commit 3ef45f1

File tree

4 files changed

+3
-60
lines changed

4 files changed

+3
-60
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,8 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
36823682
if (ModelUtils.isComposedSchema(schema) && !this.getLegacyDiscriminatorBehavior()) {
36833683
List<MappedModel> otherDescendants = getOneOfAnyOfDescendants(schemaName, discriminatorPropertyName, schema);
36843684
for (MappedModel otherDescendant : otherDescendants) {
3685-
if (!uniqueDescendants.contains(otherDescendant)) {
3685+
// add only if the model names are not the same
3686+
if (uniqueDescendants.stream().map(MappedModel::getModelName).noneMatch(it -> it.equals(otherDescendant.getModelName()))) {
36863687
uniqueDescendants.add(otherDescendant);
36873688
}
36883689
}

samples/client/others/go/oneof-discriminator-lookup/model_object.go

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/go/go-petstore/model_filter_any.go

Lines changed: 0 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Fruit.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "fruitType", visible = true)
3131
@JsonSubTypes({
3232
@JsonSubTypes.Type(value = Apple.class, name = "APPLE"),
33-
@JsonSubTypes.Type(value = Banana.class, name = "BANANA"),
34-
@JsonSubTypes.Type(value = Apple.class, name = "Apple"),
35-
@JsonSubTypes.Type(value = Banana.class, name = "Banana")
33+
@JsonSubTypes.Type(value = Banana.class, name = "BANANA")
3634
})
3735

3836
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT")

0 commit comments

Comments
 (0)