Retrofit: fix form field naming by using baseName

This commit is contained in:
xhh 2015-07-20 10:12:36 +08:00
parent e879268043
commit a134b5ca76
6 changed files with 10 additions and 10 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

@ -83,20 +83,20 @@ public interface PetApi {
@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 apiKey
* @param petId Pet id to delete * @param petId Pet id to delete
* @param apiKey
* @return Void * @return Void
*/ */
@DELETE("/pet/{petId}") @DELETE("/pet/{petId}")
Void deletePet( Void deletePet(
@Header("api_key") String apiKey,@Path("petId") Long petId @Path("petId") Long petId, @Header("api_key") String apiKey
); );
/** /**
@ -111,7 +111,7 @@ public interface PetApi {
@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;

View File

@ -120,7 +120,7 @@ public class PetApiTest {
api.addPet(pet); api.addPet(pet);
Pet fetched = api.getPetById(pet.getId()); Pet fetched = api.getPetById(pet.getId());
api.deletePet(null, fetched.getId()); api.deletePet(fetched.getId(), null);
try { try {
fetched = api.getPetById(fetched.getId()); fetched = api.getPetById(fetched.getId());