SwaggerUI не показывает документированный API, сгенерированный должным образом OpenApi codegen - PullRequest
0 голосов
/ 07 апреля 2020

Я использую openapi-generator-maven-plugin для генерации кода из документации YAML.

openapi: 3.0.3
info:
  title: Example API Doc
  description: Those are example endpoints.
  termsOfService: https://localhost:8080/termsOfService
  license:
    name: No license
    url: https://localhost:8080/license
  version: 1.0-SNAPSHOT
servers:
- url: https://localhost:8080/
- url: http://localhost:8080/
tags:
- name: example
  description: Example Tag
paths:
  /example:
    get:
      tags:
      - example
      summary: Example GET request
      description: Send example GET request
      operationId: exampleGetRequest
      responses:
        200:
          description: Successful operation
          content: {}
        400:
          description: Example Bad Request
          content: {}
        404:
          description: Example Not Found
          content: {}

Вот как я настраиваю плагин maven для генерации интерфейсов:

<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>4.1.1</version>
  <configuration>
    <generatorName>spring</generatorName>
    <inputSpec>${project.basedir}/src/main/resources/exampleApi.yaml</inputSpec>
    <apiPackage>com.example.openapi.generated.api</apiPackage>
    <modelPackage>com.example.openapi.generated.models</modelPackage>
    <generateSupportingFiles>false</generateSupportingFiles>
    <output>${project.basedir}</output>
    <configOptions>
      <dateLibrary>java8</dateLibrary>
      <java8>true</java8>
      <interfaceOnly>true</interfaceOnly>
    </configOptions>
  </configuration>
</plugin>

Этот плагин работает хорошо, и я получаю такой интерфейс

@Api(value = "example", description = "the example API")
public interface ExampleApi {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

    @ApiOperation(value = "Example GET request", nickname = "exampleGetRequest", notes = "Send example GET request", tags = {"example",})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Successful operation"),
            @ApiResponse(code = 400, message = "Example Bad Request"),
            @ApiResponse(code = 404, message = "Example Not Found")})
    @RequestMapping(value = "/example", method = RequestMethod.GET)
    default ResponseEntity<Void> exampleGetRequest() {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
    }
}

Я реализую свой интерфейс с помощью этого класса:

@RestController
public class ExampleApiImpl implements ExampleApi {

    @Override
    public ResponseEntity<Void> exampleGetRequest() {
        return ResponseEntity.ok().build();
    }
}

Я проверил решение и получил HTTP статус 200, когда я выполняю вызов API, но когда я пытаюсь получить доступ к странице swagger-ui, эта конечная точка API не документируется. Есть ли способ настроить OpenAPI UI или SwaggerUI, чтобы они указывали на мою документацию yaml?

Экран SwaggerUI enter image description here

...