Bug Report Checklist
Description
The behavior introduced in #15125 is dependent on the order of the component schemas.
If the child models comes before the parent the isOverridden is not set to true properly, and thus the child will not define a fluent setter that overrides the inherited property.
This can be seen by changing the allOf_composition_discriminator.json so that MyPets
MyPets:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
comes before the definition of the parent and the children
Pet:
type: object
required:
- petType
properties:
petType:
type: string
discriminator:
propertyName: petType
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
name:
type: string
characteristics:
$ref: '#/components/schemas/Characteristics'
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: string
I would expect Cat to be
public class Cat extends Pet {
public static final String JSON_PROPERTY_NAME = "name";
@jakarta.annotation.Nullable
private String name;
public static final String JSON_PROPERTY_CHARACTERISTICS = "characteristics";
@jakarta.annotation.Nullable
private Characteristics characteristics;
public Cat() {
}
// Other fluent setters...
@Override
public Cat petType(@jakarta.annotation.Nonnull String petType) {
this.setPetType(petType);
return this;
}
}
and have the petType as the test also asserts. But if the order is changed the fluent builder method is lost entirely from Cat.
openapi-generator version
7.25
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: OAI Specification example for Polymorphism
version: 1.0.0
paths:
/pet:
get:
responses:
'200':
description: desc
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
MyPets:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
# per https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#discriminator-object
# this discriminator must be included to use it as a hint to pick a schema
Pet:
type: object
required:
- petType
properties:
petType:
type: string
discriminator:
propertyName: petType
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
name:
type: string
characteristics:
$ref: '#/components/schemas/Characteristics'
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: string
Characteristics:
type: object
properties:
canHunt:
type: boolean
Generation Details
See test cases introduced for the PR shared above.
Steps to reproduce
See test cases introduced for the PR shared above.
Related issues/PRs
See test cases introduced for the PR shared above.
Suggest a fix
I will investigate how to handle isOverridden to get this to work as expected
Bug Report Checklist
Description
The behavior introduced in #15125 is dependent on the order of the component schemas.
If the child models comes before the parent the
isOverriddenis not set totrueproperly, and thus the child will not define a fluent setter that overrides the inherited property.This can be seen by changing the
allOf_composition_discriminator.jsonso thatMyPetscomes before the definition of the parent and the children
I would expect
Catto beand have the
petTypeas the test also asserts. But if the order is changed the fluent builder method is lost entirely fromCat.openapi-generator version
7.25
OpenAPI declaration file content or url
Generation Details
See test cases introduced for the PR shared above.
Steps to reproduce
See test cases introduced for the PR shared above.
Related issues/PRs
See test cases introduced for the PR shared above.
Suggest a fix
I will investigate how to handle
isOverriddento get this to work as expected