Ric*_*ler 5 java jax-rs maven swagger swagger-codegen
我想使用swagger-codegen maven插件为我的API生成JAX-RS服务器存根,但我想使用自己的服务实现类,而不是生成的服务实现类.有没有办法生成除了这个类以外的所有东西?对于我的API,该工具生成四个api类:ProfilesApi,ProfilesApiService,ProfilesApiServiceFactory和ProfilesApiServiceImpl.
我目前的maven配置:
<configuration>
<inputSpec>src/main/resources/Profile.json</inputSpec>
<language>jaxrs</language>
<configOptions>
<dateLibrary>java8</dateLibrary>
</configOptions>
<models>Profile,PageInformation,ProfileResult</models>
<modelPackage>com.myApp.profile-api-model</modelPackage>
<apiPackage>com.myApp.profile-api-webapp</apiPackage>
<library>jersey2</library>
<environmentVariables>
<!-- change default client library (here until plugin 2.1.5). Doesn't seem to work! -->
<library>jersey2</library>
<!-- generate all models -->
<models></models>
<!-- generate all APIs -->
<apis></apis>
<!-- generate just the supporting files that are Java source code (not project build files) -->
<supportingFiles>ApiException.java,ApiOriginFilter.java,ApiResponseMessage.java,JacksonJsonProvider.java,LocalDateProvider.java,LocalDateTimeProvider.java,NotFoundException.java,StringUtil.java,web.xml,ProfilesApi.java,ProfilesApiService.java,ProfilesApiServiceFactory.java</supportingFiles>
</environmentVariables>
</configuration>
Run Code Online (Sandbox Code Playgroud)
jbx*_*jbx 10
正确的方法是通过<generateSupportingFiles>配置和配置<interfaceOnly>中的两个配置选项<configOptions>.在<generateSupportingFiles>不生成可执行文件入口点,pom.xml等等,而<interfaceOnly>标志不产生服务的实现,只有接口.通过这种方式,您可以拥有自己的可执行类来执行其他任务,您自己pom.xml的服务实现以及您自己的服务实现,并且您可以根据需要多次重新生成API和模型mvn clean package.
我不确定Jersey模板是否会检查<interfaceOnly,但Spring Boot和CXF JAX-RS模板是否可以.
在你的maven中pom.xml,你的<configuration>内部构建插件swagger-codegen-maven-plugin需要看起来像这样:
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<interfaceOnly>true</interfaceOnly>
...
</configOptions>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这些配置选项没有很好的文档记录,你必须做大量的研究,并在一些github问题上偶然发现它们.
| 归档时间: |
|
| 查看次数: |
5527 次 |
| 最近记录: |