Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display OpenAPI 3.0 YAML file in Spring Boot (Maven)

I feel like I'm missing something simple, but none of my searches have gotten me the answer I was hoping/looking for.

Problem Statement
I'm writing a Spring Boot application which exposes a bunch of RESTful API's. For various reasons I have a YAML file that contains the API documentation (written in OpenAPI 3.0). I'm looking for an easy (it's Spring Boot after all) way to show that document.

What I've done
Spent more then 3 hours reading various posts, watching youtube vids that talk about Springfox's swagger and swagger-ui (amongst other things)
This generates the documentation 'on the fly', I want to display the YAML file

I've seen a couple of posts that discuss downloading the swagger-ui github repo, unzip it and modify the index.html to point at my YAML file instead of the default it has.
While this is doable, it requires me to manual download, update files and repackage them (not a huge issue but seems more then I would expect)

Solution being looked for
Ideally I was hoping there was a Maven plugin that I could setup and pass a config option to, telling it where the YAML file is located and it would simply display it

Thanks in advance

like image 974
Jim M. Avatar asked Sep 05 '25 03:09

Jim M.


1 Answers

You can serve the file as a static resource, either by adding it to one of the spring boot default static resources locations (src/main/resources/META-INF/resources, src/main/resources/resources, src/main/resources/static, src/main/resources/public) or by overriding default locations and add your custom path where your open-api yaml file is located (set spring.resources.static-locations property).

like image 181
Tudro Avatar answered Sep 07 '25 23:09

Tudro