我找到了项目https://github.com/swagger-api/swagger-codegen。
然而,这是生成一个基于OpenFeign的客户端。
有没有办法自动生成使用Netflix的假注释和请求映射的客户端界面?
示例:
@FeignClient(name = "ldap-proxy")
public interface LdapProxyClient {
@RequestMapping(path = "/ldap-proxy/v1/users/{userNameOrEMail}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
LdapUser search(@PathVariable("userNameOrEMail") String userNameOrEMail);
}
与以下课程相反:
Thannks
答案 0 :(得分:2)
您可以尝试spring-cloud swagger-codegen library。
生成客户端的命令示例:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l spring \
--library spring-cloud \
-o samples/client/petstore/java
以下是生成文件的示例:
<强> PetApi.java 强>
@Api(value = "Pet", description = "the Pet API")
public interface PetApi {
@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
@Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets")
})
}, tags={ "pet", })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") })
@RequestMapping(value = "/pet",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.POST)
ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet body);
}
<强> PetApiClient.java 强>
@FeignClient(name="${swaggerPetstore.name:swaggerPetstore}", url="${swaggerPetstore.url:http://petstore.swagger.io/v2}", configuration = ClientConfiguration.class)
public interface PetApiClient extends PetApi {
}