2

我无法理解为什么 swagger-maven-plugin 不为 Spring Boot 中的参数生成定义。json看起来像这样

      "parameters" : [ {
      "name" : "targetFilterSaveRqDto",
      "in" : "query",
      "required" : true,
      "type" : "ref"
    } ],

我希望它看起来像这样。参考架构

     "parameters" : [ {
      "in" : "body",
      "name" : "body",
      "description" : "DTO",
      "required" : true,
      "schema" : {
        "$ref" : "#/definitions/TargetFilterSaveRqDto"
      }
    } ],

我在这样的 Spring Boot 应用程序中使用 swagger-maven-plugin

<plugin>


<groupId>com.github.kongchen</groupId>
                    <artifactId>swagger-maven-plugin</artifactId>
                    <version>3.1.7</version>
                    <configuration>
                        <skipSwaggerGeneration>${swagger.skipGeneration}</skipSwaggerGeneration>
                        <apiSources>
                            <apiSource>
                                <springmvc>true</springmvc>
                                <locations>
                                    <location>${swagger.api.package}</location>
                                </locations>
                                <schemes>
                                    <schema>http</schema>
                                    <schema>https</schema>
                                </schemes>
                                <host>${swagger.api.url.host}:${swagger.api.url.port}</host>
                                <basePath>${swagger.api.url.base}</basePath>
                                <info>
                                    <title>${swagger.api.title}</title>
                                    <version>${swagger.api.version}</version>
                                    <description>${swagger.api.description}</description>
                                    <contact>
                                        <email>support@stream.ru</email>
                                        <url>http://stream.ru</url>
                                    </contact>
                                    <license>
                                        <name>Company Licence</name>
                                    </license>
                                </info>
                                <securityDefinitions>
                                    <securityDefinition>
                                        <name>basicAuth</name>
                                        <type>basic</type>
                                    </securityDefinition>
                                </securityDefinitions>
                                <outputFormats>json,yaml</outputFormats>
                                <swaggerDirectory>${swagger.directory}/desc</swaggerDirectory>
                            </apiSource>
                        </apiSources>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

在控制器中它看起来

    @PostMapping("/filter")
@ApiOperation()
public void createTargetFilter(
        @ApiParam(value = "TargetFilterSaveRqDto", required = true) @RequestParam TargetFilterSaveRqDto targetFilterSaveRqDto
) throws JsonProcessingException {
4

0 回答 0