swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Can't mix and match polymorphic annotation declarations

Open jknova opened this issue 13 years ago • 2 comments

If I have a base model declared in Java, with an ApiModel annotation, and some jackson annotations:

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="type", defaultImpl=Animal.class)
@JsonSubTypes({  
    @Type(value = Cat.class, name = "cat"),  
    @Type(value = Dog.class, name = "dog") })
@ApiModel(value="Animal description")
public class AttributeSource
{
...
}

Then the model's 'subTypes' and 'discriminator' properties are empty. I need to explicitly define them in the ApiModel annotation or remove the ApiModel annotation

jknova avatar Oct 24 '13 03:10 jknova

Thanks, this is fixed in develop and pushed to 1.3.1-SNAPSHOT

fehguy avatar Oct 25 '13 00:10 fehguy

Hello,

Feel free to correct me if I'm wrong, but I think this might still be an issue. ApiModel.discriminator has an empty string as a default value, so it will still choose ApiModel's discriminator over JsonTypeInfo.property.

And I think ApiModel.subTypes suffers from the same problem as well.

I made the following change in my repo: 9ebafcb977c5d29fb35ee865dd9a77bae2e5f0c1

Please let me know if I've missed anything. Thanks

jknova avatar Oct 25 '13 03:10 jknova