Skip to content

Is there a way for springdoc-openapi to determine Schema discriminatorProperty / discriminatorMapping purely from @JsonTypeInfo / @JsonSubTypes ? #2999

Closed
@bmr-exerp

Description

@bmr-exerp

As title. I'm working on an API in Spring Boot 2.7.17, using springdoc 1.8.0. It seems like I am forced to effectively duplicate my schema specification between @Schema and @JsonTypeInfo, which leaves a sour taste.

@Schema(
	subTypes = {
		Foo1.class,
		Foo2.class,
	},
	discriminatorProperty = "fooType",
	discriminatorMapping = {
		@DiscriminatorMapping(value = "foo1", schema = Foo1.class),
		@DiscriminatorMapping(value = "foo2", schema = Foo2.class),
	})
@JsonTypeInfo(
	use = JsonTypeInfo.Id.NAME,
	visible = true,
	include = JsonTypeInfo.As.EXISTING_PROPERTY,
	property = "fooType")
@JsonSubTypes({
	@Type(value = Foo1.class, name = "foo1"),
	@Type(value = Foo2.class, name = "foo2"),
})
public interface AbstractFoo {
	String getFooType();
}

As is evident, the information on the @Schema annotation exactly matches (and therefore must be kept in sync with) the Jackson type information on JsonTypeInfo and JsonSubTypes. Is there a way to get springdoc to build subschema 'routing' documentation without reiterating myself here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions