我将我的 swagger yaml 文件打包在它自己的项目中,该文件被打包为 jar 上传到我们的 Maven 存储库。使用 swagger 文件和 swagger-maven-codegen-plugin,客户端应该可以从 swagger 文件生成他们的 nedded 模型。
客户端如何访问位于 static/swagger.yaml 下的 jar 内的 swagger 文件?当然,前提是他们将其声明为依赖项。
客户示例:
<build>
<plugins>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>path/to/yaml/in/jar.yaml</inputSpec> <!-- CORRECT PATH? -->
<language>spring</language>
<modelPackage>com.dos.search.api</modelPackage>
<apiPackage>com.dos.search.api</apiPackage>
<language>spring</language>
<generateSupportingFiles>false</generateSupportingFiles>
<withXml>false</withXml>
<generateApis>true</generateApis>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateModels>true</generateModels>
<configOptions>
<library>spring-boot</library>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<useTags>true</useTags>
<useBeanValidation>true</useBeanValidation>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>false</delegatePattern>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
您可以使用
maven-dependency-plugin
来 unpack
您的依赖项 jar。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>validate</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.example</groupId>
<artifactId>api-interface</artifactId>
<version>${project.version}</version>
<type>jar</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>**/*.yaml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>