spring-hateoasspringdoc

Render HAL formatted links in openapi3 json with SpringDoc


I'm running a Spring Boot REST application with Spring HATEOAS support and generating OpenAPIv3 docs with the Springdoc Maven plugin. However when I call my REST endpoints I get links the in HAL formatted JSON ("_links"). But the generated OpenAPIv3 documentation is giving me a different format for the links ("links").

How can I get the generated OpenAPIv3 docs to match the HAL formatted links?

The only resource I've found is this link: https://github.com/springdoc/springdoc-openapi/issues/446 However, the solution given there involves using spring-data-rest which I am not using (do I need to?)

I've also tried adding @EnableHyperMediaSupport which says it configures the JSON rendering, but that had no effect on the OpenAPIv3 docs.


Solution

  • The answer was simple enough, I needed to pull in the springdoc-openapi-hateoas dependency (https://springdoc.org/#spring-hateoas-support). After pulling this in the JSON documentation was generated correctly with no additional configuration (I did not need @EnableHypermediaSupport or spring-data-rest).

    However, if you are using the Swagger UI be aware that it will automatically generate bogus 'additionalProperty' links as an example for the resource schema. This is only in the Swagger UI, if you look at the generated openapiv3 json the structure is correct (cf: https://github.com/springdoc/springdoc-openapi/issues/237). To remedy this you can provide your own example of the resource schema.