Open AffeJonsson opened 6 months ago
Putting the discriminator on the base class also works. But having the discriminator on the response is valid according to the spec: https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/
PR is welcome?
I realize there is two ways this could be solved, but I'm not sure which is the way to go. Either we add the discriminated property to the types, or we add it to the combined response type. That is, either:
export type TypeObj1 = Base & {
moreProp?: string;
type: TypeObj1Type;
};
export type TypeObj2 = Base & {
prop?: string;
type: TypeObj2Type;
};
or
export type GetApiSample200 = (TypeObj1 & { type: TypeObj1Type }) | (TypeObj2 & { type: TypeObj2Type });
I assume the first one is the wanted one, but I'm unsure if there could be implications with changing the component schema based on the response schema. Could there be two responses which return the same objects, but discriminate on different properties? If so, option 2 is the safe option.
What are the steps to reproduce this issue?
Using the following schema:
the discriminator is not handled properly.
What happens?
The generated types are
What were you expecting to happen?
The generated types should be
Any other comments?
Moving the response into the components schema definition and referencing it from the response solves the issue:
What versions are you using?
Package Version: 6.27.1