Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Removes / from the beginning of annotation paths (#28)
Browse files Browse the repository at this point in the history
* Removes `/` from the beginning of relative paths as per Retrofit recommendations.

* Updated tests.
  • Loading branch information
carlosefonseca authored and ferranpons committed Jan 21, 2019
1 parent 1cfd537 commit 3c19ac4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
12 changes: 6 additions & 6 deletions src/main/kotlin/protein/kotlinbuilders/KotlinApiBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ class KotlinApiBuilder(

val annotationSpec: AnnotationSpec = when {
operation.key.name.contains(
"GET") -> AnnotationSpec.builder(GET::class).addMember("\"${path.key}\"").build()
"GET") -> AnnotationSpec.builder(GET::class).addMember("\"${path.key.removePrefix("/")}\"").build()
operation.key.name.contains(
"POST") -> AnnotationSpec.builder(POST::class).addMember("\"${path.key}\"").build()
"POST") -> AnnotationSpec.builder(POST::class).addMember("\"${path.key.removePrefix("/")}\"").build()
operation.key.name.contains(
"PUT") -> AnnotationSpec.builder(PUT::class).addMember("\"${path.key}\"").build()
"PUT") -> AnnotationSpec.builder(PUT::class).addMember("\"${path.key.removePrefix("/")}\"").build()
operation.key.name.contains(
"PATCH") -> AnnotationSpec.builder(PATCH::class).addMember("\"${path.key}\"").build()
"PATCH") -> AnnotationSpec.builder(PATCH::class).addMember("\"${path.key.removePrefix("/")}\"").build()
operation.key.name.contains(
"DELETE") -> AnnotationSpec.builder(DELETE::class).addMember("\"${path.key}\"").build()
else -> AnnotationSpec.builder(GET::class).addMember("\"${path.key}\"").build()
"DELETE") -> AnnotationSpec.builder(DELETE::class).addMember("\"${path.key.removePrefix("/")}\"").build()
else -> AnnotationSpec.builder(GET::class).addMember("\"${path.key.removePrefix("/")}\"").build()
}

try {
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/KotlinApiBuilderShould.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class KotlinApiBuilderShould {
" *\n" +
" * @param Authorization Authorization\n" +
" */\n" +
" @GET(\"/favorites\")\n" +
" @GET(\"favorites\")\n" +
" fun getFavorites(): Single<GetFavoritesResponse>\n" +
"\n" +
" /**\n" +
Expand All @@ -67,7 +67,7 @@ class KotlinApiBuilderShould {
" * @param adId adId\n" +
" * @param Authorization Authorization\n" +
" */\n" +
" @PUT(\"/favorites/{adId}\")\n" +
" @PUT(\"favorites/{adId}\")\n" +
" fun saveFavorite(@Path(\"adId\") adId: String): Completable\n" +
"\n" +
" /**\n" +
Expand All @@ -76,7 +76,7 @@ class KotlinApiBuilderShould {
" * @param adId adId\n" +
" * @param Authorization Authorization\n" +
" */\n" +
" @DELETE(\"/favorites/{adId}\")\n" +
" @DELETE(\"favorites/{adId}\")\n" +
" fun deleteFavorite(@Path(\"adId\") adId: String): Completable\n" +
"}\n",
kotlinApiBuilder.getGeneratedApiInterfaceString())
Expand Down
22 changes: 11 additions & 11 deletions src/test/kotlin/mocks/openstf_code_generated_mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ const val OPENSTF_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" /**\n" +
" * User Profile\n" +
" */\n" +
" @GET(\"/user\")\n" +
" @GET(\"user\")\n" +
" fun getUser(): Single<UserResponse>\n" +
"\n" +
" /**\n" +
" * User Devices\n" +
" *\n" +
" * @param fields Fields query parameter takes a comma seperated list of fields. Only listed field will be return in response\n" +
" */\n" +
" @GET(\"/user/devices\")\n" +
" @GET(\"user/devices\")\n" +
" fun getUserDevices(@Query(\"fields\") fields: String?): Single<DeviceListResponse>\n" +
"\n" +
" /**\n" +
" * Add a device to a user\n" +
" *\n" +
" * @param device Device to add\n" +
" */\n" +
" @POST(\"/user/devices\")\n" +
" @POST(\"user/devices\")\n" +
" fun addUserDevice(@Body device: AddUserDevicePayload): Completable\n" +
"\n" +
" /**\n" +
Expand All @@ -40,45 +40,45 @@ const val OPENSTF_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param serial Device Serial\n" +
" * @param fields Fields query parameter takes a comma seperated list of fields. Only listed field will be return in response\n" +
" */\n" +
" @GET(\"/user/devices/{serial}\")\n" +
" @GET(\"user/devices/{serial}\")\n" +
" fun getUserDeviceBySerial(@Path(\"serial\") serial: String, @Query(\"fields\") fields: String?): Single<DeviceResponse>\n" +
"\n" +
" /**\n" +
" * Delete User Device\n" +
" *\n" +
" * @param serial Device Serial\n" +
" */\n" +
" @DELETE(\"/user/devices/{serial}\")\n" +
" @DELETE(\"user/devices/{serial}\")\n" +
" fun deleteUserDeviceBySerial(@Path(\"serial\") serial: String): Completable\n" +
"\n" +
" /**\n" +
" * Remote Connect\n" +
" *\n" +
" * @param serial Device Serial\n" +
" */\n" +
" @POST(\"/user/devices/{serial}/remoteConnect\")\n" +
" @POST(\"user/devices/{serial}/remoteConnect\")\n" +
" fun remoteConnectUserDeviceBySerial(@Path(\"serial\") serial: String): Single<RemoteConnectUserDeviceResponse>\n" +
"\n" +
" /**\n" +
" * Remote Disconnect\n" +
" *\n" +
" * @param serial Device Serial\n" +
" */\n" +
" @DELETE(\"/user/devices/{serial}/remoteConnect\")\n" +
" @DELETE(\"user/devices/{serial}/remoteConnect\")\n" +
" fun remoteDisconnectUserDeviceBySerial(@Path(\"serial\") serial: String): Completable\n" +
"\n" +
" /**\n" +
" * Access Tokens\n" +
" */\n" +
" @GET(\"/user/accessTokens\")\n" +
" @GET(\"user/accessTokens\")\n" +
" fun getUserAccessTokens(): Single<AccessTokensResponse>\n" +
"\n" +
" /**\n" +
" * Device List\n" +
" *\n" +
" * @param fields Fields query parameter takes a comma seperated list of fields. Only listed field will be return in response\n" +
" */\n" +
" @GET(\"/devices\")\n" +
" @GET(\"devices\")\n" +
" fun getDevices(@Query(\"fields\") fields: String?): Single<DeviceListResponse>\n" +
"\n" +
" /**\n" +
Expand All @@ -87,6 +87,6 @@ const val OPENSTF_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param serial Device Serial\n" +
" * @param fields Fields query parameter takes a comma seperated list of fields. Only listed field will be return in response\n" +
" */\n" +
" @GET(\"/devices/{serial}\")\n" +
" @GET(\"devices/{serial}\")\n" +
" fun getDeviceBySerial(@Path(\"serial\") serial: String, @Query(\"fields\") fields: String?): Single<DeviceResponse>\n" +
"}\n"
"}\n"
42 changes: 21 additions & 21 deletions src/test/kotlin/mocks/pet_store_code_generated_mocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" *\n" +
" * @param body Pet object that needs to be added to the store\n" +
" */\n" +
" @PUT(\"/pet\")\n" +
" @PUT(\"pet\")\n" +
" fun updatePet(@Body body: Pet): Completable\n" +
"\n" +
" /**\n" +
" * Add a new pet to the store\n" +
" *\n" +
" * @param body Pet object that needs to be added to the store\n" +
" */\n" +
" @POST(\"/pet\")\n" +
" @POST(\"pet\")\n" +
" fun addPet(@Body body: Pet): Completable\n" +
"\n" +
" /**\n" +
" * Finds Pets by status\n" +
" *\n" +
" * @param status Status values that need to be considered for filter\n" +
" */\n" +
" @GET(\"/pet/findByStatus\")\n" +
" @GET(\"pet/findByStatus\")\n" +
" fun findPetsByStatus(@Query(\"status\") status: List<String>): Single<List<Pet>>\n" +
"\n" +
" /**\n" +
" * Finds Pets by tags\n" +
" *\n" +
" * @param tags Tags to filter by\n" +
" */\n" +
" @GET(\"/pet/findByTags\")\n" +
" @GET(\"pet/findByTags\")\n" +
" fun findPetsByTags(@Query(\"tags\") tags: List<String>): Single<List<Pet>>\n" +
"\n" +
" /**\n" +
" * Find pet by ID\n" +
" *\n" +
" * @param petId ID of pet to return\n" +
" */\n" +
" @GET(\"/pet/{petId}\")\n" +
" @GET(\"pet/{petId}\")\n" +
" fun getPetById(@Path(\"petId\") petId: Long): Single<Pet>\n" +
"\n" +
" /**\n" +
Expand All @@ -61,15 +61,15 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param name Updated name of the pet\n" +
" * @param status Updated status of the pet\n" +
" */\n" +
" @POST(\"/pet/{petId}\")\n" +
" @POST(\"pet/{petId}\")\n" +
" fun updatePetWithForm(@Path(\"petId\") petId: Long): Completable\n" +
"\n" +
" /**\n" +
" * Deletes a pet\n" +
" *\n" +
" * @param petId Pet id to delete\n" +
" */\n" +
" @DELETE(\"/pet/{petId}\")\n" +
" @DELETE(\"pet/{petId}\")\n" +
" fun deletePet(@Path(\"petId\") petId: Long): Completable\n" +
"\n" +
" /**\n" +
Expand All @@ -79,61 +79,61 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param additionalMetadata Additional data to pass to server\n" +
" * @param file file to upload\n" +
" */\n" +
" @POST(\"/pet/{petId}/uploadImage\")\n" +
" @POST(\"pet/{petId}/uploadImage\")\n" +
" fun uploadFile(@Path(\"petId\") petId: Long): Single<ApiResponse>\n" +
"\n" +
" /**\n" +
" * Returns pet inventories by status\n" +
" */\n" +
" @GET(\"/store/inventory\")\n" +
" @GET(\"store/inventory\")\n" +
" fun getInventory(): Completable\n" +
"\n" +
" /**\n" +
" * Place an order for a pet\n" +
" *\n" +
" * @param body order placed for purchasing the pet\n" +
" */\n" +
" @POST(\"/store/order\")\n" +
" @POST(\"store/order\")\n" +
" fun placeOrder(@Body body: Order): Single<Order>\n" +
"\n" +
" /**\n" +
" * Find purchase order by ID\n" +
" *\n" +
" * @param orderId ID of pet that needs to be fetched\n" +
" */\n" +
" @GET(\"/store/order/{orderId}\")\n" +
" @GET(\"store/order/{orderId}\")\n" +
" fun getOrderById(@Path(\"orderId\") orderId: Long): Single<Order>\n" +
"\n" +
" /**\n" +
" * Delete purchase order by ID\n" +
" *\n" +
" * @param orderId ID of the order that needs to be deleted\n" +
" */\n" +
" @DELETE(\"/store/order/{orderId}\")\n" +
" @DELETE(\"store/order/{orderId}\")\n" +
" fun deleteOrder(@Path(\"orderId\") orderId: Long): Completable\n" +
"\n" +
" /**\n" +
" * Create user\n" +
" *\n" +
" * @param body Created user object\n" +
" */\n" +
" @POST(\"/user\")\n" +
" @POST(\"user\")\n" +
" fun createUser(@Body body: User): Completable\n" +
"\n" +
" /**\n" +
" * Creates list of users with given input array\n" +
" *\n" +
" * @param body List of user object\n" +
" */\n" +
" @POST(\"/user/createWithArray\")\n" +
" @POST(\"user/createWithArray\")\n" +
" fun createUsersWithArrayInput(@Body body: List<User>): Completable\n" +
"\n" +
" /**\n" +
" * Creates list of users with given input array\n" +
" *\n" +
" * @param body List of user object\n" +
" */\n" +
" @POST(\"/user/createWithList\")\n" +
" @POST(\"user/createWithList\")\n" +
" fun createUsersWithListInput(@Body body: List<User>): Completable\n" +
"\n" +
" /**\n" +
Expand All @@ -142,21 +142,21 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param username The user name for login\n" +
" * @param password The password for login in clear text\n" +
" */\n" +
" @GET(\"/user/login\")\n" +
" @GET(\"user/login\")\n" +
" fun loginUser(@Query(\"username\") username: String, @Query(\"password\") password: String): Completable\n" +
"\n" +
" /**\n" +
" * Logs out current logged in user session\n" +
" */\n" +
" @GET(\"/user/logout\")\n" +
" @GET(\"user/logout\")\n" +
" fun logoutUser(): Completable\n" +
"\n" +
" /**\n" +
" * Get user by user name\n" +
" *\n" +
" * @param username The name that needs to be fetched. Use user1 for testing.\n" +
" */\n" +
" @GET(\"/user/{username}\")\n" +
" @GET(\"user/{username}\")\n" +
" fun getUserByName(@Path(\"username\") username: String): Single<User>\n" +
"\n" +
" /**\n" +
Expand All @@ -165,14 +165,14 @@ const val PET_STORE_INTERFACE_MOCK = "package com.mycompany.mylibrary\n" +
" * @param username name that need to be updated\n" +
" * @param body Updated user object\n" +
" */\n" +
" @PUT(\"/user/{username}\")\n" +
" @PUT(\"user/{username}\")\n" +
" fun updateUser(@Path(\"username\") username: String, @Body body: User): Completable\n" +
"\n" +
" /**\n" +
" * Delete user\n" +
" *\n" +
" * @param username The name that needs to be deleted\n" +
" */\n" +
" @DELETE(\"/user/{username}\")\n" +
" @DELETE(\"user/{username}\")\n" +
" fun deleteUser(@Path(\"username\") username: String): Completable\n" +
"}\n"
"}\n"

0 comments on commit 3c19ac4

Please sign in to comment.