【问题标题】:Swagger Maven Plugin not generating parameters from @BeanParam annotatated parametersSwagger Maven 插件未从 @BeanParam 注释参数生成参数
【发布时间】:2019-10-20 04:20:09
【问题描述】:

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

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

Call in main class MyBean example

这是我当前的配置

我的输入文件

//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 文件

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

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

【问题讨论】:

  • (SpringBoot) 在 @RequestMapping 注解中使用来自 application.properties 的变量也会导致此问题。 @RequestMapping("/api/${api.version}") 将在 swagger.yaml 中生成 /api/${api.version}。我也想知道是否可以使用kongchen版本的插件来做到这一点。

标签: jax-rs swagger-maven-plugin


【解决方案1】:

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

【讨论】:

  • 可以反过来吗?有一个 openapi yml 文件生成一个带有 beanparam 的接口吗?
猜你喜欢
  • 1970-01-01
  • 2020-03-03
  • 1970-01-01
  • 2014-12-24
  • 2019-09-24
  • 2022-01-13
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
相关资源
最近更新 更多