Skip to content

Good documentation on applying swagger inheritance in JAX-RS endpoints. #851

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

Closed
erdebee opened this issue Feb 3, 2015 · 3 comments
Closed
Assignees

Comments

@erdebee
Copy link

erdebee commented Feb 3, 2015

Initially I expected swagger to pass class binding information to the Jackson deserializer, since swagger allows for annotating all required inheritance information to be supplied. It took me quite a while to figure out that I needed to add @JsonTypeInfo annotations...

It would have saved me days of my time if there would at least have been an example for polymorphism in the PetStore examples, or anything of sorts. Judging from the amount of unanswered questions on stackoverflow, and lack of examples/implementations I could find online, im not the only one.

Is it an idea to add some basic inheritance to the petstore example?

Suggestion for the petstore pet model:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME, // Were binding by providing a name
    include = JsonTypeInfo.As.PROPERTY, // The name is provided in a property
    property = "type", // Property name is type
    visible = true // Retain the value of type after deserialisation
)
@JsonSubTypes({//Below, we define the names and the binding classes.
    @JsonSubTypes.Type(value = CatPet.class, name = "Cat"),
    @JsonSubTypes.Type(value = DogPet.class, name = "Dog")
})
@ApiModel(value = "Pet", subTypes = {DogPet.class, CatPet.class}, discriminator = "type")
public abstract class Pet {
@erdebee
Copy link
Author

erdebee commented Feb 3, 2015

Also, does swagger generate these annotations when one does codegen of yaml -> JAX-RS?

@fehguy fehguy added this to the v1.5-M2 milestone Feb 5, 2015
@webron webron added P1 and removed Documentation labels Mar 10, 2015
@webron webron modified the milestones: v1.5, v1.5-M2 Apr 29, 2015
@webron webron modified the milestones: v1.5, v1.5.1 Jun 8, 2015
@webron webron removed the P1 label Jul 13, 2015
@webron webron modified the milestones: v1.5.1, v1.5.3 Aug 6, 2015
@webron webron modified the milestones: v1.5.3, v1.5.4 Aug 18, 2015
@fehguy fehguy modified the milestones: v1.5.5, v1.5.4 Oct 19, 2015
@fehguy fehguy modified the milestones: v1.5.5, v1.5.6 Dec 23, 2015
@fehguy fehguy modified the milestones: v1.5.6, v1.5.7 Jan 6, 2016
@fehguy fehguy modified the milestones: v1.5.7, v1.5.6 Jan 6, 2016
@fehguy fehguy modified the milestones: v1.5.7, v1.5.8 Feb 5, 2016
frantuma added a commit to swagger-api/swagger-samples that referenced this issue Mar 11, 2016
@webron webron modified the milestones: v1.5.8, v1.5.9 Mar 18, 2016
@fehguy fehguy modified the milestone: v1.5.9 Sep 8, 2016
@fehguy
Copy link
Contributor

fehguy commented Dec 19, 2016

This was added by swagger-api/swagger-samples#53

@fehguy fehguy closed this as completed Dec 19, 2016
@erdebee
Copy link
Author

erdebee commented Dec 19, 2016

Thanks a lot for adding this, and for all your hard work on this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants