Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.MatrixParam;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
Expand Down Expand Up @@ -67,6 +68,13 @@ public ResolvedParameter extractParameters(List<Annotation> annotations,
pp.setIn(PATH_PARAM);
pp.setName(param.value());
parameter = pp;
} else if (annotation instanceof MatrixParam) {
MatrixParam param = (MatrixParam) annotation;
Parameter pp = new Parameter();
pp.setIn(PATH_PARAM);
pp.setStyle(Parameter.StyleEnum.MATRIX);
pp.setName(param.value());
parameter = pp;
} else if (annotation instanceof HeaderParam) {
HeaderParam param = (HeaderParam) annotation;
Parameter pp = new Parameter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,36 @@ public void testCompletePetResource() throws IOException {
" $ref: '#/components/schemas/Pet'\n" +
" 400:\n" +
" description: Invalid tag value\n" +
" /pet/findByCategory/{category}:\n" +
" get:\n" +
" summary: Finds Pets by category\n" +
" operationId: findPetsByCategory\n" +
" parameters:\n" +
" - name: category\n" +
" in: path\n" +
" description: Category value that need to be considered for filter\n" +
" required: true\n" +
" style: matrix\n" +
" schema:\n" +
" $ref: '#/components/schemas/Category'\n" +
" - name: skip\n" +
" in: query\n" +
" schema:\n" +
" type: integer\n" +
" format: int32\n" +
" - name: limit\n" +
" in: query\n" +
" schema:\n" +
" type: integer\n" +
" format: int32\n" +
" responses:\n" +
" default:\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/Pet'\n" +
" 400:\n" +
" description: Invalid category value\n" +
" /pet/{petId}:\n" +
" get:\n" +
" summary: Find pet by ID\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.swagger.v3.jaxrs2.resources.data.PetData;
import io.swagger.v3.jaxrs2.resources.exception.NotFoundException;
import io.swagger.v3.jaxrs2.resources.model.Category;
import io.swagger.v3.jaxrs2.resources.model.Pet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -28,6 +29,7 @@
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -145,6 +147,25 @@ public Response findPetsByStatus(
return Response.ok(petData.findPetByStatus(status)).build();
}

@GET
@Path("/findByCategory/{category}")
@Produces("application/xml")
@Operation(summary = "Finds Pets by category",
responses = {
@ApiResponse(
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Pet.class))),
@ApiResponse(
responseCode = "400", description = "Invalid category value"
)}
)
public Response findPetsByCategory(
@Parameter(description = "Category value that need to be considered for filter", required = true) @MatrixParam("category") Category category,
@BeanParam QueryResultBean qr
) {
return Response.ok(petData.findPetByCategory(category)).build();
}

@GET
@Path("/findByTags")
@Produces("application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.swagger.v3.jaxrs2.resources.data.PetData;
import io.swagger.v3.jaxrs2.resources.exception.NotFoundException;
import io.swagger.v3.jaxrs2.resources.model.Category;
import io.swagger.v3.jaxrs2.resources.model.Pet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -28,6 +29,7 @@
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -161,4 +163,24 @@ public Response findPetsByTags(
@Parameter(description = "Tags to filter by", required = true/*, allowMultiple = true*/) @QueryParam("tags") String tags) {
return Response.ok(petData.findPetByTags(tags)).build();
}

@GET
@Path("/findByCategory/{category}")
@Produces("application/xml")
@Operation(summary = "Finds Pets by category",
responses = {
@ApiResponse(
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Pet.class))),
@ApiResponse(
responseCode = "400", description = "Invalid category value"
)}
)
public Response findPetsByCategory(
@Parameter(description = "Category value that need to be considered for filter", required = true) @MatrixParam("category") Category category,
@BeanParam QueryResultBean qr
) {
return Response.ok(petData.findPetByCategory(category)).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class PetData {
static List<Pet> pets = new ArrayList<Pet>();
Expand Down Expand Up @@ -80,6 +81,10 @@ public List<Pet> findPetByStatus(String status) {
return result;
}

public List<Pet> findPetByCategory(Category category) {
return pets.stream().filter(pet -> category.equals(pet.getCategory())).collect(Collectors.toList());
}

public List<Pet> findPetByTags(String tags) {
String[] tagList = tags.split(",");
List<Pet> result = new ArrayList<Pet>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

public Category() {
}

public Category(String name) {
this.name = name;
}
}