Skip to content
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

Enum based discriminator generates incorrect OpenAPI code #4707

Open
PetrPytelka opened this issue Oct 11, 2024 · 2 comments
Open

Enum based discriminator generates incorrect OpenAPI code #4707

PetrPytelka opened this issue Oct 11, 2024 · 2 comments
Assignees
Labels
emitter:openapi3 Issues for @typespec/openapi3 emitter

Comments

@PetrPytelka
Copy link

It seems to me that OpenAPI code generated for enum based discriminator is incorrect. Here is link to an example from the TypeSpec documentation and the generated code:

Playground Link

The problem is that property 'kind' is generated directly inside the Dog and Cat objects and also inhereted from Pet schema due to the declaration: "allOf: - $ref: '#/components/schemas/Pet'".

There is very similar example in the OpenAPI specification in the paragraph: https://spec.openapis.org/oas/latest.html#fixed-fields-20, see part "For example:". That example does not repeat discriminator in each object. The current solution causes a problem when generating code from OpenAPI. The enum is generated twice - first time from the abstract class with all items, and then as inner class for each enum nested insided the Dog and Cat types.

My conlucision: Extended models (Cat, Dog) should not contained repeated declarations of discriminator because it is automatically included due to the allOf operator while including the base model (Pet).

@wanlwanl
Copy link
Member

@timotheeguerin
Copy link
Member

I am not sure this is incorrect openapi code. I think we are describing things correctly. The kind property is not exactly the same as what the parent is. OpenAPI3 doesn't require you to redefine it because it has the discriminator implicitly defining the value and use allOf to inherit the property but I think the way we have it is also valid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:openapi3 Issues for @typespec/openapi3 emitter
Projects
None yet
Development

No branches or pull requests

4 participants