How to describe polymorphic endpoint
See original GitHub issueWe use Spring+Jackson(Java). And in our API we can send different object to same endpoint. For example
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = As.PROPERTY,
property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "dog"),
@JsonSubTypes.Type(value = Cat.class, name = "cat")
})
public static class Animal {
}
@JsonTypeName("dog")
public static class Dog extends Animal {
public double barkVolume;
}
@JsonTypeName("cat")
public static class Cat extends Animal {
boolean likesCream;
public int lives;
}
@Controller
public class MyController {
//REST service
@RequestMapping( value = "test")
public @ResponseBody String save(@RequestBody Animal animal){
System.out.println(animal.getClass());
return success;
}
}
Sending to /test
{
"type": "dog",
"barkVolume": 23.3
}
will show Dog.class
Sending to /test
{
"type": "cat",
"likesCream": true,
"lives": 42
}
will show Cat.class
How to describe polymorphic endpoint in Swagger?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to describe polymorphic endpoint in Swagger?
How to describe polymorphic endpoint in Swagger? java · spring · jackson · polymorphism · swagger · Share.
Read more >Inheritance and Polymorphism - Swagger
Instead of describing these properties for each schema repeatedly, you can describe the schemas as a composition of the common property set and...
Read more >Polymorphic endpoints with Jackson - Thinking in java
When you are designing an application model, one of the most useful techniques is the polymorphism. This allow to us , to write...
Read more >Polymorphic Endpoint Types for Copyless Message ... - arXiv
Polymorphic Endpoint Types for Copyless Message Passing may be used to describe (part of) the behavior of a Seller object as it can...
Read more >What is a Polymorphic Virus? Detection and Best Practices
A polymorphic virus is a type of malware that is programmed to repeatedly ... The virus is installed on an endpoint and the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks @SabhtarshaMojo , it was indeed a bug, fixed in #3293
Hit a NPE when my model had some required fields but did not have the discriminatorProperty as part of the class definition. Could fix it by changing the code here: https://github.com/swagger-api/swagger-core/blob/6c702f1e5d5842d1abdcf5ba664f54ca615cd202/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java#L1643
Changed the condition to following and it fixed it,
if (modelToUpdate.getRequired() == null || !modelToUpdate.getRequired().contains(typeInfoProp)) {