SwaggerUI没有显示由OpenApi代码生成的正确生成的文档化API

时间:2020-04-07 15:52:05

标签: java swagger swagger-ui openapi openapi-generator

我正在使用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();
    }
}

我已经检查了解决方案,并且在执行api调用时获得HTTP状态200,但是当我尝试访问swagger-ui页面时,未记录此API端点。有什么方法可以配置OpenAPI UI或SwaggerUI指向我的Yaml文档?

SwaggerUI屏幕 enter image description here

0 个答案:

没有答案