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

Swagger ignores @JsonTypeInfo if applied through a Mixin

Open rozzamozza opened this issue 6 years ago • 3 comments

Swagger correctly identifies subtypes annotated with @JsonSubTypes on Mixins but it seems to ignore a @JsonTypeInfo specified on a Mixin.

@Test
 fun `should generate polymorphic swagger based on json annotations`() {

   Json.mapper.addMixIn(Pet::class.java, PetMixin::class.java)

   val schemas = ModelConverters()
       .apply {
         addConverter(ModelResolver(Json.mapper))
       }
       .readAll(Pet::class.java)
   assertThat(schemas, hasKey("Dog"))

   Json.prettyMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
   println(Json.encodePrettily(schemas))
 }

 @JsonSubTypes(
     Type(value = Dog::class, name = "Dog"),
     Type(value = Cat::class, name = "Cat")
 )
 @JsonTypeInfo(use = CLASS, include = PROPERTY, property = "@class")
 abstract class PetMixin


// @JsonTypeInfo(use = CLASS, include = PROPERTY, property = "@class")
 abstract class Pet {
 }

 data class Dog(val noisy: Boolean = false, val legs: Int = 4) : Pet() {
 }

 data class Cat(val friendly: Boolean = true, val legs: Int = 4) : Pet() {
 }

rozzamozza avatar Sep 30 '19 15:09 rozzamozza

Any updates on this topic. Im having the same problem...

daanbefort avatar Sep 07 '22 14:09 daanbefort

We also have this problem, here another executable example: https://github.com/erikpetzold/swagger-duplicate-schema-generation/blob/main/src/main/java/de/epet/demo/issue3/typeinfoinmixin/SwaggerDemo.java (project contains examples for more issues).

erikpetzold avatar Mar 13 '23 20:03 erikpetzold

I also have the same issue. Is there any update?

mdanish98 avatar Aug 25 '23 14:08 mdanish98