如何解决有没有办法在Spring的Swagger中包含控制器未使用的类?
我正在使用swagger-maven-plugin(kongchen)生成静态文档并 我想生成这样的Yaml:
swagger: "2.0"
info:
version: "1.0.0"
title: "Swagger example"
paths:
/api/students:
post:
operationId: "addStudent"
parameters:
- in: "body"
name: "body"
required: false
schema:
$ref: "#/definitions/Student"
responses:
200:
description: "successful operation"
schema:
type: "boolean"
definitions:
Student:
type: "object"
properties:
id:
type: "integer"
format: "int32"
minimum: 1
maximum: 20
name:
type: "string"
surname:
type: "string"
但是我也希望插件包含控制器中未定义的类。
我的插件设置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.8</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>true</springmvc>
<locations>
<location>
mypackage
</location>
</locations>
<info>
<title>
Swagger example
</title>
<version>
1.0.0
</version>
</info>
<outputFormats>json,yaml</outputFormats>
<swaggerDirectory>generated</swaggerDirectory>
<swaggerApiReader>com.github.kongchen.swagger.docgen.reader.SpringMvcApiReader</swaggerApiReader>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- Adding dependency to swagger-hibernate-validations to enable the BeanValidator as a custom
model converter -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-hibernate-validations</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
有什么方法可以使用Swagger实现此目标吗? 它的主要目标是拥有可以导入到Apicurio并在我的应用程序中使用的yaml。
或者也许有什么方法可以生成包含所有此类的yaml,而无需在任何控制器中使用它?
@ApiModel
public class Student {
@Min(1)
@Max(20)
@ApiModelProperty
private int id;
@ApiModelProperty
private String name;}
解决方法
您是要包括模型,请求/响应存根吗? 如果是这样,您可以使用Swagger注释
方法级别:
val == -0.0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。