有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有没有办法在Spring中包含controller with Swagger中未使用的类?

我正在使用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>

有什么方法可以通过大摇大摆来实现这个目标吗? 它的主要目标是让yaml可以导入Apicurio并在我的应用程序中使用

或者,是否有任何方法可以生成包含所有此类类的yaml,而无需在任何控制器中使用它

 @ApiModel
    public class Student {
        @Min(1)
        @Max(20)
        @ApiModelProperty
        private int id;
        @ApiModelProperty
        private String name;}

共 (1) 个答案

  1. # 1 楼答案

    使用micronaut是可能的。openapi包含yml文件。例如,如果在openapi/mySchema.yml中有一个openapi模式,可以通过在openapi.properties中放置以下行将其导入到模式中:

    micronaut.openapi.additional.files=openapi
    

    不幸的是,如果需要使用该类,这种方法就不起作用。你可以单独定义一个类,但你需要保持它与mySchema同步。yml是手动的