swagger-core
swagger-core copied to clipboard
Swagger ignores @JsonTypeInfo if applied through a Mixin
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() {
}
Any updates on this topic. Im having the same problem...
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).
I also have the same issue. Is there any update?