[英]Is there any way to include classes that are not used in controller with Swagger in Spring?
I'm using swagger-maven-plugin(kongchen) to generate static document and I would like to generate yaml like this:我正在使用 swagger-maven-plugin(kongchen) 生成 static 文档,我想像这样生成 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"
But i would also want plugin to include classes that are not defined in my controller.但我也希望插件包含我的 controller 中未定义的类。
my plugin setup:我的插件设置:
<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>
Is there any way to achieve this goal using Swagger?有没有办法使用 Swagger 来实现这个目标? The main goal of it is to have yaml that i can import to Apicurio and use in my applications.
它的主要目标是拥有 yaml,我可以将其导入 Apicurio 并在我的应用程序中使用。
Or maybe is there any way to generate yaml that includes all classes like this without using it in any controller?或者也许有什么方法可以生成 yaml,其中包括所有这样的类,而无需在任何 controller 中使用它?
@ApiModel
public class Student {
@Min(1)
@Max(20)
@ApiModelProperty
private int id;
@ApiModelProperty
private String name;}
Do you mean to include the models, request / response stubs?您的意思是包括模型、请求/响应存根吗? If so you can use Swagger annotations
如果是这样,您可以使用 Swagger 注释
Method Level:方法级别:
@ApiOperation(value = "Get Details", response = ResponseClassStub, produces = MediaType.APPLICATION_JSON_VALUE)
It is possible with micronaut.openapi to include yml files. micronaut.openapi 可以包含 yml 文件。 For example, if you have an openapi schema in
openapi/mySchema.yml
, you can import it to your schema by putting the following line in openapi.properties
:例如,如果您在
openapi/mySchema.yml
mySchema.yml 中有一个 openapi 架构,您可以通过将以下行放入openapi.properties
将其导入到您的架构中:
micronaut.openapi.additional.files=openapi
Unfortunately this approach doesn't work if you need to use the class. You can have a class defined separately but you need to keep it in sync with mySchema.yml manually.不幸的是,如果您需要使用 class,则此方法不起作用。您可以单独定义 class,但您需要手动将其与 mySchema.yml 保持同步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.