3

I have a Spring Boot application where the API is specified as a OpenAPI 3.0.2 YAML document. I used the openapi-generator-maven-plugin to generate code from the spec. When I open up http://localhost:8080/swagger-ui.html, it displays: "No operations defined in spec!"

In the spec, I have:

servers:
    - url: /books/api/v1

Which results in this in the controller class:

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2021-06-17T14:52:43.686820-07:00[America/Los_Angeles]")
@Controller
@RequestMapping("${openapi.axmPlatformKeyService.base-path:/books/api/v1}")
public class SvcApiController implements SvcApi {
    // ...
    // ...
}

If I load the openapi-definition.yaml in editor.swagger.io, it shows the definitions as expected.

If I create another controller this way:

@RestController
public class AddonController implements SvcApi {
    // ...
    // ...
}

then Swagger UI shows the APIs, which basically means that if the generated code had "@RestController" it would have worked okay.

Since the generated controller is annotated with @Controller, Swagger UI is not able to pick it up. Even after adding this extra @RestController, Swagger UI's Try it out function doesn't include "/books/api/v1" in the URL it generates.

Net-effect is with this AddonController, if I have one request /book/{id} in the spec, there are two endpoints in the service:

/books/api/v1/book/{id} /book/{id}

and the latter is invoked by Swagger UI.

These are the relevant dependencies:

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

    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.6.2</version>
    </dependency>
devurandom
  • 61
  • 1
  • 4

1 Answers1

0

Adding a static initializer that does

SpringDocUtils.getConfig().addRestControllers(SvcApiController.class) 

resolves the issue. The AddonController is not needed in this case.

devurandom
  • 61
  • 1
  • 4