如何从swagger下载多个文件

How to download multi files from swagger

我在尝试从 swagger 下载文件时遇到问题。

当我使用下面的配置编译代码时,出现错误:

Could not find goal 'download' in plugin io.swagger:swagger-codegen-maven-plugin:2.3.1 among available goals generate

我尝试破解成 2 个插件并编译成功,但只下载了一个文件。

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>download</goal>
            </goals>
            <configuration>
                <api>Addresses</api>
                <owner>test</owner>
                <version>2.13.0</version>
                <format>yaml</format>
                <token>test</token>
                <outputFile>${address-service-swagger.file}</outputFile>
            </configuration>
        </execution>
        <execution>
            <id>aec</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>download</goal>
            </goals>
            <configuration>
                <api>Shipper</api>
                <owner>test</owner>
                <version>2.13.0</version>
                <format>yaml</format>
                <token>test</token>
                <outputFile>${shipper-service-swagger.file}</outputFile>
            </configuration>
        </execution>
    </executions>
</plugin>

对了,我想定义outputFile是target文件夹下的一个文件,我试过通过target路径来改变outputFile,但是编译失败。你对这个案例有什么想法吗?

感谢您的帮助

如评论中所述,要从 SwaggerHub 下载 API 定义,您需要使用 swaggerhub-maven-plugin, not swagger-codegen-maven-plugin.

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swaggerhub-maven-plugin</artifactId>
    ...
</plugin>

你用错了插件,你可以这样做 如果你的 swaggerhub api link 是这样的 https://app.swaggerhub.com/apis/massivebet/betting/0.9.0 然后你配置这个和 运行

mvn clean generate-resources 下载为 yaml 文件

  <plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swaggerhub-maven-plugin</artifactId>
    <version>1.0.8</version>
    <executions>
      <execution>
        <phase>generate-resources</phase>
        <goals>
          <goal>download</goal>
        </goals>

        <configuration>
          <api>betting</api>
          <owner>massivebet</owner>
          <version>0.9.0</version>
          <host>api.swaggerhub.com</host>
          <format>yaml</format>
          <token>your token if private apis</token>-->
          <outputFile>target/test.yaml</outputFile>
        </configuration>
      </execution>
    </executions>
  </plugin>