Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/java-dropwizard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ To run the sample:
```
mvn package

java -jar target/swagger-java-dropwizard-sample-app-1.0.0-SNAPSHOT.jar server conf/swagger-sample.yml
java -jar target/swagger-java-dropwizard-sample-app-1.0.0.jar server conf/swagger-sample.yml

```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class PetData {
"url1", "url2" }, new String[] { "tag3", "tag4" }, "available"));
}

public Pet getPetbyId(long petId) {
public Pet getPetById(long petId) {
for (Pet pet : pets) {
if (pet.getId() == petId) {
return pet;
Expand All @@ -66,15 +66,17 @@ public Pet getPetbyId(long petId) {
return null;
}

public void deletePet(long petId) {
public boolean deletePet(long petId) {
if(pets.size() > 0) {
for (int i = pets.size() - 1; i >= 0; i--) {
Pet pet = pets.get(i);
if(pet.getId() == petId) {
pets.remove(i);
return true;
}
}
}
return false;
}

public List<Pet> findPetByStatus(String status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class StoreData {
orders.add(createOrder(3, 2, 2, new Date(), "placed"));
orders.add(createOrder(4, 2, 2, new Date(), "delivered"));
orders.add(createOrder(5, 3, 2, new Date(), "placed"));
orders.add(createOrder(11, 3, 2, new Date(), "placed"));
orders.add(createOrder(12, 3, 2, new Date(), "placed"));
orders.add(createOrder(13, 3, 2, new Date(), "placed"));
orders.add(createOrder(14, 3, 2, new Date(), "placed"));
orders.add(createOrder(15, 3, 2, new Date(), "placed"));
orders.add(createOrder(6, 3, 2, new Date(), "placed"));
orders.add(createOrder(7, 3, 2, new Date(), "placed"));
orders.add(createOrder(8, 3, 2, new Date(), "placed"));
orders.add(createOrder(9, 3, 2, new Date(), "placed"));
orders.add(createOrder(10, 3, 2, new Date(), "placed"));
}

public Order findOrderById(long orderId) {
Expand All @@ -59,14 +59,16 @@ public Order placeOrder(Order order) {
return order;
}

public void deleteOrder(long orderId) {
public boolean deleteOrder(long orderId) {
if (orders.size() > 0) {
for (int i = orders.size() - 1; i >= 0; i--) {
if (orders.get(i).getId() == orderId) {
orders.remove(i);
return true;
}
}
}
return false;
}

private static Order createOrder(long id, long petId, int quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ public void addUser(User user) {
users.add(user);
}

public void removeUser(String username) {
public boolean removeUser(String username) {
if (users.size() > 0) {
for (int i = users.size() - 1; i >= 0; i--) {
if (users.get(i).getUsername().equals(username)) {
users.remove(i);
return true;
}
}
}
return false;
}

private static User createUser(long id, String username, String firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@
@Produces({"application/json"})
public class PetResource {
static PetData petData = new PetData();
static JavaRestResourceUtil ru = new JavaRestResourceUtil();

@GET
@Path("/{petId}")
@ApiOperation(
value = "Find pet by ID",
notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions",
notes = "Returns a pet when 0 < ID <= 10. ID > 10 or nonintegers will simulate API error conditions",
response = Pet.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Pet not found") })
public Response getPetById(
@ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("petId") String petId)
@ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,10]", required = true) @PathParam("petId") Long petId)
throws NotFoundException {
Pet pet = petData.getPetbyId(ru.getLong(0, 100000, 0, petId));
Pet pet = petData.getPetById(petId);
if (null != pet) {
return Response.ok().entity(pet).build();
} else {
Expand Down Expand Up @@ -87,7 +86,7 @@ public Response findPetsByStatus(
@Path("/findByTags")
@ApiOperation(
value = "Finds Pets by tags",
notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
response = Pet.class,
responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tag value") })
Expand Down