【问题标题】:Netflix Feign Code Generation using Swagger使用 Swagger 生成 Netflix Feign 代码
【发布时间】:2018-09-24 04:21:31
【问题描述】:

我找到了项目https://github.com/swagger-api/swagger-codegen。

但是,这会生成一个基于 OpenFeign 的客户端。

有没有办法自动生成一个使用 Netflix 的 feign 注解和请求映射的客户端接口?

例子:

@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);
}

与以下课程相反:

https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/java/feign/src/main/java/io/swagger/client/ApiClient.java

谢谢

【问题讨论】:

标签: spring swagger-codegen netflix-feign spring-cloud-feign feign


【解决方案1】:

你可以试试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 {
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 2022-10-20
    相关资源
    最近更新 更多