-
-
Notifications
You must be signed in to change notification settings - Fork 527
Is there a way for springdoc-openapi to determine Schema discriminatorProperty / discriminatorMapping purely from @JsonTypeInfo / @JsonSubTypes ? #2999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
More recent versions of springdoc-api introspects the JsonTypeInfo annotation and will construct an allOf-polymorphic schema based upon that information (the drawback is instead that an invalid schema will be generator if there is both a Json-annotation and a Schema annotation that contains a oneOf definition. See discussion under this issue as an example #2915. |
Hi @Mattias-Sehlstedt , thanks for getting back to me. I tried it with a greenfields Spring Boot app, running Java 24, spring-boot-starter-web 3.4.5, and org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8. While it's correctly showing the discriminator property name, it doesn't add the
This means I have the 'base' request type, As an aside, I don't know if this is how the spec actually works, but given an explicit discriminator mapping via
Right now, I do this 'manually'. Example:
to force the schema to say "If you want to send the API a request of type Foo1, the value of fooType must be 'foo1'". But doing this on all my polymorphic types is a bit of a slog. Assuming all of the discriminator value / discriminator mapping stuff works as intended, is this the sort of behaviour I should expect? Would it help if I pushed my findings to a repository for someone such as yourself to sanity check? |
I have so far always relied on my consumers being understanding of the implicit expectation on a discriminator property:
taken from the section So I would say it becomes a question of whether your consumers could understand this contract if you were simply to add a general "discriminator properties" section in the service description that covers this behavior. Or is it necessary that the schema object itself exactly states this? It is of course a different scenario if you cannot ensure that the schema name is the same as the object name, since they you would need an explicit discriminator mapping, but I generally try to always avoid placing myself in that situation. |
Uh oh!
There was an error while loading. Please reload this page.
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.As is evident, the information on the
@Schema
annotation exactly matches (and therefore must be kept in sync with) the Jackson type information onJsonTypeInfo
andJsonSubTypes
. Is there a way to get springdoc to build subschema 'routing' documentation without reiterating myself here?The text was updated successfully, but these errors were encountered: