Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
updated spring samples handling security for client and server to use swagger-annotations 2.1.1
  • Loading branch information
alexsuperdev committed Mar 8, 2020
1 parent 4592a00 commit d31703c
Show file tree
Hide file tree
Showing 76 changed files with 1,462 additions and 936 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public void testMultipartBoot() throws IOException {
// Check that the api handles the array
final String multipartArrayApi = files.get("/src/main/java/org/openapitools/api/MultipartArrayApi.java");
Assert.assertTrue(multipartArrayApi.contains("List<MultipartFile> files"));
Assert.assertTrue(multipartArrayApi.contains("@ApiParam(value = \"Many files\")"));
Assert.assertTrue(multipartArrayApi.contains("@Parameter(description = \"Many files\")"));
Assert.assertTrue(multipartArrayApi.contains("operationId = \"multipartArray\""));
Assert.assertTrue(multipartArrayApi.contains("ApiResponse(responseCode"));
Assert.assertTrue(multipartArrayApi.contains("@RequestPart(value = \"files\")"));

// Check that the delegate handles the single file
Expand All @@ -291,7 +293,7 @@ public void testMultipartBoot() throws IOException {
// Check that the api handles the single file
final String multipartSingleApi = files.get("/src/main/java/org/openapitools/api/MultipartSingleApi.java");
Assert.assertTrue(multipartSingleApi.contains("MultipartFile file"));
Assert.assertTrue(multipartSingleApi.contains("@ApiParam(value = \"One file\")"));
Assert.assertTrue(multipartSingleApi.contains("@Parameter(description = \"One file\")"));
Assert.assertTrue(multipartSingleApi.contains("@RequestPart(value = \"file\")"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.v3.oas.annotations.media.*;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -46,11 +47,15 @@ public interface PetApi {
* @param body Pet object that needs to be added to the store (required)
* @return Invalid input (status code 405)
*/
@Operation(summary = "Add a new pet to the store", description = "",
@Operation(summary = "Add a new pet to the store", operationId = "addPet", description = "",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "405", description = "Invalid input" ) })
@RequestMapping(value = "/pet",
@RequestMapping(value = "/pet",
consumes = "application/json",
method = RequestMethod.POST)
CompletableFuture<ResponseEntity<Void>> addPet(@Parameter(description = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet body);
Expand All @@ -63,11 +68,15 @@ public interface PetApi {
* @param apiKey (optional)
* @return Invalid pet value (status code 400)
*/
@Operation(summary = "Deletes a pet", description = "",
@Operation(summary = "Deletes a pet", operationId = "deletePet", description = "",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "400", description = "Invalid pet value" ) })
@RequestMapping(value = "/pet/{petId}",
@RequestMapping(value = "/pet/{petId}",
method = RequestMethod.DELETE)
CompletableFuture<ResponseEntity<Void>> deletePet(@Parameter(in = ParameterIn.PATH,description = "Pet id to delete", required=true) @PathVariable("petId") Long petId,@Parameter(in = ParameterIn.HEADER, description = "" ) @RequestHeader(value="api_key", required=false) String apiKey);

Expand All @@ -80,12 +89,16 @@ public interface PetApi {
* @return successful operation (status code 200)
* or Invalid status value (status code 400)
*/
@Operation(summary = "Finds Pets by status", description = "Multiple status values can be provided with comma separated strings",
@Operation(summary = "Finds Pets by status", operationId = "findPetsByStatus", description = "Multiple status values can be provided with comma separated strings",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( schema = @Schema(implementation = Pet.class) )} ) ,
@ApiResponse(responseCode = "400", description = "Invalid status value" ) })
@RequestMapping(value = "/pet/findByStatus",
@RequestMapping(value = "/pet/findByStatus",
produces = "application/json",
method = RequestMethod.GET)
CompletableFuture<ResponseEntity<List<Pet>>> findPetsByStatus(@NotNull @Parameter(schema = @Schema(allowableValues = {"available, pending, sold"}, description = "Status values that need to be considered for filter", required = true)) @Valid @RequestParam(value = "status", required = true) List<String> status);
Expand All @@ -100,12 +113,16 @@ public interface PetApi {
* or Invalid tag value (status code 400)
* @deprecated
*/
@Operation(summary = "Finds Pets by tags", description = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
@Operation(summary = "Finds Pets by tags", operationId = "findPetsByTags", description = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( schema = @Schema(implementation = Pet.class) )} ) ,
@ApiResponse(responseCode = "400", description = "Invalid tag value" ) })
@RequestMapping(value = "/pet/findByTags",
@RequestMapping(value = "/pet/findByTags",
produces = "application/json",
method = RequestMethod.GET)
CompletableFuture<ResponseEntity<List<Pet>>> findPetsByTags(@NotNull @Parameter(schema = @Schema( description = "Tags to filter by", required = true)) @Valid @RequestParam(value = "tags", required = true) List<String> tags);
Expand All @@ -120,13 +137,14 @@ public interface PetApi {
* or Invalid ID supplied (status code 400)
* or Pet not found (status code 404)
*/
@Operation(summary = "Find pet by ID", description = "Returns a single pet",
@Operation(summary = "Find pet by ID", operationId = "getPetById", description = "Returns a single pet",
tags={ "pet", },
security = @SecurityRequirement(name = "api_key"),
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( array = @ArraySchema(schema = @Schema(implementation = Pet.class)) )} ) ,
@ApiResponse(responseCode = "400", description = "Invalid ID supplied" ) ,
@ApiResponse(responseCode = "404", description = "Pet not found" ) })
@RequestMapping(value = "/pet/{petId}",
@RequestMapping(value = "/pet/{petId}",
produces = "application/json",
method = RequestMethod.GET)
CompletableFuture<ResponseEntity<Pet>> getPetById(@Parameter(in = ParameterIn.PATH,description = "ID of pet to return", required=true) @PathVariable("petId") Long petId);
Expand All @@ -140,13 +158,17 @@ public interface PetApi {
* or Pet not found (status code 404)
* or Validation exception (status code 405)
*/
@Operation(summary = "Update an existing pet", description = "",
@Operation(summary = "Update an existing pet", operationId = "updatePet", description = "",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "400", description = "Invalid ID supplied" ) ,
@ApiResponse(responseCode = "404", description = "Pet not found" ) ,
@ApiResponse(responseCode = "405", description = "Validation exception" ) })
@RequestMapping(value = "/pet",
@RequestMapping(value = "/pet",
consumes = "application/json",
method = RequestMethod.PUT)
CompletableFuture<ResponseEntity<Void>> updatePet(@Parameter(description = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet body);
Expand All @@ -160,11 +182,15 @@ public interface PetApi {
* @param status Updated status of the pet (optional)
* @return Invalid input (status code 405)
*/
@Operation(summary = "Updates a pet in the store with form data", description = "",
@Operation(summary = "Updates a pet in the store with form data", operationId = "updatePetWithForm", description = "",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "405", description = "Invalid input" ) })
@RequestMapping(value = "/pet/{petId}",
@RequestMapping(value = "/pet/{petId}",
consumes = "application/x-www-form-urlencoded",
method = RequestMethod.POST)
CompletableFuture<ResponseEntity<Void>> updatePetWithForm(@Parameter(in = ParameterIn.PATH,description = "ID of pet that needs to be updated", required=true) @PathVariable("petId") Long petId,@Parameter( description = "Updated name of the pet" ) @RequestParam(value="name", required=false) String name,@Parameter( description = "Updated status of the pet" ) @RequestParam(value="status", required=false) String status);
Expand All @@ -178,11 +204,15 @@ public interface PetApi {
* @param file file to upload (optional)
* @return successful operation (status code 200)
*/
@Operation(summary = "uploads an image", description = "",
@Operation(summary = "uploads an image", operationId = "uploadFile", description = "",
tags={ "pet", },
security = @SecurityRequirement(name = "petstore_auth", scopes = {
"write:pets" ,
"read:pets"
}),
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( array = @ArraySchema(schema = @Schema(implementation = ModelApiResponse.class)) )} ) })
@RequestMapping(value = "/pet/{petId}/uploadImage",
@RequestMapping(value = "/pet/{petId}/uploadImage",
produces = "application/json",
consumes = "multipart/form-data",
method = RequestMethod.POST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.oas.annotations.media.*;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -47,12 +48,12 @@ public interface StoreApi {
* @return Invalid ID supplied (status code 400)
* or Order not found (status code 404)
*/
@Operation(summary = "Delete purchase order by ID", description = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
@Operation(summary = "Delete purchase order by ID", operationId = "deleteOrder", description = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors",
tags={ "store", },
responses = {
@ApiResponse(responseCode = "400", description = "Invalid ID supplied" ) ,
@ApiResponse(responseCode = "404", description = "Order not found" ) })
@RequestMapping(value = "/store/order/{orderId}",
@RequestMapping(value = "/store/order/{orderId}",
method = RequestMethod.DELETE)
CompletableFuture<ResponseEntity<Void>> deleteOrder(@Parameter(in = ParameterIn.PATH,description = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") String orderId);

Expand All @@ -63,11 +64,12 @@ public interface StoreApi {
*
* @return successful operation (status code 200)
*/
@Operation(summary = "Returns pet inventories by status", description = "Returns a map of status codes to quantities",
@Operation(summary = "Returns pet inventories by status", operationId = "getInventory", description = "Returns a map of status codes to quantities",
tags={ "store", },
security = @SecurityRequirement(name = "api_key"),
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( schema = @Schema(implementation = Map.class) )} ) })
@RequestMapping(value = "/store/inventory",
@RequestMapping(value = "/store/inventory",
produces = "application/json",
method = RequestMethod.GET)
CompletableFuture<ResponseEntity<Map<String, Integer>>> getInventory();
Expand All @@ -82,13 +84,13 @@ public interface StoreApi {
* or Invalid ID supplied (status code 400)
* or Order not found (status code 404)
*/
@Operation(summary = "Find purchase order by ID", description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
@Operation(summary = "Find purchase order by ID", operationId = "getOrderById", description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
tags={ "store", },
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( array = @ArraySchema(schema = @Schema(implementation = Order.class)) )} ) ,
@ApiResponse(responseCode = "400", description = "Invalid ID supplied" ) ,
@ApiResponse(responseCode = "404", description = "Order not found" ) })
@RequestMapping(value = "/store/order/{orderId}",
@RequestMapping(value = "/store/order/{orderId}",
produces = "application/json",
method = RequestMethod.GET)
CompletableFuture<ResponseEntity<Order>> getOrderById(@Min(1L) @Max(5L) @Parameter(in = ParameterIn.PATH,description = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") Long orderId);
Expand All @@ -101,12 +103,12 @@ public interface StoreApi {
* @return successful operation (status code 200)
* or Invalid Order (status code 400)
*/
@Operation(summary = "Place an order for a pet", description = "",
@Operation(summary = "Place an order for a pet", operationId = "placeOrder", description = "",
tags={ "store", },
responses = {
@ApiResponse(responseCode = "200", description = "successful operation" , content = { @Content( array = @ArraySchema(schema = @Schema(implementation = Order.class)) )} ) ,
@ApiResponse(responseCode = "400", description = "Invalid Order" ) })
@RequestMapping(value = "/store/order",
@RequestMapping(value = "/store/order",
produces = "application/json",
method = RequestMethod.POST)
CompletableFuture<ResponseEntity<Order>> placeOrder(@Parameter(description = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body);
Expand Down
Loading

0 comments on commit d31703c

Please sign in to comment.