admin管理员组文章数量:1293704
We are using discriminator method in the interface for an openapi based spring code generator based on which we are generating the classes to be shared across.
Discriminator interface:
@Schema(
discriminatorMapping = {
@DiscriminatorMapping(value = "type1", schema = Type1.class),
@DiscriminatorMapping(value = "type2", schema = Type2.class),
@DiscriminatorMapping(value = "type3", schema = Type3.class),
},
discriminatorProperty = "type",
oneOf = {Type1.class,
Type2.class,
Type3.class
}
)
public interface MainInterface {
@Schema(
requiredMode = Schema.RequiredMode.REQUIRED,
example = "type1"
)
Type getType();
}
There properties that are shared across these Type child interfaces. So we want to add the shared getters in the MainInterface
itself.
SharedProperties.java
public interface SharedProperties {
String getName();
String getDescription();
}
We want to the Type interfaces to have SharedProperties
methods. But we are not able to add it properly. Tried add it as anyOf
to MainInterface
but discriminators are messing up and not Type
doesn't implement MainInterface
but it has all the properties from SharedProperties
. Is there a way to implement this with keeping Type interfaces consistent to extend the Discriminator properties.
The generator currently generates main interface as
@JsonIgnoreProperties(
value = {"type"},
allowSetters = true
)
@JsonTypeInfo(
use = Id.NAME,
include = As.PROPERTY,
property = "type",
visible = true
)
@JsonSubTypes({@Type(
value = Type1.class,
name = "type1"
), @Type(
value = Type2.class,
name = "type2"
), @Type(
value = Type3.class,
name = "type3"
)})
public interface MainInterface {
Type getType();
}
But we want getName()
and getDescription()
as well as part of the MainInterface
.
We also tried adding the methods directly to MainInterface
but the generator ignores them.
本文标签:
版权声明:本文标题:java - Discriminator interface not generating all methods in codegen interface for openapi spring - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741585077a2386798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论