Upgrade to Pro — share decks privately, control downloads, hide ads and more …

generate pojo with swagger-codegen in android

generate pojo with swagger-codegen in android

swagger-codegenでpojo生成

Shinnosuke Kugimiya

September 29, 2017
Tweet

More Decks by Shinnosuke Kugimiya

Other Decks in Programming

Transcript

  1. public interface ApiClient { @GET("/api/users") Single<List<GetUserResponse>> getAll(); @GET("/api/users/{id}") Single<UserResponse> get(@Path("id")

    int id); @POST("/api/users") Single<UserResponse> create(@Body CreateUserRequest request); @POST("/tokens/new") Single<PublishTokenResponse> publishToken(@Body PublishTokenRequest request); @POST("/tokens/verify") Single<VerifyTokenResponse> tokenVerify(@Body VerifyTokenRequest request); }
  2. public interface ApiClient { @GET("/api/users") Single<List<GetUserResponse>> getAll(); @GET("/api/users/{id}") Single<UserResponse> get(@Path("id")

    int id); @POST("/api/users") Single<UserResponse> create(@Body CreateUserRequest request); @POST("/tokens/new") Single<PublishTokenResponse> publishToken(@Body PublishTokenRequest request); @POST("/tokens/verify") Single<VerifyTokenResponse> tokenVerify(@Body VerifyTokenRequest request); } 3FUSPpUΛ࢖༻ͯ͠ ֤"1*ͱͷૄ௨Λ ఆ͍ٛͯ͠ΔͳΜͰ΋ͳ͍ίʔυ
  3. public interface ApiClient { @GET("/api/users") Single<List<GetUserResponse>> getAll(); @GET("/api/users/{id}") Single<UserResponse> get(@Path("id")

    int id); @POST("/api/users") Single<UserResponse> create(@Body CreateUserRequest request); @POST("/tokens/new") Single<PublishTokenResponse> publishToken(@Body PublishTokenRequest request); @POST("/tokens/verify") Single<VerifyTokenResponse> tokenVerify(@Body VerifyTokenRequest request); } ͜Ε͸ಛʹ໰୊ͳ͍ ͨͩ"1*ͷ਺͕͍͢͝૿͑ͨ࣌ɺɺ
  4. public interface ApiClient { @GET("/api/users") Single<List<GetUserResponse>> getAll(); @GET("/api/users/{id}") Single<UserResponse> get(@Path("id")

    int id); @POST("/api/users") Single<UserResponse> create(@Body CreateUserRequest request); @POST("/tokens/new") Single<PublishTokenResponse> publishToken(@Body PublishTokenRequest request); @POST("/tokens/verify") Single<VerifyTokenResponse> tokenVerify(@Body VerifyTokenRequest request); : Լʹͨ͘͞Μଓ͘ } ͜ΕΒ࡞Δͷ େม͡Όͳ͍Ͱ͔͢ʁ
  5. { "item": { "id": 1234, "summary": { "name": "hoge", "description":

    "hoge" }, "items": { "items": [ { "id": 1234, "hogeId": 1234, "hogeUrl": “https://hoge.com“ } ], "pager": { "next": 3, "current": 2, "previous": 1 } } } } ྫ͑͹͜ΜͳKTPOΛ QPKPʹ͢Δͱͯ͠
  6. ੜ੒ίϚϯυଧͭ java -jar swagger-codegen-cli.jar generate -i ./ swagger.json -l android-poco

    -t android --model- package hoge.anroid.api --model-name-suffix Json -o dist w AJAΦϓγϣϯͰTXBHHFSKTPOࢦఆ w AUAΦϓγϣϯͰςϯϓϨʔτࢦఆ w APAΦϓγϣϯͰग़ྗઌࢦఆ w ANPEFMOBNFTV⒏YAͰQPKPͷTV⒏YΛࢦఆ w ANPEFMQBDLBHFAͰQBDLBHF໊ࢦఆ ςϯϓϨʔτʹNPEFMNVTUBDIF͔͠ͳͯ͘΋ଞͷ΋ͷ΋ੜ੒͞Ε ·͢ɻෆཁͳ΋ͷ͸࡟আͯ͠͠·͍·͠ΐ͏ɻ