1

如标题所述,我对 swagger maven 插件的配置似乎跳过了带有 @BeanParam 注释的参数。

我已经按照与 github 上的示例相同的方式配置了我的代码(如下链接所示),所以我不知道会出现什么问题。

在主类 MyBean 示例中调用

这是我目前的配置

我的输入文件

//MyInterface.java
@Api(value = "myInterface")
public interface MyInterface {
    @Path("/.../{bar}/.../{baz}")
    Response foo(@BeanParam MyBean myBean);
}
//MyBean.java
public class MyBean {
    @PathParam("bar")
    private Long bar;

    @PathParam("baz")
    private Long baz;

    //getters and setters
}
<!-- pom.xml -->
<plugin>
  <groupId>com.github.kongchen</groupId>
  <artifactId>swagger-maven-plugin</artifactId>
  <version>3.1.8</version>
  <executions>
    <execution>
      <id>ID</id>
      <phase>compile</phase>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <apiSources>
          <apiSource>
            <springmvc>false</springmvc>
            <locations>
              <location>package.of.MyInterface</location>
              <location>package.of.MyBean</location>
            </locations>
            <schemes>
              <scheme>https</scheme>
            </schemes>
            <host>${swagger.ui.host}</host>
            <basePath>/api</basePath>
            <info>
              <title>Title</title>
              <version>1.0.0</version>
              <description>Desc</description>
            </info>
            <outputFormats>yaml</outputFormats>
            <swaggerFileName>${project.name}-external</swaggerFileName>
            <swaggerDirectory>${project.build.directory}/swagger</swaggerDirectory>
          </apiSource>
        </apiSources>
      </configuration>
    </execution>
   </executions>
 </plugin>

我的输出招摇文件

---
swagger: "2.0"
#...
paths:
  /.../{bar}/.../{baz}:
    put:
      operationId: "foo"
      parameters: []

是什么导致输出中的参数数组保持为空?我所有没有 bean 注释的方法都可以正常工作。

4

1 回答 1

0

我最终改用了这个插件,文档有点稀疏,但梳理示例很有帮助。作为额外的奖励,它生成 openapi3 而不是 swagger 2。

于 2019-06-07T13:56:45.803 回答