Skip to content

Commit e9cad60

Browse files
committed
fix for #1029, updating pet with form data
1 parent e2cdac4 commit e9cad60

File tree

5 files changed

+54
-157
lines changed

5 files changed

+54
-157
lines changed

samples/java-jaxrs-no-webxml/src/main/java/com/wordnik/swagger/sample/resource/PetResource.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,21 @@ public Response findPetsByTags(
127127
@ApiResponses(value = {
128128
@ApiResponse(code = 405, message = "Invalid input")})
129129
public Response updatePetWithForm (
130-
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") String petId,
130+
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") Long petId,
131131
@ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name,
132132
@ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) {
133133
System.out.println(name);
134134
System.out.println(status);
135-
return Response.ok().entity(new com.wordnik.swagger.sample.model.ApiResponse(200, "SUCCESS")).build();
135+
Pet pet = petData.getPetbyId(petId);
136+
if(pet != null) {
137+
if(name != null && !"".equals(name))
138+
pet.setName(name);
139+
if(status != null && !"".equals(status))
140+
pet.setStatus(status);
141+
petData.addPet(pet);
142+
return Response.ok().build();
143+
}
144+
else
145+
return Response.status(404).build();
136146
}
137-
138-
139-
}
147+
}

samples/java-jaxrs/src/main/java/com/wordnik/swagger/sample/resource/PetResource.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public Response getPetById(
5353
@ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("petId") Long petId)
5454
throws NotFoundException {
5555
Pet pet = petData.getPetbyId(petId);
56-
if (null != pet) {
56+
if (pet != null) {
5757
return Response.ok().entity(pet).build();
5858
} else {
5959
throw new NotFoundException(404, "Pet not found");
@@ -126,14 +126,23 @@ public Response findPetsByTags(
126126
consumes = MediaType.APPLICATION_FORM_URLENCODED)
127127
@ApiResponses(value = {
128128
@ApiResponse(code = 405, message = "Invalid input")})
129-
public Response updatePetWithForm (
130-
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") String petId,
129+
public Response updatePetWithForm (
130+
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") Long petId,
131131
@ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name,
132132
@ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) {
133133
System.out.println(name);
134134
System.out.println(status);
135-
return Response.ok().entity(new com.wordnik.swagger.sample.model.ApiResponse(200, "SUCCESS")).build();
136-
}
137-
138135

136+
Pet pet = petData.getPetbyId(petId);
137+
if(pet != null) {
138+
if(name != null && !"".equals(name))
139+
pet.setName(name);
140+
if(status != null && !"".equals(status))
141+
pet.setStatus(status);
142+
petData.addPet(pet);
143+
return Response.ok().build();
144+
}
145+
else
146+
return Response.status(404).build();
147+
}
139148
}

samples/java-jersey-jaxrs/src/main/java/com/wordnik/swagger/sample/resource/PetResource.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,21 @@ public Response findPetsByTags(
168168
@ApiResponses(value = {
169169
@ApiResponse(code = 405, message = "Invalid input")})
170170
public Response updatePetWithForm (
171-
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") String petId,
171+
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") Long petId,
172172
@ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name,
173173
@ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) {
174174
System.out.println(name);
175175
System.out.println(status);
176-
return Response.ok().entity(new com.wordnik.swagger.sample.model.ApiResponse(200, "SUCCESS")).build();
176+
Pet pet = petData.getPetbyId(petId);
177+
if(pet != null) {
178+
if(name != null && !"".equals(name))
179+
pet.setName(name);
180+
if(status != null && !"".equals(status))
181+
pet.setStatus(status);
182+
petData.addPet(pet);
183+
return Response.ok().build();
184+
}
185+
else
186+
return Response.status(404).build();
177187
}
178188
}

samples/java-mule/src/main/java/com/wordnik/swagger/sample/PetResource.java

Lines changed: 0 additions & 138 deletions
This file was deleted.

samples/java-mule/src/main/java/com/wordnik/swagger/sample/resource/PetResource.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
@Path("/pet")
3131
@Api(value = "/pet", description = "Operations about pets", authorizations = {
32-
@Authorization(value = "petstore_auth"
32+
@Authorization(value = "petstore_auth",
3333
scopes = {
3434
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
3535
@AuthorizationScope(scope = "read:pets", description = "read your pets")
@@ -127,13 +127,21 @@ public Response findPetsByTags(
127127
@ApiResponses(value = {
128128
@ApiResponse(code = 405, message = "Invalid input")})
129129
public Response updatePetWithForm (
130-
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") String petId,
130+
@ApiParam(value = "ID of pet that needs to be updated", required = true)@PathParam("petId") Long petId,
131131
@ApiParam(value = "Updated name of the pet", required = false)@FormParam("name") String name,
132132
@ApiParam(value = "Updated status of the pet", required = false)@FormParam("status") String status) {
133133
System.out.println(name);
134134
System.out.println(status);
135-
return Response.ok().entity(new com.wordnik.swagger.sample.model.ApiResponse(200, "SUCCESS")).build();
135+
Pet pet = petData.getPetbyId(petId);
136+
if(pet != null) {
137+
if(name != null && !"".equals(name))
138+
pet.setName(name);
139+
if(status != null && !"".equals(status))
140+
pet.setStatus(status);
141+
petData.addPet(pet);
142+
return Response.ok().build();
143+
}
144+
else
145+
return Response.status(404).build();
136146
}
137-
138-
139-
}
147+
}

0 commit comments

Comments
 (0)