Merge pull request #987 from xhh/retrofit-form-field-naming

Retrofit: fix form field naming by using baseName
This commit is contained in:
wing328 2015-07-31 09:09:09 +08:00
commit 92208b4ec2
5 changed files with 47 additions and 47 deletions

View File

@ -22,7 +22,7 @@ public interface {{classname}} {
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}} {{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
@{{httpMethod}}("{{path}}") @{{httpMethod}}("{{path}}")
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{nickname}}({{^allParams}});{{/allParams}} {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{nickname}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{^hasMore}} {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/allParams}} );{{/hasMore}}{{/allParams}}
{{/operation}} {{/operation}}
} }

View File

@ -1 +1 @@
{{#isFormParam}}{{#notFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{paramName}}") TypedFile {{paramName}}{{/isFile}}{{/isFormParam}} {{#isFormParam}}{{#notFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{baseName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}{{#isMultipart}}@Part{{/isMultipart}}{{^isMultipart}}@Field{{/isMultipart}}("{{baseName}}") TypedFile {{paramName}}{{/isFile}}{{/isFormParam}}

View File

@ -10,108 +10,108 @@ import io.swagger.client.model.Pet;
import java.io.File; import java.io.File;
public interface PetApi { public interface PetApi {
/** /**
* Update an existing pet * Update an existing pet
* *
* @param body Pet object that needs to be added to the store * @param body Pet object that needs to be added to the store
* @return Void * @return Void
*/ */
@PUT("/pet") @PUT("/pet")
Void updatePet( Void updatePet(
@Body Pet body @Body Pet body
); );
/** /**
* Add a new pet to the store * Add a new pet to the store
* *
* @param body Pet object that needs to be added to the store * @param body Pet object that needs to be added to the store
* @return Void * @return Void
*/ */
@POST("/pet") @POST("/pet")
Void addPet( Void addPet(
@Body Pet body @Body Pet body
); );
/** /**
* Finds Pets by status * Finds Pets by status
* Multiple status values can be provided with comma seperated strings * Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter * @param status Status values that need to be considered for filter
* @return List<Pet> * @return List<Pet>
*/ */
@GET("/pet/findByStatus") @GET("/pet/findByStatus")
List<Pet> findPetsByStatus( List<Pet> findPetsByStatus(
@Query("status") List<String> status @Query("status") List<String> status
); );
/** /**
* Finds Pets by tags * Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by * @param tags Tags to filter by
* @return List<Pet> * @return List<Pet>
*/ */
@GET("/pet/findByTags") @GET("/pet/findByTags")
List<Pet> findPetsByTags( List<Pet> findPetsByTags(
@Query("tags") List<String> tags @Query("tags") List<String> tags
); );
/** /**
* Find pet by ID * Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions * Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched * @param petId ID of pet that needs to be fetched
* @return Pet * @return Pet
*/ */
@GET("/pet/{petId}") @GET("/pet/{petId}")
Pet getPetById( Pet getPetById(
@Path("petId") Long petId @Path("petId") Long petId
); );
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
* *
* @param petId ID of pet that needs to be updated * @param petId ID of pet that needs to be updated
* @param name Updated name of the pet * @param name Updated name of the pet
* @param status Updated status of the pet * @param status Updated status of the pet
* @return Void * @return Void
*/ */
@FormUrlEncoded @FormUrlEncoded
@POST("/pet/{petId}") @POST("/pet/{petId}")
Void updatePetWithForm( Void updatePetWithForm(
@Path("petId") String petId,@Field("name") String name,@Field("status") String status @Path("petId") String petId, @Field("name") String name, @Field("status") String status
); );
/** /**
* Deletes a pet * Deletes a pet
* *
* @param petId Pet id to delete * @param petId Pet id to delete
* @param apiKey * @param apiKey
* @return Void * @return Void
*/ */
@DELETE("/pet/{petId}") @DELETE("/pet/{petId}")
Void deletePet( Void deletePet(
@Path("petId") Long petId,@Header("api_key") String apiKey @Path("petId") Long petId, @Header("api_key") String apiKey
); );
/** /**
* uploads an image * uploads an image
* *
* @param petId ID of pet to update * @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server * @param additionalMetadata Additional data to pass to server
* @param file file to upload * @param file file to upload
* @return Void * @return Void
*/ */
@Multipart @Multipart
@POST("/pet/{petId}/uploadImage") @POST("/pet/{petId}/uploadImage")
Void uploadFile( Void uploadFile(
@Path("petId") Long petId,@Part("additionalMetadata") String additionalMetadata,@Part("file") TypedFile file @Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file
); );
} }

View File

@ -57,7 +57,7 @@ public interface UserApi {
@GET("/user/login") @GET("/user/login")
String loginUser( String loginUser(
@Query("username") String username,@Query("password") String password @Query("username") String username, @Query("password") String password
); );
/** /**
@ -92,7 +92,7 @@ public interface UserApi {
@PUT("/user/{username}") @PUT("/user/{username}")
Void updateUser( Void updateUser(
@Path("username") String username,@Body User body @Path("username") String username, @Body User body
); );
/** /**

View File

@ -1,8 +1,8 @@
package io.swagger.client.model; package io.swagger.client.model;
import io.swagger.client.model.Category; import io.swagger.client.model.Category;
import java.util.*;
import io.swagger.client.model.Tag; import io.swagger.client.model.Tag;
import java.util.*;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;