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.

本文标签: