-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support JsonTypeInfo and JsonSubTypes annotations #280
Comments
Added support for subType declaration: This doesn't include @JsonTypeInfo as-is. Looking at supporting that but this is the work-around: @ApiModel(value="my base model",
discriminator="type",
subTypes={WildAnimal.class, DomesticAnimal.class}) |
@fehguy Isnt it kind of redefining the runtime serialization relationships, just for documentation. Meaning if we're using jackson to serialize to json, the Animal class will have similar annotations @JsonTypeInfo( use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type" )
@JsonSubTypes( { @Type( value = WildAnimal.class, name = "wild" ),
@Type( value = DomesticAnimal.class, name = "domestic" ) } )
abstract class Animal {
//...
public String name;
} Now we end up with a problem to keep them in sync. Since you're still in the midst of implementing this, any way to avoid this? |
That's the next step of this. |
It seems not to be working if the property 'type' (for the example property="type") is not a bean property (only used by Jackson for transportation). |
@fehguy Has this been fixed ? Does it work if type is not a bean property?
Generated swagger.json:-
property "type" is missing in properties as well as required(since it is discriminator) which is leading to wrong code generation. Any thoughts on this ? |
Any update since @mukulb90 's comment? This thread seems only but it still doesn't seem to work, even on 2.0.8... |
Please file a new ticket for further investigation. |
When using polymorphism and only the parent class is referenced in the API operations its subclasses aren't added to the model.
Jackson discovers the inheritance model with the annotations JsonTypeInfo and JsonSubTypes.
I think it would be useful if Swagger could pick up the classes listed in JsonSubTypes and add them to the model. I also think it would be nice if Swagger could pick up the discriminator property from JsonTypeInfo and add the parameter to the model as adding the property to the subclasses makes Jackson write the property twice.
The text was updated successfully, but these errors were encountered: