@Schema oneOf, anyOf, etc. and better support for inheritance
Can we use polymorphism features like oneOf, anyOf etc with Springfox?
@ApiResponse( content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(oneOf = { Bird.class, Cat.class })) )
@PostMapping( path = "animals", produces = "application/json" )
ResponseEntity<IAnimal> echoAnimal( @RequestBody IAnimal animal );
I used io.swagger.v3.oas.annotations.responses.ApiResponse. But did not work. Can anyone please help me to do it?
Note: I am using springfox-boot-starter:3.0.0-SNAPSHOT.
Not yet. This will be available in the next release
@dilipkrish thanks for the quick reply. Will 3.0.0 be released on tomorrow?
Yes will be pushing it today! 🎉
@dilipkrish Thanks for the new release. I updated to the new release, but still, I could not succeed what I was trying to do (maybe my is approach wrong).
I needed to show Cat and Bird as possible inputs for IAnimal and I used oneOf,
@PostMapping( path = "animals", produces = "application/json" )
ResponseEntity<IAnimal> echoAnimal( @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema( oneOf = { Bird.class, Cat.class } ), examples = {
@ExampleObject( name = "Cat",
value = "{\n" +
" \"name\": \"Kitty\",\n" +
" \"id\": 034,\n" +
" \"runningSpeed\": 34.0\n" +
"}" )
} ) ) @RequestBody IAnimal animal );
But the result is,

In my pom.xml,
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Expected result:

Hi @dilipkrish, What is the status of this polymorphic feature?
This worked for me. I just annotated base class with //java @Schema( oneOf = { Bird.class, Cat.class } ) //kotlin @Schema( oneOf = [Bird.class,Cat.class ])
I think we should close this to avoid confusion that this feature is not available yet.