-
-
Notifications
You must be signed in to change notification settings - Fork 530
Discriminator property not set for 2-level inheritance types #1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If someone could give some insights if this is working as expected our not, I willing to put effort in this to fix it. But I would like to know in front if I'm not wasting time because it works like this by design. |
@melvinnijholt correct me if I’m wrong but I don’t see The implementation followed comes from the 3.1 spec. I believe you may be missing some fields to make it work properly. But if there’s an official example of valid syntax that looks different from this, if you provide a link I’d be happy to add alternate behavior. |
@drwpow You can find the complete example in this repo: https://github.com/melvinnijholt/openapi-typescript-discriminator-issue/ Your correct that in my schema Poodle doesn't contain a _petType. But dog also doesn't. Dog is omitting it from Pet and then adds the new value of "Dog". I would expect Poodle to do the same. Omit the _petType from Dog and it with the value of "Poodle". But I'm not sure if this multi-level inherentance is supported by the specifcations. |
Please see an example: MyResponseType:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Lizard'
- $ref: 'https://gigantic-server.com/schemas/Monster/schema.json'
discriminator:
propertyName: petType
mapping:
dog: '#/components/schemas/Dog'
monster: 'https://gigantic-server.com/schemas/Monster/schema.json'
|
Wanted to provide an apology and a correction—yes your original issue is how the spec outlines discriminators to work and infers they do. They are more “magical” than I originally understood it to be! The expectation you posted seems correct to me, and is how it should work as outlined in the spec. However, currently, this library does require |
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed. |
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem. |
Description
For 1-level inheritance types the discriminator property is to a static value that identifies the type. For 2-level inheritance types this is not the case which makes it not possible to detect the type that is returned by the api endpoint.
Take for example
Pet
->Dog
->Poodle
. When a discriminator is specified forPet
this will be set onDog
but it will not be set onPoodle
.I don't know if this is excepted behavior, if it is than I will change this to a feature request.
openapi-typescript
6.2.4
16.19.0
Windows 11
Reproduction
I have a swagger.json that contains the following definition for
Pet
that defines a discriminator named_petType
.It also contains a definition for
Dog
that defines theallOf
property toPet
and a definition for
Poodle
that defines theallOf
property toDog
The generated swagger.ts contains
Dog
specifying a value_petType: "Dog"
for the discriminator. The discriminator value forPoodle
is missing.I would the generated swagger to contain a
Poodle
specifying a value_petType: "Poodle"
for the discriminator like swagger-expected.ts thatChecklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: