question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to describe polymorphic endpoint

See original GitHub issue

We 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:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
frantumacommented, Sep 18, 2019

thanks @SabhtarshaMojo , it was indeed a bug, fixed in #3293

0reactions
SabhtarshaMojocommented, Sep 18, 2019

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)) {

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found