-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
discriminator mapping ignored when using allOf with oneOf #1690
Comments
This is actually a common misconception about how |
I'm not sure why this would a behavior that we want. The property that maps the reference in this example is |
Oh I’m fully in agreement with you—I also would prefer the mapping be manual. But this is how the JSONSchema (and by extension, OpenAPI 3) specification is designed to work, at least going through the examples. They explicitly call out this behavior. If you reference any object where the |
I'm not sure that this isn't a bug still. With our schema uploaded to swagger the schemas are being shown as expected, its only when using this typescript generation tool that we are seeing the bug. And it's only when using it with openapi: 3.0.0
components:
schemas:
A:
oneOf:
- $ref: '#/components/schemas/C'
- $ref: '#/components/schemas/D'
discriminator:
propertyName: pet_type
mapping:
c: '#/components/schemas/C'
d: '#/components/schemas/D'
B:
allOf:
- $ref: '#/components/schemas/A'
properties:
prop:
type: string
C:
type: object
properties:
pet_type:
type: string
enum: [c]
D:
type: object
properties:
pet_type:
type: string
enum: [d] |
@drwpow-figma openapi: 3.0.3
info:
title: Sample API
version: 1.0.0
paths: {}
components:
schemas:
B:
type: object
properties:
prop:
type: string
type:
type: string
enum: [b]
C:
type: object
properties:
otherProp:
type: string
type:
type: string
enum: [c]
TypeADiscriminator:
oneOf:
- $ref: '#/components/schemas/B'
- $ref: '#/components/schemas/C'
discriminator:
propertyName: type
mapping:
b: '#/components/schemas/B'
c: '#/components/schemas/C'
TypeA:
$ref: '#/components/schemas/TypeADiscriminator'
ExtendedTypeA:
allOf:
- $ref: '#/components/schemas/TypeA'
- type: object
properties:
name:
type: string |
Description
Here's a very basic example
As you can see we should be able to use this syntax to easily cut down the fluff and add more properties to
B
while maintaining the discriminators mapping. Instead thepet_type
is omitted and a newpet_type
is created overwriting C and D casing A to be completely invalid.openapi-typescript
openapi-typescript@next
18.16.0
macOS 13
Reproduction
How can this be reproduced / when did the error occur?
npx openapi-typescript@next test.yaml -o ./testnext.d.ts
Expected result
something like
(in case it’s not obvious)
Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: