Skip to content

Empty API docs with nested routes #879

Closed
@DanyUP

Description

@DanyUP

Im trying SpringDoc version 1.4.7 (with only springdoc-openapi-webflux-core module) with Spring Boot 2.3.4.RELEASE and Webflux Functional Endpoints.

I mapped the routes definition bean with RouterOperations as shown in this example:

    @Bean
    @RouterOperations({
            @RouterOperation(path = "/greeter/namedHello", beanClass = HelloHandler.class, beanMethod = "namedHello"),
            @RouterOperation(path = "/greeter/hello", beanClass = HelloHandler.class, beanMethod = "hello"),
    })
    public RouterFunction<ServerResponse> helloRoutes() {
        return nest(path("/greeter"),
                route(GET("/namedHello"), helloHandler::namedHello)
                .andRoute(GET("/hello"), helloHandler::hello)
        );
    }

However the output of calling http://localhost:8080/v3/api-docs shows an empty definition:

{
  "openapi":"3.0.1",
  "info":{
    "title":"OpenAPI definition",
    "version":"v0"
  },
  "servers":[{"url":"http://localhost:8080","description":"Generated server url"}],
  "paths":{},
  "components":{}}

If I remove the prefix path from RouterOperation path, like this

    @Bean
    @RouterOperations({
            @RouterOperation(path = "/namedHello", beanClass = HelloHandler.class, beanMethod = "namedHello"),
            @RouterOperation(path = "/hello", beanClass = HelloHandler.class, beanMethod = "hello"),
    })
    public RouterFunction<ServerResponse> helloRoutes() {
        return nest(path("/greeter"),
                route(GET("/namedHello"), helloHandler::namedHello)
                .andRoute(GET("/hello"), helloHandler::hello)
        );
    }

Something seems to change, however the path in the OpenAPI definition is wrong:

{
  "openapi":"3.0.1",
  "info":{
    "title":"OpenAPI definition",
    "version":"v0"
  },
  "servers":[
    {
      "url":"http://localhost:8080",
      "description":"Generated server url"
    }
  ],
  "paths":{
    "/hello":{
      "get":{
        "tags":[
          "hello-handler"
        ],
        "operationId":"hello",
        "responses":{
          "200":{
            "description":"OK",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/HelloResponseDef"
                }
              }
            }
          }
        }
      }
    },
    "/namedHello":{
      "get":{
        "tags":[
          "hello-handler"
        ],
        "operationId":"namedHello",
        "responses":{
          "200":{
            "description":"OK",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/ServerResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  // JSON truncated

Here is the expected output:

{
  "openapi":"3.0.1",
  "info":{
    "title":"OpenAPI definition",
    "version":"v0"
  },
  "servers":[
    {
      "url":"http://localhost:8080",
      "description":"Generated server url"
    }
  ],
  "paths":{
    "/greeter/hello":{
      "get":{
        "tags":[
          "hello-handler"
        ],
        "operationId":"hello",
        "responses":{
          "200":{
            "description":"OK",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/HelloResponseDef"
                }
              }
            }
          }
        }
      }
    },
    "/greeter/namedHello":{
      "get":{
        "tags":[
          "hello-handler"
        ],
        "operationId":"namedHello",
        "responses":{
          "200":{
            "description":"OK",
            "content":{
              "application/json":{
                "schema":{
                  "$ref":"#/components/schemas/ServerResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  // JSON truncated

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions