Springdoc openapi with webflux: display custom json/yml file instead of generated one

Viewed 1621

I have a simple service-description file open-api.json:

{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "paths": {
    "/agents/{id}/plugins": {
      "post": {
        "tags": [
          "api-controller"
        ],
...
  },
  "components": {}
}

And I use springdoc-openapi-webflux-ui in my Spring-webflux project:

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-ui</artifactId>
            <version>1.4.0</version>
        </dependency>

Is it possible to display existing file instead of generated one? Any help, thanks!

2 Answers

If your file 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)

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.

The property springdoc.swagger-ui.configUrl, can be used for different usage as discussed here, because the structure is different from

Ok so here is what you need.

  1. Inside your src/main/resources directory, create a directory called static. Inside that place your open-api.json file. (Note- The name of the json file can be anything) [ Here is a sample open api spec json file ]
  2. Add this property in your application yaml:
springdoc:
  swagger-ui:
    configUrl: /open-api.json

Then start your App and hit the URL http://localhost:8080/swagger-ui.html

Note that if spring security is present, you need additional configuration.

Related