标题翻译
Swagger codegen Maven plugin - generate ResponseEntity?
问题
有没有一种方法可以告诉Swagger代码生成的Maven插件,在生成客户端API定义(即ApiClient的消费者)时,它应该使用org.springframework.http.ResponseEntity<T>
作为返回类型生成方法签名,其中T
是实际返回的类型?
我希望在调用服务器上的方法时能够检查实例的HTTP状态码。
为了明确我想要的,而不是
public void deleteById(String id);
我想要
public ResponseEntity<Void> deleteById(String id);
我正在使用插件的2.3.1版本。当前配置如下:
<execution>
<id>generate-client</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.json</inputSpec>
<language>java</language>
<library>resttemplate</library>
<addCompileSourceRoot>true</addCompileSourceRoot>
<modelPackage>com.my.group.model</modelPackage>
<apiPackage>com.my.group.api</apiPackage>
<invokerPackage>com.my.group.invoker</invokerPackage>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<groupId>com.my.group</groupId>
<artifactId>client</artifactId>
</configOptions>
</configuration>
</execution>
英文翻译
Is there a way to tell the Swagger codegen Maven plugin that, when it generates clientside API definitions (i.e. consumers of ApiClient), it should generate method signatures using org.springframework.http.ResponseEntity<T>
as the return type, where T
is the actual type being returned?
I would like to be able to check for instance the HTTP status codes when invoking methods on the server.
To make it explicit what I want, rather than
public void deleteById(String id);
I want
public ResponseEntity<Void> deleteById(String id);
I'm using 2.3.1 of the plugin. Current configuration:
<execution>
<id>generate-client</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.json</inputSpec>
<language>java</language>
<library>resttemplate</library>
<addCompileSourceRoot>true</addCompileSourceRoot>
<modelPackage>com.my.group.model</modelPackage>
<apiPackage>com.my.group.api</apiPackage>
<invokerPackage>com.my.group.invoker</invokerPackage>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<groupId>com.my.group</groupId>
<artifactId>client</artifactId>
</configOptions>
</configuration>
</execution>
专注分享java语言的经验与见解,让所有开发者获益!
评论