How to display a manually generated OAS in "swagger-ui/index.html"

Viewed 125

I've created a REST API with Spring Boot as a project for a boot camp.

After finishing it, I decided to document the endpoints and found "springdoc-openapi-ui" (which I understand is meant to create automatically documentation based on my project code)

The thing is, I've found the results quite disappointing so I took the JSON from "/v3/api-docs/", and pasted it into the online Swagger Editor

Once I finished creating a beautiful documentation I realized I don't know how to make the "swagger-ui/index.html" point to my swagger.json or swagger.yaml automatically. I've read in the Swagger UI configuration guide that I can create a "swagger-configuration.YAML" file and define a parameter called spec where I can point to my JSON object but I couldn't understand exactly how to implement that solution (don't know where to place the file and the syntaxes for said configuration) Another option I read somewhere on this page (can't find it now) was to embed the JSON in the index.html as a script but there was no example on how to do it correctly

Which was the whole point of creating manually my documentation

I'll appreciate any help and I hope I've been clear to explain what I'm looking for.

1 Answers

I've found the solution! Extracted from Springdoc.org - F.A.Q.

If your file open-api.json, contains the OpenAPI documentation in OpenAPI 3 format. Then simply declare: The file name can be anything you want, from the moment your declaration is consistent yaml or json OpenAPI Spec.

springdoc.swagger-ui.url=/open-api.json

Then the file open-api.json, should be located in: src/main/resources/static No additional configuration is needed.

Related