我正在使用swagger-maven插件(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注释
方法级别:
@ApiOperation(value = "Get Details", response = ResponseClassStub, produces = MediaType.APPLICATION_JSON_VALUE)
使用micronaut.openapi可以包含yml文件。例如,如果您在openapi/mySchema.yml
中有一个openapi模式,您可以通过在openapi.properties
:中放入以下行将其导入到您的模式中
micronaut.openapi.additional.files=openapi
不幸的是,如果您需要使用类,这种方法就不起作用。您可以单独定义一个类,但需要手动将其与mySchema.yml保持同步。