问题描述
我定义了以下示例OpenAPI 3.0规范:
openapi: 3.0.1
info:
title: Hello World REST API
version: v0
servers:
- url: 'http://localhost:8080'
description: Auto generated URL
paths:
/helloWorld:
get:
tags:
- controller.
operationId: helloWorld
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/HelloWorld'
examples:
HelloWorld1:
value:
someText: test
someBoolean: true
components:
schemas:
HelloWorld:
type: object
properties:
someText:
type: string
someBoolean:
type: boolean
我正在使用OpenAPI Generator Maven插件来生成spring引导代码。我也正在使用Swagger UI可视地生成开放的api文档。代码生成器工作正常,但是当我打开URL http:// localhost:8080 / swagger-ui.html 时,我可以看到文档未正确创建。 Swagger UI似乎忽略了所生成代码中的几个注释。例如。我看不到示例数据。
最小工作示例:
POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>restApi</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jackson-databind-nullable.version>0.2.1</jackson-databind-nullable.version>
<openapitools.version>4.3.1</openapitools.version>
<springdoc-openapi-ui.version>1.4.6</springdoc-openapi-ui.version>
<swagger-annotations.version>1.6.2</swagger-annotations.version>
</properties>
<dependencies>
<!-- Swagger UI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
</dependency>
<!-- Swagger Codegen / OpenAPI -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>${jackson-databind-nullable.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapitools.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/openapi.yaml
</inputSpec>
<generatorName>spring</generatorName>
<generateModels>true</generateModels>
<generateApis>true</generateApis>
<generateApiDocumentation>true</generateApiDocumentation>
<generateSupportingFiles>true</generateSupportingFiles>
<apiPackage>${project.groupId}.api</apiPackage>
<modelPackage>${project.groupId}.model</modelPackage>
<configOptions>
<dateLibrary>java8-localdatetime</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
API实现:
@RestController
public class HelloWorldApiImpl implements HelloWorldApi {
@Override
public ResponseEntity<HelloWorld> helloWorld() {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)