You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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).
The text was updated successfully, but these errors were encountered:
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
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).
The text was updated successfully, but these errors were encountered: