-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
_links property schema using Spring Data REST is array instead of object #2359
Comments
@bnasslahsen I got the same issue without using Spring Data REST but After investigating, it seems that the Here are my autoconfiguration debugging logs :
Therefore, I suggest to change the @Bean(Constants.LINKS_SCHEMA_CUSTOMISER)
@ConditionalOnMissingBean(name = Constants.LINKS_SCHEMA_CUSTOMISER)
@Lazy(false)
GlobalOpenApiCustomizer linksSchemaCustomizer(HateoasHalProvider halProvider, SpringDocConfigProperties springDocConfigProperties,
ObjectMapperProvider objectMapperProvider) {
...
} Or to change the return type, @Bean(Constants.LINKS_SCHEMA_CUSTOMISER)
@ConditionalOnMissingBean
@Lazy(false)
OpenApiHateoasLinksCustomizer linksSchemaCustomizer(HateoasHalProvider halProvider, SpringDocConfigProperties springDocConfigProperties,
ObjectMapperProvider objectMapperProvider) {
...
} But it will harder for end users to override it. Thank you in advance for your help. |
@mathieu-amblard |
@uc4w6c Sure I will create one. |
Is there an estimate of when this will get released? In the meantime I've copied that linksSchemaCustomizer bean definition into a |
Should be released, by the end of this week-end. |
Describe the bug
When working with Spring Data REST, the generated schema is an array of links, instead of a map of links (object with additionalProperties of type Link).
This bug is similar to #1090, but as it happens on the latest version (2.2.0), I'm opening a new one.
Here is a quick analysis of the problem:
org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer
so it generates an array schema of #/components/schemas/Link instead
Workaround
I could customize the generated spec to fix the _links properties with this:
To Reproduce
Generate an OpenAPI spec including entities manages through Spring DATA REST repositories, using latest versions of Spring Boot (3.1.3), Spring Data (2023.0.2), SpringDoc (2.2.0).
The generated schema for "links" properties (in collection or entity models) is like this:
The Link schema in itself is OK:
Expected behavior
The generated schema for _links properties should be:
and the Links schema should exist:
The text was updated successfully, but these errors were encountered: