From d77b721ff39284ff3cb5992465462744942a40f0 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:48:06 +0800 Subject: [PATCH 01/19] fix openapi.yaml: typos, default values, description --- templates/todo/api/common/openapi.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/todo/api/common/openapi.yaml b/templates/todo/api/common/openapi.yaml index b5d1f18cced..f374a45dcaa 100644 --- a/templates/todo/api/common/openapi.yaml +++ b/templates/todo/api/common/openapi.yaml @@ -62,7 +62,7 @@ components: in: path required: true name: itemId - description: The Todo list unique identifier + description: The Todo item unique identifier schema: type: string state: @@ -79,6 +79,7 @@ components: description: The max number of items to returns in a result schema: type: number + default: 20 skip: in: query required: false @@ -86,6 +87,7 @@ components: description: The number of items to skip within the results schema: type: number + default: 0 requestBodies: TodoList: @@ -288,6 +290,7 @@ paths: tags: - Items requestBody: + description: unique identifiers of the Todo items to update content: application/json: schema: From b3f08baeb7c70275bfecbb84bb77b44280e07406 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:50:10 +0800 Subject: [PATCH 02/19] generate separate API interfaces with setting `--additional-properties=useTags=true` --- .../azure/simpletodo/api/ItemsApi.java | 326 ++++++++++++++++ .../azure/simpletodo/api/ListsApi.java | 357 ++---------------- 2 files changed, 360 insertions(+), 323 deletions(-) create mode 100644 templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java new file mode 100644 index 00000000000..e74195c16ec --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java @@ -0,0 +1,326 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.2.1). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package com.microsoft.azure.simpletodo.api; + +import com.microsoft.azure.simpletodo.model.TodoItem; +import com.microsoft.azure.simpletodo.model.TodoState; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.annotation.Generated; +import javax.validation.Valid; +import java.math.BigDecimal; +import java.util.List; +import java.util.Optional; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-11-10T14:15:18.580500200+08:00[Asia/Shanghai]") +@Validated +@Tag(name = "Items", description = "the Items API") +public interface ItemsApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /lists/{listId}/items : Creates a new Todo item within a list + * + * @param listId The Todo list unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 201) + * or Todo list not found (status code 404) + */ + @Operation( + operationId = "createItem", + summary = "Creates a new Todo item within a list", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "201", description = "A Todo item result", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) + }), + @ApiResponse(responseCode = "404", description = "Todo list not found") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/lists/{listId}/items", + produces = {"application/json"}, + consumes = {"application/json"} + ) + default ResponseEntity createItem( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return Todo item deleted successfully (status code 204) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "deleteItemById", + summary = "Deletes a Todo item by unique identifier", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/lists/{listId}/items/{itemId}" + ) + default ResponseEntity deleteItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return A Todo item result (status code 200) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "getItemById", + summary = "Gets a Todo item by unique identifier", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo item result", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) + }), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/lists/{listId}/items/{itemId}", + produces = {"application/json"} + ) + default ResponseEntity getItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /lists/{listId}/items : Gets Todo items within the specified list + * + * @param listId The Todo list unique identifier (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) + * or Todo list not found (status code 404) + */ + @Operation( + operationId = "getItemsByListId", + summary = "Gets Todo items within the specified list", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) + }), + @ApiResponse(responseCode = "404", description = "Todo list not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/lists/{listId}/items", + produces = {"application/json"} + ) + default ResponseEntity> getItemsByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state + * + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "getItemsByListIdAndState", + summary = "Gets a list of Todo items of a specific state", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) + }), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/lists/{listId}/items/state/{state}", + produces = {"application/json"} + ) + default ResponseEntity> getItemsByListIdAndState( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier + * + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 200) + * or Todo item is invalid (status code 400) + * or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "updateItemById", + summary = "Updates a Todo item by unique identifier", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo item result", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) + }), + @ApiResponse(responseCode = "400", description = "Todo item is invalid"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/{itemId}", + produces = {"application/json"}, + consumes = {"application/json"} + ) + default ResponseEntity updateItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items + * + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param requestBody (optional) + * @return Todo items updated (status code 204) + * or Update request is invalid (status code 400) + */ + @Operation( + operationId = "updateItemsStateByListId", + summary = "Changes the state of the specified list items", + tags = {"Items"}, + responses = { + @ApiResponse(responseCode = "204", description = "Todo items updated"), + @ApiResponse(responseCode = "400", description = "Update request is invalid") + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/state/{state}", + consumes = {"application/json"} + ) + default ResponseEntity updateItemsStateByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, + @Parameter(name = "request_body", description = "") @Valid @RequestBody(required = false) List requestBody + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java index dcc1795e412..f1d3e29919e 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java @@ -1,101 +1,54 @@ /** - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.1). + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.2.1). * https://openapi-generator.tech * Do not edit the class manually. */ package com.microsoft.azure.simpletodo.api; -import java.math.BigDecimal; -import java.util.List; -import com.microsoft.azure.simpletodo.model.TodoItem; import com.microsoft.azure.simpletodo.model.TodoList; -import com.microsoft.azure.simpletodo.model.TodoState; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -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; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Generated; import javax.validation.Valid; -import javax.validation.constraints.*; +import java.math.BigDecimal; import java.util.List; -import java.util.Map; import java.util.Optional; -import javax.annotation.Generated; -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-11-10T14:15:18.580500200+08:00[Asia/Shanghai]") @Validated -@Tag(name = "lists", description = "the lists API") +@Tag(name = "Lists", description = "the Lists API") public interface ListsApi { default Optional getRequest() { return Optional.empty(); } - /** - * POST /lists/{listId}/items : Creates a new Todo item within a list - * - * @param listId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 201) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "createItem", - summary = "Creates a new Todo item within a list", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.POST, - value = "/lists/{listId}/items", - produces = { "application/json" }, - consumes = { "application/json" } - ) - default ResponseEntity createItem( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * POST /lists : Creates a new Todo list * * @param todoList The Todo List (optional) * @return A Todo list result (status code 201) - * or Invalid request schema (status code 400) + * or Invalid request schema (status code 400) */ @Operation( operationId = "createList", summary = "Creates a new Todo list", - tags = { "Lists" }, + tags = {"Lists"}, responses = { @ApiResponse(responseCode = "201", description = "A Todo list result", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) @@ -106,14 +59,14 @@ default ResponseEntity createItem( @RequestMapping( method = RequestMethod.POST, value = "/lists", - produces = { "application/json" }, - consumes = { "application/json" } + produces = {"application/json"}, + consumes = {"application/json"} ) default ResponseEntity createList( @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList ) { getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; ApiUtil.setExampleResponse(request, "application/json", exampleString); @@ -126,47 +79,17 @@ default ResponseEntity createList( } - /** - * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @return Todo item deleted successfully (status code 204) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "deleteItemById", - summary = "Deletes a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.DELETE, - value = "/lists/{listId}/items/{itemId}" - ) - default ResponseEntity deleteItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * DELETE /lists/{listId} : Deletes a Todo list by unique identifier * * @param listId The Todo list unique identifier (required) * @return Todo list deleted successfully (status code 204) - * or Todo list not found (status code 404) + * or Todo list not found (status code 404) */ @Operation( operationId = "deleteListById", summary = "Deletes a Todo list by unique identifier", - tags = { "Lists" }, + tags = {"Lists"}, responses = { @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), @ApiResponse(responseCode = "404", description = "Todo list not found") @@ -184,149 +107,17 @@ default ResponseEntity deleteListById( } - /** - * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @return A Todo item result (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemById", - summary = "Gets a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" } - ) - default ResponseEntity getItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists/{listId}/items : Gets Todo items within the specified list - * - * @param listId The Todo list unique identifier (required) - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) - * @return An array of Todo items (status code 200) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "getItemsByListId", - summary = "Gets Todo items within the specified list", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items", - produces = { "application/json" } - ) - default ResponseEntity> getItemsByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) - * @return An array of Todo items (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemsByListIdAndState", - summary = "Gets a list of Todo items of a specific state", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/state/{state}", - produces = { "application/json" } - ) - default ResponseEntity> getItemsByListIdAndState( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * GET /lists/{listId} : Gets a Todo list by unique identifier * * @param listId The Todo list unique identifier (required) * @return A Todo list result (status code 200) - * or Todo list not found (status code 404) + * or Todo list not found (status code 404) */ @Operation( operationId = "getListById", summary = "Gets a Todo list by unique identifier", - tags = { "Lists" }, + tags = {"Lists"}, responses = { @ApiResponse(responseCode = "200", description = "A Todo list result", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) @@ -337,13 +128,13 @@ default ResponseEntity> getItemsByListIdAndState( @RequestMapping( method = RequestMethod.GET, value = "/lists/{listId}", - produces = { "application/json" } + produces = {"application/json"} ) default ResponseEntity getListById( @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId ) { getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; ApiUtil.setExampleResponse(request, "application/json", exampleString); @@ -359,14 +150,14 @@ default ResponseEntity getListById( /** * GET /lists : Gets an array of Todo lists * - * @param top The max number of items to returns in a result (optional) - * @param skip The number of items to skip within the results (optional) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) * @return An array of Todo lists (status code 200) */ @Operation( operationId = "getLists", summary = "Gets an array of Todo lists", - tags = { "Lists" }, + tags = {"Lists"}, responses = { @ApiResponse(responseCode = "200", description = "An array of Todo lists", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) @@ -376,14 +167,14 @@ default ResponseEntity getListById( @RequestMapping( method = RequestMethod.GET, value = "/lists", - produces = { "application/json" } + produces = {"application/json"} ) default ResponseEntity> getLists( - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false) BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false) BigDecimal skip + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip ) { getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; ApiUtil.setExampleResponse(request, "application/json", exampleString); @@ -396,98 +187,18 @@ default ResponseEntity> getLists( } - /** - * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 200) - * or Todo item is invalid (status code 400) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "updateItemById", - summary = "Updates a Todo item by unique identifier", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "400", description = "Todo item is invalid"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" }, - consumes = { "application/json" } - ) - default ResponseEntity updateItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo list unique identifier", required = true) @PathVariable("itemId") String itemId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param requestBody (optional) - * @return Todo items updated (status code 204) - * or Update request is invalid (status code 400) - */ - @Operation( - operationId = "updateItemsStateByListId", - summary = "Changes the state of the specified list items", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "204", description = "Todo items updated"), - @ApiResponse(responseCode = "400", description = "Update request is invalid") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/state/{state}", - consumes = { "application/json" } - ) - default ResponseEntity updateItemsStateByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "request_body", description = "") @Valid @RequestBody(required = false) List requestBody - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** * PUT /lists/{listId} : Updates a Todo list by unique identifier * - * @param listId The Todo list unique identifier (required) + * @param listId The Todo list unique identifier (required) * @param todoList The Todo List (optional) * @return A Todo list result (status code 200) - * or Todo list is invalid (status code 400) + * or Todo list is invalid (status code 400) */ @Operation( operationId = "updateListById", summary = "Updates a Todo list by unique identifier", - tags = { "Lists" }, + tags = {"Lists"}, responses = { @ApiResponse(responseCode = "200", description = "A Todo list result", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) @@ -498,15 +209,15 @@ default ResponseEntity updateItemsStateByListId( @RequestMapping( method = RequestMethod.PUT, value = "/lists/{listId}", - produces = { "application/json" }, - consumes = { "application/json" } + produces = {"application/json"}, + consumes = {"application/json"} ) default ResponseEntity updateListById( @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList ) { getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; ApiUtil.setExampleResponse(request, "application/json", exampleString); From aa6ed7a29cdb5cc88617b5b199bbfdcda76091e0 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:51:54 +0800 Subject: [PATCH 03/19] fix equals/hashCode of model classes and simplify TodoItem and TodoList with `lombok` --- templates/todo/api/java/pom.xml | 17 ++ .../azure/simpletodo/model/TodoItem.java | 265 ++++-------------- .../azure/simpletodo/model/TodoList.java | 135 ++------- 3 files changed, 86 insertions(+), 331 deletions(-) diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index f24a89c9654..a8520a9d909 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -79,6 +79,10 @@ applicationinsights-runtime-attach 3.3.1 + + org.projectlombok + lombok + src/main/java @@ -89,6 +93,19 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 92bc02fff1a..69dd5de5b53 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -1,233 +1,64 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.microsoft.azure.simpletodo.model.TodoState; -import java.time.OffsetDateTime; -import org.springframework.format.annotation.DateTimeFormat; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; - -import java.util.*; import javax.annotation.Generated; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.time.OffsetDateTime; /** * A task that needs to be completed */ - +@Getter +@Setter +@ToString +@EqualsAndHashCode(onlyExplicitlyIncluded = true) @Schema(name = "TodoItem", description = "A task that needs to be completed") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @JsonProperty("id") - private String id; - - @JsonProperty("listId") - private String listId; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - @JsonProperty("state") - private TodoState state; - - @JsonProperty("dueDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime dueDate; - - @JsonProperty("completedDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime completedDate; - - public TodoItem id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TodoItem listId(String listId) { - this.listId = listId; - return this; - } - - /** - * Get listId - * @return listId - */ - @NotNull - @Schema(name = "listId", required = true) - public String getListId() { - return listId; - } - - public void setListId(String listId) { - this.listId = listId; - } - - public TodoItem name(String name) { - this.name = name; - return this; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TodoItem description(String description) { - this.description = description; - return this; - } - - /** - * Get description - * @return description - */ - @NotNull - @Schema(name = "description", required = true) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public TodoItem state(TodoState state) { - this.state = state; - return this; - } - - /** - * Get state - * @return state - */ - @Valid - @Schema(name = "state", required = false) - public TodoState getState() { - return state; - } - - public void setState(TodoState state) { - this.state = state; - } - - public TodoItem dueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - return this; - } - - /** - * Get dueDate - * @return dueDate - */ - @Valid - @Schema(name = "dueDate", required = false) - public OffsetDateTime getDueDate() { - return dueDate; - } - - public void setDueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - } - - public TodoItem completedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - return this; - } - - /** - * Get completedDate - * @return completedDate - */ - @Valid - @Schema(name = "completedDate", required = false) - public OffsetDateTime getCompletedDate() { - return completedDate; - } - - public void setCompletedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TodoItem todoItem = (TodoItem) o; - return Objects.equals(this.id, todoItem.id) && - Objects.equals(this.listId, todoItem.listId) && - Objects.equals(this.name, todoItem.name) && - Objects.equals(this.description, todoItem.description) && - Objects.equals(this.state, todoItem.state) && - Objects.equals(this.dueDate, todoItem.dueDate) && - Objects.equals(this.completedDate, todoItem.completedDate); - } - - @Override - public int hashCode() { - return Objects.hash(id, listId, name, description, state, dueDate, completedDate); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TodoItem {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" listId: ").append(toIndentedString(listId)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append(" state: ").append(toIndentedString(state)).append("\n"); - sb.append(" dueDate: ").append(toIndentedString(dueDate)).append("\n"); - sb.append(" completedDate: ").append(toIndentedString(completedDate)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } + @EqualsAndHashCode.Include + @JsonProperty("id") + @Schema(name = "id", required = false) + private String id; + + @EqualsAndHashCode.Include + @NotNull + @JsonProperty("listId") + @Schema(name = "listId", required = true) + private String listId; + + @NotNull + @JsonProperty("name") + @Schema(name = "name", required = true) + private String name; + + @JsonProperty("description") + @Schema(name = "description", required = true) + private String description; + + @Valid + @JsonProperty("state") + @Schema(name = "state", required = false) + private TodoState state; + + @Valid + @JsonProperty("dueDate") + @Schema(name = "dueDate", required = false) + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime dueDate; + + @Valid + @JsonProperty("completedDate") + @Schema(name = "completedDate", required = false) + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime completedDate; } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index e667387d99b..ae731d136eb 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -1,132 +1,39 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonCreator; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; - -import java.util.*; import javax.annotation.Generated; +import javax.validation.constraints.NotNull; /** - * A list of related Todo items + * A list of related Todo items */ +@Getter +@Setter +@ToString +@EqualsAndHashCode(onlyExplicitlyIncluded = true) @Schema(name = "TodoList", description = " A list of related Todo items") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @JsonProperty("id") - private String id; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - public TodoList id(String id) { - this.id = id; - return this; - } - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public TodoList name(String name) { - this.name = name; - return this; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public TodoList description(String description) { - this.description = description; - return this; - } - - /** - * Get description - * @return description - */ - - @Schema(name = "description", required = false) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TodoList todoList = (TodoList) o; - return Objects.equals(this.id, todoList.id) && - Objects.equals(this.name, todoList.name) && - Objects.equals(this.description, todoList.description); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, description); - } + @EqualsAndHashCode.Include + @Schema(name = "id", required = false) + @JsonProperty("id") + private String id; - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TodoList {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).append("\n"); - sb.append(" description: ").append(toIndentedString(description)).append("\n"); - sb.append("}"); - return sb.toString(); - } + @NotNull + @Schema(name = "name", required = true) + @JsonProperty("name") + private String name; - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } + @Schema(name = "description", required = false) + @JsonProperty("description") + private String description; } From c9b37394e4a7643da99cc4a34b6378db9b34b072 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:52:57 +0800 Subject: [PATCH 04/19] format TodoState --- .../azure/simpletodo/model/TodoState.java | 75 ++++++++----------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java index 773481722e2..3c5e01f0ab7 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java @@ -1,58 +1,47 @@ package com.microsoft.azure.simpletodo.model; -import java.net.URI; -import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; -import org.openapitools.jackson.nullable.JsonNullable; -import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.*; import javax.annotation.Generated; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - /** * Gets or Sets TodoState */ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public enum TodoState { - - TODO("todo"), - - INPROGRESS("inprogress"), - - DONE("done"); - - private String value; - - TodoState(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - @Override - public String toString() { - return String.valueOf(value); - } - - @JsonCreator - public static TodoState fromValue(String value) { - for (TodoState b : TodoState.values()) { - if (b.value.equals(value)) { - return b; - } + + TODO("todo"), + + INPROGRESS("inprogress"), + + DONE("done"); + + private String value; + + TodoState(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static TodoState fromValue(String value) { + for (TodoState b : TodoState.values()) { + if (b.value.equalsIgnoreCase(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); } - throw new IllegalArgumentException("Unexpected value '" + value + "'"); - } } From ee5595e69011e28c37e7eee97bb5d75d48f85d67 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:53:51 +0800 Subject: [PATCH 05/19] spring can not convert string "todo" to enum `TodoState.TODO` without converters. --- .../StringToTodoStateConverter.java | 16 ++++++++++++++++ .../configuration/WebConfiguration.java | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java new file mode 100644 index 00000000000..e2255b744c7 --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +package com.microsoft.azure.simpletodo.configuration; + +import com.microsoft.azure.simpletodo.model.TodoState; +import org.springframework.core.convert.converter.Converter; + +public class StringToTodoStateConverter implements Converter { + @Override + public TodoState convert(String source) { + return TodoState.fromValue(source); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java index 191fa0b6d82..af7acf21d90 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java @@ -2,11 +2,17 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -public class WebConfiguration { +public class WebConfiguration implements WebMvcConfigurer { + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new StringToTodoStateConverter()); + } @Bean public WebMvcConfigurer webConfigurer() { From 995011c59b0c64c34f4144257de29c8ff3791ed5 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:55:42 +0800 Subject: [PATCH 06/19] separate TodoLists/TodoItems Controllers and fix bugs and simplify code. --- .../repository/TodoItemRepository.java | 14 +- .../repository/TodoListRepository.java | 2 + .../simpletodo/web/TodoItemsController.java | 93 ++++++++++ .../simpletodo/web/TodoListsController.java | 160 +++--------------- 4 files changed, 123 insertions(+), 146 deletions(-) create mode 100644 templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java index b32b1320832..dadeca8b8cf 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java @@ -1,17 +1,19 @@ package com.microsoft.azure.simpletodo.repository; -import java.util.List; - +import com.microsoft.azure.simpletodo.model.TodoItem; import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; -import org.springframework.data.mongodb.repository.Query; -import com.microsoft.azure.simpletodo.model.TodoItem; +import java.util.List; +import java.util.Optional; public interface TodoItemRepository extends MongoRepository { - @Query("{ 'listId' : ?0 }") - List findTodoItemsByTodoList(String listId); + TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); + + List findTodoItemsByListId(String listId); + + Optional findTodoItemByListIdAndId(String listId, String id); @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0 } }", diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java index 5b9a7202ebb..90e199a3210 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java @@ -13,4 +13,6 @@ public interface TodoListRepository extends MongoRepository { "{ '$limit': ?1 }", }) List findAll(int skip, int limit); + + TodoList deleteTodoListById(String id); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java new file mode 100644 index 00000000000..9e3d1b3e6bb --- /dev/null +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +package com.microsoft.azure.simpletodo.web; + +import com.microsoft.azure.simpletodo.api.ItemsApi; +import com.microsoft.azure.simpletodo.model.TodoItem; +import com.microsoft.azure.simpletodo.model.TodoList; +import com.microsoft.azure.simpletodo.model.TodoState; +import com.microsoft.azure.simpletodo.repository.TodoItemRepository; +import com.microsoft.azure.simpletodo.repository.TodoListRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import java.math.BigDecimal; +import java.net.URI; +import java.util.List; +import java.util.Optional; +import java.util.stream.StreamSupport; + +@RestController +@RequiredArgsConstructor +public class TodoItemsController implements ItemsApi { + private final TodoListRepository todoListRepository; + private final TodoItemRepository todoItemRepository; + + public ResponseEntity createItem(String listId, TodoItem todoItem) { + final Optional optionalTodoList = todoListRepository.findById(listId); + if (optionalTodoList.isPresent()) { + todoItem.setListId(listId); + final TodoItem savedTodoItem = todoItemRepository.save(todoItem); + final URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoItem.getId()) + .toUri(); + return ResponseEntity.created(location).body(savedTodoItem); + } else { + return ResponseEntity.notFound().build(); + } + } + + public ResponseEntity deleteItemById(String listId, String itemId) { + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) + .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) + .map(i -> ResponseEntity.noContent().build()) + .orElse(ResponseEntity.notFound().build()); + } + + public ResponseEntity getItemById(String listId, String itemId) { + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { + return todoListRepository.findById(listId) + .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { + todoItem.setId(itemId); + todoItem.setListId(listId); + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) + .map(t -> todoItemRepository.save(todoItem)) + .map(ResponseEntity::ok) // return the saved item. + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, BigDecimal skip) { + return todoListRepository.findById(listId) + .map(l -> todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), skip.intValue(), top.intValue())) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { + final List items = Optional.ofNullable(itemIds).filter(ids -> !CollectionUtils.isEmpty(ids)) + .map(ids -> StreamSupport.stream(todoItemRepository.findAllById(ids).spliterator(), false) + .filter(i -> listId.equalsIgnoreCase(i.getListId())).toList()) + .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); + items.forEach(item -> item.setState(state)); + todoItemRepository.saveAll(items); // save items in batch. + return ResponseEntity.noContent().build(); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java index b4f2e10a69b..456488015ce 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java @@ -1,174 +1,54 @@ package com.microsoft.azure.simpletodo.web; import com.microsoft.azure.simpletodo.api.ListsApi; -import com.microsoft.azure.simpletodo.model.TodoItem; import com.microsoft.azure.simpletodo.model.TodoList; -import com.microsoft.azure.simpletodo.model.TodoState; -import com.microsoft.azure.simpletodo.repository.TodoItemRepository; import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.HttpStatus; +import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.net.URI; import java.util.List; -import java.util.Optional; @RestController +@RequiredArgsConstructor public class TodoListsController implements ListsApi { - private final TodoListRepository todoListRepository; - private final TodoItemRepository todoItemRepository; - - public TodoListsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { - this.todoListRepository = todoListRepository; - this.todoItemRepository = todoItemRepository; - } - - @Override - public ResponseEntity createItem(String listId, TodoItem todoItem) { - Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isPresent()) { - todoItem.setListId(listId); - TodoItem savedTodoItem = todoItemRepository.save(todoItem); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoItem.getId()) - .toUri(); - return ResponseEntity.created(location).body(savedTodoItem); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override public ResponseEntity createList(TodoList todoList) { - TodoList savedTodoList = todoListRepository.save(todoList); + final TodoList savedTodoList = todoListRepository.save(todoList); URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoList.getId()) - .toUri(); + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoList.getId()) + .toUri(); return ResponseEntity.created(location).body(savedTodoList); } - @Override - public ResponseEntity deleteItemById(String listId, String itemId) { - Optional todoItem = getTodoItem(listId, itemId); - if (todoItem.isPresent()) { - todoItemRepository.deleteById(itemId); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override public ResponseEntity deleteListById(String listId) { - Optional todoList = todoListRepository.findById(listId); - if (todoList.isPresent()) { - todoListRepository.deleteById(listId); - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity getItemById(String listId, String itemId) { - return getTodoItem(listId, itemId).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); + return todoListRepository.findById(listId) + .map(l -> todoListRepository.deleteTodoListById(l.getId())) + .map(l -> ResponseEntity.noContent().build()) + .orElseGet(() -> ResponseEntity.notFound().build()); } - @Override - public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } - Optional todoList = todoListRepository.findById(listId); - if (todoList.isPresent()) { - return ResponseEntity.ok(todoItemRepository.findTodoItemsByTodoList(listId, skip.intValue(), top.intValue())); - } else { - return ResponseEntity.notFound().build(); - } - } - - @Override - public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } - return ResponseEntity.ok( - todoItemRepository - .findTodoItemsByTodoListAndState(listId, state.name(), skip.intValue(), top.intValue())); - } - - @Override public ResponseEntity getListById(String listId) { - return todoListRepository.findById(listId).map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); + return todoListRepository.findById(listId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); } - @Override public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { - if (top == null) { - top = new BigDecimal(20); - } - if (skip == null) { - skip = new BigDecimal(0); - } return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); } - @Override - public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { - return getTodoItem(listId, itemId).map(t -> { - todoItemRepository.save(todoItem); - return ResponseEntity.ok(todoItem); - }).orElseGet(() -> ResponseEntity.notFound().build()); - } - - @Override - public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List requestBody) { - for (TodoItem todoItem : todoItemRepository.findTodoItemsByTodoList(listId)) { - todoItem.state(state); - todoItemRepository.save(todoItem); - } - return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); - } - - @Override - public ResponseEntity updateListById(String listId, TodoList todoList) { - return todoListRepository - .findById(listId) - .map(t -> ResponseEntity.ok(todoListRepository.save(t))) - .orElseGet(() -> ResponseEntity.badRequest().build()); - } - - private Optional getTodoItem(String listId, String itemId) { - Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isEmpty()) { - return Optional.empty(); - } - Optional optionalTodoItem = todoItemRepository.findById(itemId); - if (optionalTodoItem.isPresent()) { - TodoItem todoItem = optionalTodoItem.get(); - if (todoItem.getListId().equals(listId)) { - return Optional.of(todoItem); - } else { - return Optional.empty(); - } - } else { - return Optional.empty(); - } + public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { + todoList.setId(listId); + return todoListRepository.findById(listId) + .map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) + .orElseGet(() -> ResponseEntity.notFound().build()); } } From 3a89f890dcea07913c027fb8f111e759798c9b22 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 15:56:15 +0800 Subject: [PATCH 07/19] rename package `web` to `controller` --- .../simpletodo/{web => controller}/TodoItemsController.java | 2 +- .../simpletodo/{web => controller}/TodoListsController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/{web => controller}/TodoItemsController.java (98%) rename templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/{web => controller}/TodoListsController.java (97%) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java similarity index 98% rename from templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java rename to templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java index 9e3d1b3e6bb..4ae01a4672e 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoItemsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -package com.microsoft.azure.simpletodo.web; +package com.microsoft.azure.simpletodo.controller; import com.microsoft.azure.simpletodo.api.ItemsApi; import com.microsoft.azure.simpletodo.model.TodoItem; diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java similarity index 97% rename from templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java rename to templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java index 456488015ce..2234f064398 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/web/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -1,4 +1,4 @@ -package com.microsoft.azure.simpletodo.web; +package com.microsoft.azure.simpletodo.controller; import com.microsoft.azure.simpletodo.api.ListsApi; import com.microsoft.azure.simpletodo.model.TodoList; From 6d08a41e64504ee41a6664f88917018b6c81c9da Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 16:16:29 +0800 Subject: [PATCH 08/19] add some comments and refine openapi.yaml --- templates/todo/api/common/openapi.yaml | 2 ++ .../azure/simpletodo/configuration/WebConfiguration.java | 1 + .../azure/simpletodo/controller/TodoItemsController.java | 4 ++++ .../azure/simpletodo/controller/TodoListsController.java | 2 ++ .../java/com/microsoft/azure/simpletodo/model/TodoItem.java | 2 +- .../java/com/microsoft/azure/simpletodo/model/TodoList.java | 4 ++-- .../java/com/microsoft/azure/simpletodo/model/TodoState.java | 2 +- 7 files changed, 13 insertions(+), 4 deletions(-) diff --git a/templates/todo/api/common/openapi.yaml b/templates/todo/api/common/openapi.yaml index f374a45dcaa..0aca8700c0f 100644 --- a/templates/todo/api/common/openapi.yaml +++ b/templates/todo/api/common/openapi.yaml @@ -181,6 +181,8 @@ paths: responses: 200: $ref: "#/components/responses/TodoList" + 404: + description: Todo list not found 400: description: Todo list is invalid delete: diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java index af7acf21d90..347395387d6 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java @@ -11,6 +11,7 @@ public class WebConfiguration implements WebMvcConfigurer { @Override public void addFormatters(FormatterRegistry registry) { + // spring can not convert string "todo" to enum `TodoState.TODO` by itself without this converter. registry.addConverter(new StringToTodoStateConverter()); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java index 4ae01a4672e..e6bcc524a91 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -59,6 +59,7 @@ public ResponseEntity getItemById(String listId, String itemId) { } public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. return todoListRepository.findById(listId) .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) .map(ResponseEntity::ok) @@ -66,6 +67,7 @@ public ResponseEntity> getItemsByListId(String listId, BigDecimal } public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { + // make sure listId and itemId are set into the todoItem, otherwise it will create a new todo item. todoItem.setId(itemId); todoItem.setListId(listId); return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) @@ -75,6 +77,7 @@ public ResponseEntity updateItemById(String listId, String itemId, Tod } public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. return todoListRepository.findById(listId) .map(l -> todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), skip.intValue(), top.intValue())) .map(ResponseEntity::ok) @@ -82,6 +85,7 @@ public ResponseEntity> getItemsByListIdAndState(String listId, To } public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { + // update all items in list with the given state if `itemIds` is not specified. final List items = Optional.ofNullable(itemIds).filter(ids -> !CollectionUtils.isEmpty(ids)) .map(ids -> StreamSupport.stream(todoItemRepository.findAllById(ids).spliterator(), false) .filter(i -> listId.equalsIgnoreCase(i.getListId())).toList()) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java index 2234f064398..b2abb644284 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -42,10 +42,12 @@ public ResponseEntity getListById(String listId) { } public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); } public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { + // make sure listId is set into the todoItem, otherwise it will create a new todo list. todoList.setId(listId); return todoListRepository.findById(listId) .map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 69dd5de5b53..bd7d2cbd4ba 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -24,7 +24,7 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @EqualsAndHashCode.Include + @EqualsAndHashCode.Include // items are equal if they have the same `listId` and `id` @JsonProperty("id") @Schema(name = "id", required = false) private String id; diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index ae731d136eb..00ce000b14a 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -16,13 +16,13 @@ @Getter @Setter -@ToString +@ToString // generate `toString()` @EqualsAndHashCode(onlyExplicitlyIncluded = true) @Schema(name = "TodoList", description = " A list of related Todo items") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @EqualsAndHashCode.Include + @EqualsAndHashCode.Include // lists are equal if they have the same id @Schema(name = "id", required = false) @JsonProperty("id") private String id; diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java index 3c5e01f0ab7..aa1fb16ec31 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java @@ -37,7 +37,7 @@ public String toString() { @JsonCreator public static TodoState fromValue(String value) { for (TodoState b : TodoState.values()) { - if (b.value.equalsIgnoreCase(value)) { + if (b.value.equalsIgnoreCase(value)) { // ignore case return b; } } From 97056a653e21679ab77aa7206a2f85a87b4ea9a7 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Thu, 10 Nov 2022 22:43:35 +0800 Subject: [PATCH 09/19] fix cspell errors. --- .vscode/cspell-templates.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/cspell-templates.txt b/.vscode/cspell-templates.txt index 6d280d7c2af..60830086b0a 100644 --- a/.vscode/cspell-templates.txt +++ b/.vscode/cspell-templates.txt @@ -33,6 +33,7 @@ openapitools OPTARG prestart printenv +projectlombok pycache pytest Quickstart From dd9c679734e2aeb3220cb62af682ab33c44f5404 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 11 Nov 2022 14:08:31 +0800 Subject: [PATCH 10/19] remove dependency on lombok. --- .vscode/cspell-templates.txt | 1 - templates/todo/api/java/pom.xml | 17 ---- .../controller/TodoItemsController.java | 7 +- .../controller/TodoListsController.java | 6 +- .../azure/simpletodo/model/TodoItem.java | 90 ++++++++++++++++--- .../azure/simpletodo/model/TodoList.java | 54 +++++++++-- 6 files changed, 134 insertions(+), 41 deletions(-) diff --git a/.vscode/cspell-templates.txt b/.vscode/cspell-templates.txt index 60830086b0a..6d280d7c2af 100644 --- a/.vscode/cspell-templates.txt +++ b/.vscode/cspell-templates.txt @@ -33,7 +33,6 @@ openapitools OPTARG prestart printenv -projectlombok pycache pytest Quickstart diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index a8520a9d909..f24a89c9654 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -79,10 +79,6 @@ applicationinsights-runtime-attach 3.3.1 - - org.projectlombok - lombok - src/main/java @@ -93,19 +89,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - ${lombok.version} - - - - org.springframework.boot spring-boot-maven-plugin diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java index e6bcc524a91..9aff0750c9a 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -11,7 +11,6 @@ import com.microsoft.azure.simpletodo.model.TodoState; import com.microsoft.azure.simpletodo.repository.TodoItemRepository; import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RestController; @@ -24,11 +23,15 @@ import java.util.stream.StreamSupport; @RestController -@RequiredArgsConstructor public class TodoItemsController implements ItemsApi { private final TodoListRepository todoListRepository; private final TodoItemRepository todoItemRepository; + public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { + this.todoListRepository = todoListRepository; + this.todoItemRepository = todoItemRepository; + } + public ResponseEntity createItem(String listId, TodoItem todoItem) { final Optional optionalTodoList = todoListRepository.findById(listId); if (optionalTodoList.isPresent()) { diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java index b2abb644284..78ae01a86d4 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -3,7 +3,6 @@ import com.microsoft.azure.simpletodo.api.ListsApi; import com.microsoft.azure.simpletodo.model.TodoList; import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -14,10 +13,13 @@ import java.util.List; @RestController -@RequiredArgsConstructor public class TodoListsController implements ListsApi { private final TodoListRepository todoListRepository; + public TodoListsController(TodoListRepository todoListRepository) { + this.todoListRepository = todoListRepository; + } + public ResponseEntity createList(TodoList todoList) { final TodoList savedTodoList = todoListRepository.save(todoList); URI location = ServletUriComponentsBuilder diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index bd7d2cbd4ba..112d3fa5c03 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -2,34 +2,25 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; import javax.annotation.Generated; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.time.OffsetDateTime; +import java.util.Objects; /** * A task that needs to be completed */ -@Getter -@Setter -@ToString -@EqualsAndHashCode(onlyExplicitlyIncluded = true) @Schema(name = "TodoItem", description = "A task that needs to be completed") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @EqualsAndHashCode.Include // items are equal if they have the same `listId` and `id` @JsonProperty("id") @Schema(name = "id", required = false) private String id; - @EqualsAndHashCode.Include @NotNull @JsonProperty("listId") @Schema(name = "listId", required = true) @@ -60,5 +51,84 @@ public class TodoItem { @Schema(name = "completedDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime completedDate; + + public String getId() { + return this.id; + } + + public @NotNull String getListId() { + return this.listId; + } + + public @NotNull String getName() { + return this.name; + } + + public String getDescription() { + return this.description; + } + + public TodoState getState() { + return this.state; + } + + public OffsetDateTime getDueDate() { + return this.dueDate; + } + + public OffsetDateTime getCompletedDate() { + return this.completedDate; + } + + public void setId(String id) { + this.id = id; + } + + public void setListId(@NotNull String listId) { + this.listId = listId; + } + + public void setName(@NotNull String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setState(TodoState state) { + this.state = state; + } + + public void setDueDate(OffsetDateTime dueDate) { + this.dueDate = dueDate; + } + + public void setCompletedDate(OffsetDateTime completedDate) { + this.completedDate = completedDate; + } + + public boolean equals(final Object o) { + // items are equal if they have the same `listId` and `id` + if (o == this) return true; + if (!(o instanceof TodoItem)) return false; + final TodoItem other = (TodoItem) o; + if (!((Object) this instanceof TodoItem)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$listId = this.getListId(); + final Object other$listId = other.getListId(); + if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.listId, this.id); + } + + public String toString() { + return "TodoItem(id=" + this.getId() + ", listId=" + this.getListId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ", state=" + this.getState() + ", dueDate=" + this.getDueDate() + ", completedDate=" + this.getCompletedDate() + ")"; + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index 00ce000b14a..47c286753b4 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -2,27 +2,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; import javax.annotation.Generated; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * A list of related Todo items */ -@Getter -@Setter -@ToString // generate `toString()` -@EqualsAndHashCode(onlyExplicitlyIncluded = true) @Schema(name = "TodoList", description = " A list of related Todo items") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @EqualsAndHashCode.Include // lists are equal if they have the same id @Schema(name = "id", required = false) @JsonProperty("id") private String id; @@ -35,5 +27,49 @@ public class TodoList { @Schema(name = "description", required = false) @JsonProperty("description") private String description; + + public String getId() { + return this.id; + } + + public @NotNull String getName() { + return this.name; + } + + public String getDescription() { + return this.description; + } + + public void setId(String id) { + this.id = id; + } + + public void setName(@NotNull String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof TodoList)) return false; + final TodoList other = (TodoList) o; + if (!((Object) this instanceof TodoList)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + // lists are equal if they have the same id + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.getId()); + } + + public String toString() { + return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ")"; + } } From b8235b2dc6e60650c1d2989c064b6b09d6d3311d Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 11 Nov 2022 14:16:52 +0800 Subject: [PATCH 11/19] move annotations to getters. --- .../azure/simpletodo/model/TodoItem.java | 20 +++++++++---------- .../azure/simpletodo/model/TodoList.java | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 112d3fa5c03..41472c1ddef 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -18,64 +18,64 @@ public class TodoItem { @JsonProperty("id") - @Schema(name = "id", required = false) private String id; @NotNull @JsonProperty("listId") - @Schema(name = "listId", required = true) private String listId; @NotNull @JsonProperty("name") - @Schema(name = "name", required = true) private String name; @JsonProperty("description") - @Schema(name = "description", required = true) private String description; - @Valid @JsonProperty("state") - @Schema(name = "state", required = false) private TodoState state; - @Valid @JsonProperty("dueDate") - @Schema(name = "dueDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime dueDate; - @Valid @JsonProperty("completedDate") - @Schema(name = "completedDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private OffsetDateTime completedDate; + @Schema(name = "id", required = false) public String getId() { return this.id; } + @Schema(name = "listId", required = true) public @NotNull String getListId() { return this.listId; } + @Schema(name = "name", required = true) public @NotNull String getName() { return this.name; } + @Schema(name = "description", required = true) public String getDescription() { return this.description; } + @Valid + @Schema(name = "state", required = false) public TodoState getState() { return this.state; } + @Valid + @Schema(name = "dueDate", required = false) public OffsetDateTime getDueDate() { return this.dueDate; } + @Valid + @Schema(name = "completedDate", required = false) public OffsetDateTime getCompletedDate() { return this.completedDate; } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index 47c286753b4..2289a56e7e3 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -15,27 +15,27 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @Schema(name = "id", required = false) @JsonProperty("id") private String id; @NotNull - @Schema(name = "name", required = true) @JsonProperty("name") private String name; - @Schema(name = "description", required = false) @JsonProperty("description") private String description; + @Schema(name = "id", required = false) public String getId() { return this.id; } + @Schema(name = "name", required = true) public @NotNull String getName() { return this.name; } + @Schema(name = "description", required = false) public String getDescription() { return this.description; } From 7647439d111f5aa960ffbac5350bc749f87befa0 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 18 Nov 2022 13:32:25 +0800 Subject: [PATCH 12/19] add `useTags` setting to generate separate `ListsApi` and `ItemsApi` --- templates/todo/api/java/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index f24a89c9654..1f8277c97e9 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -134,6 +134,7 @@ false true true + true From eeaec7fd44e547f7e7595acb2a66258467e81f4e Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 18 Nov 2022 14:36:32 +0800 Subject: [PATCH 13/19] format sample code with `spring-javaformat` --- .../simpletodo/SimpleTodoApplication.java | 9 +- .../azure/simpletodo/api/ApiUtil.java | 23 +- .../azure/simpletodo/api/ItemsApi.java | 509 ++++++++---------- .../azure/simpletodo/api/ListsApi.java | 349 +++++------- .../configuration/MongoDBConfiguration.java | 47 +- .../configuration/RFC3339DateFormat.java | 51 +- .../StringToTodoStateConverter.java | 10 +- .../configuration/WebConfiguration.java | 33 +- .../controller/TodoItemsController.java | 129 +++-- .../controller/TodoListsController.java | 78 ++- .../azure/simpletodo/model/TodoItem.java | 266 +++++---- .../azure/simpletodo/model/TodoList.java | 133 +++-- .../azure/simpletodo/model/TodoState.java | 50 +- .../repository/TodoItemRepository.java | 23 +- .../repository/TodoListRepository.java | 11 +- 15 files changed, 829 insertions(+), 892 deletions(-) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java index 18f6d0bcfd1..6621a48edd4 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java @@ -8,9 +8,10 @@ @SpringBootApplication public class SimpleTodoApplication { - public static void main(String[] args) { - ApplicationInsights.attach(); + public static void main(String[] args) { + ApplicationInsights.attach(); + + new SpringApplication(SimpleTodoApplication.class).run(args); + } - new SpringApplication(SimpleTodoApplication.class).run(args); - } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java index bcdbd2577c0..2e14019e867 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java @@ -6,14 +6,17 @@ import java.io.IOException; public class ApiUtil { - public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { - try { - HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { + try { + HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java index e74195c16ec..053ca26d017 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java @@ -1,10 +1,12 @@ /** - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.2.1). + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.1). * https://openapi-generator.tech * Do not edit the class manually. */ package com.microsoft.azure.simpletodo.api; +import java.math.BigDecimal; +import java.util.List; import com.microsoft.azure.simpletodo.model.TodoItem; import com.microsoft.azure.simpletodo.model.TodoState; import io.swagger.v3.oas.annotations.Operation; @@ -17,310 +19,251 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; -import javax.annotation.Generated; import javax.validation.Valid; -import java.math.BigDecimal; -import java.util.List; import java.util.Optional; +import javax.annotation.Generated; -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-11-10T14:15:18.580500200+08:00[Asia/Shanghai]") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @Tag(name = "Items", description = "the Items API") public interface ItemsApi { - default Optional getRequest() { - return Optional.empty(); - } - - /** - * POST /lists/{listId}/items : Creates a new Todo item within a list - * - * @param listId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 201) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "createItem", - summary = "Creates a new Todo item within a list", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.POST, - value = "/lists/{listId}/items", - produces = {"application/json"}, - consumes = {"application/json"} - ) - default ResponseEntity createItem( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @return Todo item deleted successfully (status code 204) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "deleteItemById", - summary = "Deletes a Todo item by unique identifier", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.DELETE, - value = "/lists/{listId}/items/{itemId}" - ) - default ResponseEntity deleteItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - + default Optional getRequest() { + return Optional.empty(); + } - /** - * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @return A Todo item result (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemById", - summary = "Gets a Todo item by unique identifier", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/{itemId}", - produces = {"application/json"} - ) - default ResponseEntity getItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * POST /lists/{listId}/items : Creates a new Todo item within a list + * @param listId The Todo list unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 201) or Todo list not found (status code + * 404) + */ + @Operation(operationId = "createItem", summary = "Creates a new Todo item within a list", tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "201", description = "A Todo item result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoItem.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list not found") }) + @RequestMapping(method = RequestMethod.POST, value = "/lists/{listId}/items", produces = { "application/json" }, + consumes = { "application/json" }) + default ResponseEntity createItem( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "TodoItem", + description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } + } + /** + * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return Todo item deleted successfully (status code 204) or Todo list or item not + * found (status code 404) + */ + @Operation(operationId = "deleteItemById", summary = "Deletes a Todo item by unique identifier", tags = { "Items" }, + responses = { @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}/items/{itemId}") + default ResponseEntity deleteItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", + required = true) @PathVariable("itemId") String itemId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - /** - * GET /lists/{listId}/items : Gets Todo items within the specified list - * - * @param listId The Todo list unique identifier (required) - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "getItemsByListId", - summary = "Gets Todo items within the specified list", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items", - produces = {"application/json"} - ) - default ResponseEntity> getItemsByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return A Todo item result (status code 200) or Todo list or item not found (status + * code 404) + */ + @Operation(operationId = "getItemById", summary = "Gets a Todo item by unique identifier", tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo item result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoItem.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/{itemId}", + produces = { "application/json" }) + default ResponseEntity getItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", + required = true) @PathVariable("itemId") String itemId) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - /** - * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "getItemsByListIdAndState", - summary = "Gets a list of Todo items of a specific state", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}/items/state/{state}", - produces = {"application/json"} - ) - default ResponseEntity> getItemsByListIdAndState( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * GET /lists/{listId}/items : Gets Todo items within the specified list + * @param listId The Todo list unique identifier (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) or Todo list not found (status + * code 404) + */ + @Operation(operationId = "getItemsByListId", summary = "Gets Todo items within the specified list", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "200", description = "An array of Todo items", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoItem.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list not found") }) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items", produces = { "application/json" }) + default ResponseEntity> getItemsByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "top", + description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", + required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", + description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", + required = false, defaultValue = "0") BigDecimal skip) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } + } + /** + * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific + * state + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) or Todo list or item not found + * (status code 404) + */ + @Operation(operationId = "getItemsByListIdAndState", summary = "Gets a list of Todo items of a specific state", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "200", description = "An array of Todo items", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoItem.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/state/{state}", + produces = { "application/json" }) + default ResponseEntity> getItemsByListIdAndState( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "state", description = "The Todo item state", + required = true) @PathVariable("state") TodoState state, + @Parameter(name = "top", + description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", + required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", + description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", + required = false, defaultValue = "0") BigDecimal skip) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - /** - * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 200) - * or Todo item is invalid (status code 400) - * or Todo list or item not found (status code 404) - */ - @Operation( - operationId = "updateItemById", - summary = "Updates a Todo item by unique identifier", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) - }), - @ApiResponse(responseCode = "400", description = "Todo item is invalid"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/{itemId}", - produces = {"application/json"}, - consumes = {"application/json"} - ) - default ResponseEntity updateItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable("itemId") String itemId, - @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 200) or Todo item is invalid (status code + * 400) or Todo list or item not found (status code 404) + */ + @Operation(operationId = "updateItemById", summary = "Updates a Todo item by unique identifier", tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo item result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoItem.class)) }), + @ApiResponse(responseCode = "400", description = "Todo item is invalid"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) + @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}/items/{itemId}", + produces = { "application/json" }, consumes = { "application/json" }) + default ResponseEntity updateItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", + required = true) @PathVariable("itemId") String itemId, + @Parameter(name = "TodoItem", + description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - /** - * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items - * - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param requestBody (optional) - * @return Todo items updated (status code 204) - * or Update request is invalid (status code 400) - */ - @Operation( - operationId = "updateItemsStateByListId", - summary = "Changes the state of the specified list items", - tags = {"Items"}, - responses = { - @ApiResponse(responseCode = "204", description = "Todo items updated"), - @ApiResponse(responseCode = "400", description = "Update request is invalid") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}/items/state/{state}", - consumes = {"application/json"} - ) - default ResponseEntity updateItemsStateByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable("state") TodoState state, - @Parameter(name = "request_body", description = "") @Valid @RequestBody(required = false) List requestBody - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list + * items + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param requestBody unique identifiers of the Todo items to update (optional) + * @return Todo items updated (status code 204) or Update request is invalid (status + * code 400) + */ + @Operation(operationId = "updateItemsStateByListId", summary = "Changes the state of the specified list items", + tags = { "Items" }, + responses = { @ApiResponse(responseCode = "204", description = "Todo items updated"), + @ApiResponse(responseCode = "400", description = "Update request is invalid") }) + @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}/items/state/{state}", + consumes = { "application/json" }) + default ResponseEntity updateItemsStateByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "state", description = "The Todo item state", + required = true) @PathVariable("state") TodoState state, + @Parameter(name = "request_body", + description = "unique identifiers of the Todo items to update") @Valid @RequestBody( + required = false) List requestBody) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java index f1d3e29919e..ba08676c321 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java @@ -1,10 +1,11 @@ /** - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.2.1). + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (6.0.1). * https://openapi-generator.tech * Do not edit the class manually. */ package com.microsoft.azure.simpletodo.api; +import java.math.BigDecimal; import com.microsoft.azure.simpletodo.model.TodoList; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -16,217 +17,159 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; -import javax.annotation.Generated; import javax.validation.Valid; -import java.math.BigDecimal; import java.util.List; import java.util.Optional; +import javax.annotation.Generated; -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-11-10T14:15:18.580500200+08:00[Asia/Shanghai]") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @Tag(name = "Lists", description = "the Lists API") public interface ListsApi { - default Optional getRequest() { - return Optional.empty(); - } - - /** - * POST /lists : Creates a new Todo list - * - * @param todoList The Todo List (optional) - * @return A Todo list result (status code 201) - * or Invalid request schema (status code 400) - */ - @Operation( - operationId = "createList", - summary = "Creates a new Todo list", - tags = {"Lists"}, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "400", description = "Invalid request schema") - } - ) - @RequestMapping( - method = RequestMethod.POST, - value = "/lists", - produces = {"application/json"}, - consumes = {"application/json"} - ) - default ResponseEntity createList( - @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * DELETE /lists/{listId} : Deletes a Todo list by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @return Todo list deleted successfully (status code 204) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "deleteListById", - summary = "Deletes a Todo list by unique identifier", - tags = {"Lists"}, - responses = { - @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.DELETE, - value = "/lists/{listId}" - ) - default ResponseEntity deleteListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists/{listId} : Gets a Todo list by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @return A Todo list result (status code 200) - * or Todo list not found (status code 404) - */ - @Operation( - operationId = "getListById", - summary = "Gets a Todo list by unique identifier", - tags = {"Lists"}, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "404", description = "Todo list not found") - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists/{listId}", - produces = {"application/json"} - ) - default ResponseEntity getListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * GET /lists : Gets an array of Todo lists - * - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo lists (status code 200) - */ - @Operation( - operationId = "getLists", - summary = "Gets an array of Todo lists", - tags = {"Lists"}, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo lists", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }) - } - ) - @RequestMapping( - method = RequestMethod.GET, - value = "/lists", - produces = {"application/json"} - ) - default ResponseEntity> getLists( - @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", required = false, defaultValue = "0") BigDecimal skip - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - - /** - * PUT /lists/{listId} : Updates a Todo list by unique identifier - * - * @param listId The Todo list unique identifier (required) - * @param todoList The Todo List (optional) - * @return A Todo list result (status code 200) - * or Todo list is invalid (status code 400) - */ - @Operation( - operationId = "updateListById", - summary = "Updates a Todo list by unique identifier", - tags = {"Lists"}, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) - }), - @ApiResponse(responseCode = "400", description = "Todo list is invalid") - } - ) - @RequestMapping( - method = RequestMethod.PUT, - value = "/lists/{listId}", - produces = {"application/json"}, - consumes = {"application/json"} - ) - default ResponseEntity updateListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /lists : Creates a new Todo list + * @param todoList The Todo List (optional) + * @return A Todo list result (status code 201) or Invalid request schema (status code + * 400) + */ + @Operation(operationId = "createList", summary = "Creates a new Todo list", tags = { "Lists" }, + responses = { + @ApiResponse(responseCode = "201", description = "A Todo list result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoList.class)) }), + @ApiResponse(responseCode = "400", description = "Invalid request schema") }) + @RequestMapping(method = RequestMethod.POST, value = "/lists", produces = { "application/json" }, + consumes = { "application/json" }) + default ResponseEntity createList(@Parameter(name = "TodoList", + description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * DELETE /lists/{listId} : Deletes a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @return Todo list deleted successfully (status code 204) or Todo list not found + * (status code 404) + */ + @Operation(operationId = "deleteListById", summary = "Deletes a Todo list by unique identifier", tags = { "Lists" }, + responses = { @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list not found") }) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}") + default ResponseEntity deleteListById(@Parameter(name = "listId", + description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * GET /lists/{listId} : Gets a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @return A Todo list result (status code 200) or Todo list not found (status code + * 404) + */ + @Operation(operationId = "getListById", summary = "Gets a Todo list by unique identifier", tags = { "Lists" }, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo list result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoList.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list not found") }) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}", produces = { "application/json" }) + default ResponseEntity getListById(@Parameter(name = "listId", + description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * GET /lists : Gets an array of Todo lists + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo lists (status code 200) + */ + @Operation(operationId = "getLists", summary = "Gets an array of Todo lists", tags = { "Lists" }, + responses = { @ApiResponse(responseCode = "200", description = "An array of Todo lists", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoList.class)) }) }) + @RequestMapping(method = RequestMethod.GET, value = "/lists", produces = { "application/json" }) + default ResponseEntity> getLists( + @Parameter(name = "top", + description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", + required = false, defaultValue = "20") BigDecimal top, + @Parameter(name = "skip", + description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", + required = false, defaultValue = "0") BigDecimal skip) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * PUT /lists/{listId} : Updates a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @param todoList The Todo List (optional) + * @return A Todo list result (status code 200) or Todo list not found (status code + * 404) or Todo list is invalid (status code 400) + */ + @Operation(operationId = "updateListById", summary = "Updates a Todo list by unique identifier", tags = { "Lists" }, + responses = { + @ApiResponse(responseCode = "200", description = "A Todo list result", + content = { @Content(mediaType = "application/json", + schema = @Schema(implementation = TodoList.class)) }), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + @ApiResponse(responseCode = "400", description = "Todo list is invalid") }) + @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}", produces = { "application/json" }, + consumes = { "application/json" }) + default ResponseEntity updateListById( + @Parameter(name = "listId", description = "The Todo list unique identifier", + required = true) @PathVariable("listId") String listId, + @Parameter(name = "TodoList", + description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList) { + getRequest().ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java index a47d5eb92fe..20e9d27d738 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java @@ -12,27 +12,28 @@ @Configuration public class MongoDBConfiguration { - @Bean - public MongoCustomConversions mongoCustomConversions() { - return new MongoCustomConversions(Arrays.asList( - new OffsetDateTimeReadConverter(), - new OffsetDateTimeWriteConverter() - )); - } - - static class OffsetDateTimeWriteConverter implements Converter { - - @Override - public Date convert(OffsetDateTime source) { - return Date.from(source.toInstant().atZone(ZoneOffset.UTC).toInstant()); - } - } - - static class OffsetDateTimeReadConverter implements Converter { - - @Override - public OffsetDateTime convert(Date source) { - return source.toInstant().atOffset(ZoneOffset.UTC); - } - } + @Bean + public MongoCustomConversions mongoCustomConversions() { + return new MongoCustomConversions( + Arrays.asList(new OffsetDateTimeReadConverter(), new OffsetDateTimeWriteConverter())); + } + + static class OffsetDateTimeWriteConverter implements Converter { + + @Override + public Date convert(OffsetDateTime source) { + return Date.from(source.toInstant().atZone(ZoneOffset.UTC).toInstant()); + } + + } + + static class OffsetDateTimeReadConverter implements Converter { + + @Override + public OffsetDateTime convert(Date source) { + return source.toInstant().atOffset(ZoneOffset.UTC); + } + + } + } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java index 06754ffab41..a57f2a24539 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java @@ -10,29 +10,30 @@ import java.util.TimeZone; public class RFC3339DateFormat extends DateFormat { - private static final long serialVersionUID = 1L; - private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); - - private final StdDateFormat fmt = new StdDateFormat() - .withTimeZone(TIMEZONE_Z) - .withColonInTimeZone(true); - - public RFC3339DateFormat() { - this.calendar = new GregorianCalendar(); - } - - @Override - public Date parse(String source, ParsePosition pos) { - return fmt.parse(source, pos); - } - - @Override - public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { - return fmt.format(date, toAppendTo, fieldPosition); - } - - @Override - public Object clone() { - return this; - } + + private static final long serialVersionUID = 1L; + + private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); + + private final StdDateFormat fmt = new StdDateFormat().withTimeZone(TIMEZONE_Z).withColonInTimeZone(true); + + public RFC3339DateFormat() { + this.calendar = new GregorianCalendar(); + } + + @Override + public Date parse(String source, ParsePosition pos) { + return fmt.parse(source, pos); + } + + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + return fmt.format(date, toAppendTo, fieldPosition); + } + + @Override + public Object clone() { + return this; + } + } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java index e2255b744c7..7b30dfcc184 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java @@ -9,8 +9,10 @@ import org.springframework.core.convert.converter.Converter; public class StringToTodoStateConverter implements Converter { - @Override - public TodoState convert(String source) { - return TodoState.fromValue(source); - } + + @Override + public TodoState convert(String source) { + return TodoState.fromValue(source); + } + } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java index 347395387d6..344d29761ec 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java @@ -9,23 +9,22 @@ @Configuration public class WebConfiguration implements WebMvcConfigurer { - @Override - public void addFormatters(FormatterRegistry registry) { - // spring can not convert string "todo" to enum `TodoState.TODO` by itself without this converter. - registry.addConverter(new StringToTodoStateConverter()); - } + @Override + public void addFormatters(FormatterRegistry registry) { + // spring can not convert string "todo" to enum `TodoState.TODO` by itself without + // this converter. + registry.addConverter(new StringToTodoStateConverter()); + } - @Bean - public WebMvcConfigurer webConfigurer() { - return new WebMvcConfigurer() { + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*"); + } + }; + } - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOrigins("*") - .allowedMethods("*") - .allowedHeaders("*"); - } - }; - } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java index 9aff0750c9a..96c339e60ba 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -24,77 +24,76 @@ @RestController public class TodoItemsController implements ItemsApi { - private final TodoListRepository todoListRepository; - private final TodoItemRepository todoItemRepository; - public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { - this.todoListRepository = todoListRepository; - this.todoItemRepository = todoItemRepository; - } + private final TodoListRepository todoListRepository; - public ResponseEntity createItem(String listId, TodoItem todoItem) { - final Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isPresent()) { - todoItem.setListId(listId); - final TodoItem savedTodoItem = todoItemRepository.save(todoItem); - final URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoItem.getId()) - .toUri(); - return ResponseEntity.created(location).body(savedTodoItem); - } else { - return ResponseEntity.notFound().build(); - } - } + private final TodoItemRepository todoItemRepository; - public ResponseEntity deleteItemById(String listId, String itemId) { - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) - .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) - .map(i -> ResponseEntity.noContent().build()) - .orElse(ResponseEntity.notFound().build()); - } + public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { + this.todoListRepository = todoListRepository; + this.todoItemRepository = todoItemRepository; + } - public ResponseEntity getItemById(String listId, String itemId) { - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity createItem(String listId, TodoItem todoItem) { + final Optional optionalTodoList = todoListRepository.findById(listId); + if (optionalTodoList.isPresent()) { + todoItem.setListId(listId); + final TodoItem savedTodoItem = todoItemRepository.save(todoItem); + final URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") + .buildAndExpand(savedTodoItem.getId()).toUri(); + return ResponseEntity.created(location).body(savedTodoItem); + } + else { + return ResponseEntity.notFound().build(); + } + } - public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return todoListRepository.findById(listId) - .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity deleteItemById(String listId, String itemId) { + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) + .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) + .map(i -> ResponseEntity.noContent().build()).orElse(ResponseEntity.notFound().build()); + } - public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { - // make sure listId and itemId are set into the todoItem, otherwise it will create a new todo item. - todoItem.setId(itemId); - todoItem.setListId(listId); - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) - .map(t -> todoItemRepository.save(todoItem)) - .map(ResponseEntity::ok) // return the saved item. - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity getItemById(String listId, String itemId) { + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId).map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } - public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return todoListRepository.findById(listId) - .map(l -> todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), skip.intValue(), top.intValue())) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository.findById(listId) + .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) + .map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { + // make sure listId and itemId are set into the todoItem, otherwise it will create + // a new todo item. + todoItem.setId(itemId); + todoItem.setListId(listId); + return todoItemRepository.findTodoItemByListIdAndId(listId, itemId).map(t -> todoItemRepository.save(todoItem)) + .map(ResponseEntity::ok) // return the saved item. + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, + BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository + .findById(listId).map(l -> todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), + skip.intValue(), top.intValue())) + .map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { + // update all items in list with the given state if `itemIds` is not specified. + final List items = Optional.ofNullable(itemIds).filter(ids -> !CollectionUtils.isEmpty(ids)) + .map(ids -> StreamSupport.stream(todoItemRepository.findAllById(ids).spliterator(), false) + .filter(i -> listId.equalsIgnoreCase(i.getListId())).toList()) + .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); + items.forEach(item -> item.setState(state)); + todoItemRepository.saveAll(items); // save items in batch. + return ResponseEntity.noContent().build(); + } - public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { - // update all items in list with the given state if `itemIds` is not specified. - final List items = Optional.ofNullable(itemIds).filter(ids -> !CollectionUtils.isEmpty(ids)) - .map(ids -> StreamSupport.stream(todoItemRepository.findAllById(ids).spliterator(), false) - .filter(i -> listId.equalsIgnoreCase(i.getListId())).toList()) - .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); - items.forEach(item -> item.setState(state)); - todoItemRepository.saveAll(items); // save items in batch. - return ResponseEntity.noContent().build(); - } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java index 78ae01a86d4..31a7f98dddc 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -14,45 +14,41 @@ @RestController public class TodoListsController implements ListsApi { - private final TodoListRepository todoListRepository; - - public TodoListsController(TodoListRepository todoListRepository) { - this.todoListRepository = todoListRepository; - } - - public ResponseEntity createList(TodoList todoList) { - final TodoList savedTodoList = todoListRepository.save(todoList); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest() - .path("/{id}") - .buildAndExpand(savedTodoList.getId()) - .toUri(); - return ResponseEntity.created(location).body(savedTodoList); - } - - public ResponseEntity deleteListById(String listId) { - return todoListRepository.findById(listId) - .map(l -> todoListRepository.deleteTodoListById(l.getId())) - .map(l -> ResponseEntity.noContent().build()) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - - public ResponseEntity getListById(String listId) { - return todoListRepository.findById(listId) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - - public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); - } - - public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { - // make sure listId is set into the todoItem, otherwise it will create a new todo list. - todoList.setId(listId); - return todoListRepository.findById(listId) - .map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) - .orElseGet(() -> ResponseEntity.notFound().build()); - } + + private final TodoListRepository todoListRepository; + + public TodoListsController(TodoListRepository todoListRepository) { + this.todoListRepository = todoListRepository; + } + + public ResponseEntity createList(TodoList todoList) { + final TodoList savedTodoList = todoListRepository.save(todoList); + URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") + .buildAndExpand(savedTodoList.getId()).toUri(); + return ResponseEntity.created(location).body(savedTodoList); + } + + public ResponseEntity deleteListById(String listId) { + return todoListRepository.findById(listId).map(l -> todoListRepository.deleteTodoListById(l.getId())) + .map(l -> ResponseEntity.noContent().build()).orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity getListById(String listId) { + return todoListRepository.findById(listId).map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); + } + + public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { + // make sure listId is set into the todoItem, otherwise it will create a new todo + // list. + todoList.setId(listId); + return todoListRepository.findById(listId).map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 41472c1ddef..85d35adfbe3 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -13,122 +13,160 @@ /** * A task that needs to be completed */ + @Schema(name = "TodoItem", description = "A task that needs to be completed") @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @JsonProperty("id") - private String id; - - @NotNull - @JsonProperty("listId") - private String listId; - - @NotNull - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - @JsonProperty("state") - private TodoState state; - - @JsonProperty("dueDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime dueDate; - - @JsonProperty("completedDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime completedDate; - - @Schema(name = "id", required = false) - public String getId() { - return this.id; - } - - @Schema(name = "listId", required = true) - public @NotNull String getListId() { - return this.listId; - } - - @Schema(name = "name", required = true) - public @NotNull String getName() { - return this.name; - } - - @Schema(name = "description", required = true) - public String getDescription() { - return this.description; - } - - @Valid - @Schema(name = "state", required = false) - public TodoState getState() { - return this.state; - } - - @Valid - @Schema(name = "dueDate", required = false) - public OffsetDateTime getDueDate() { - return this.dueDate; - } - - @Valid - @Schema(name = "completedDate", required = false) - public OffsetDateTime getCompletedDate() { - return this.completedDate; - } - - public void setId(String id) { - this.id = id; - } - - public void setListId(@NotNull String listId) { - this.listId = listId; - } - - public void setName(@NotNull String name) { - this.name = name; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setState(TodoState state) { - this.state = state; - } - - public void setDueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - } - - public void setCompletedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - } - - public boolean equals(final Object o) { - // items are equal if they have the same `listId` and `id` - if (o == this) return true; - if (!(o instanceof TodoItem)) return false; - final TodoItem other = (TodoItem) o; - if (!((Object) this instanceof TodoItem)) return false; - final Object this$id = this.getId(); - final Object other$id = other.getId(); - if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; - final Object this$listId = this.getListId(); - final Object other$listId = other.getListId(); - if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) return false; - return true; - } - - public int hashCode() { - return Objects.hash(this.listId, this.id); - } - - public String toString() { - return "TodoItem(id=" + this.getId() + ", listId=" + this.getListId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ", state=" + this.getState() + ", dueDate=" + this.getDueDate() + ", completedDate=" + this.getCompletedDate() + ")"; - } -} + @JsonProperty("id") + private String id; + + @JsonProperty("listId") + private String listId; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("state") + private TodoState state; + + @JsonProperty("dueDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime dueDate; + + @JsonProperty("completedDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime completedDate; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get listId + * @return listId + */ + @NotNull + @Schema(name = "listId", required = true) + public String getListId() { + return listId; + } + + public void setListId(String listId) { + this.listId = listId; + } + + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + @NotNull + @Schema(name = "description", required = true) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * Get state + * @return state + */ + @Valid + @Schema(name = "state", required = false) + public TodoState getState() { + return state; + } + + public void setState(TodoState state) { + this.state = state; + } + + /** + * Get dueDate + * @return dueDate + */ + @Valid + @Schema(name = "dueDate", required = false) + public OffsetDateTime getDueDate() { + return dueDate; + } + + public void setDueDate(OffsetDateTime dueDate) { + this.dueDate = dueDate; + } + + /** + * Get completedDate + * @return completedDate + */ + @Valid + @Schema(name = "completedDate", required = false) + public OffsetDateTime getCompletedDate() { + return completedDate; + } + + public void setCompletedDate(OffsetDateTime completedDate) { + this.completedDate = completedDate; + } + + public boolean equals(final Object o) { + // items are equal if they have the same `listId` and `id` + if (o == this) + return true; + if (!(o instanceof TodoItem)) + return false; + final TodoItem other = (TodoItem) o; + if (!((Object) this instanceof TodoItem)) + return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + final Object this$listId = this.getListId(); + final Object other$listId = other.getListId(); + if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) + return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.listId, this.id); + } + + public String toString() { + return "TodoItem(id=" + this.getId() + ", listId=" + this.getListId() + ", name=" + this.getName() + + ", description=" + this.getDescription() + ", state=" + this.getState() + ", dueDate=" + + this.getDueDate() + ", completedDate=" + this.getCompletedDate() + ")"; + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index 2289a56e7e3..561345c5479 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -15,61 +15,80 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @JsonProperty("id") - private String id; - - @NotNull - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - @Schema(name = "id", required = false) - public String getId() { - return this.id; - } - - @Schema(name = "name", required = true) - public @NotNull String getName() { - return this.name; - } - - @Schema(name = "description", required = false) - public String getDescription() { - return this.description; - } - - public void setId(String id) { - this.id = id; - } - - public void setName(@NotNull String name) { - this.name = name; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof TodoList)) return false; - final TodoList other = (TodoList) o; - if (!((Object) this instanceof TodoList)) return false; - final Object this$id = this.getId(); - final Object other$id = other.getId(); - // lists are equal if they have the same id - if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; - return true; - } - - public int hashCode() { - return Objects.hash(this.getId()); - } - - public String toString() { - return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ")"; - } -} + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + + @Schema(name = "description", required = false) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean equals(final Object o) { + if (o == this) + return true; + if (!(o instanceof TodoList)) + return false; + final TodoList other = (TodoList) o; + if (!((Object) this instanceof TodoList)) + return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + // lists are equal if they have the same id + if (this$id == null ? other$id != null : !this$id.equals(other$id)) + return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.getId()); + } + + public String toString() { + return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() + + ")"; + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java index aa1fb16ec31..11b62fb1e89 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java @@ -12,36 +12,36 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public enum TodoState { - TODO("todo"), + TODO("todo"), - INPROGRESS("inprogress"), + INPROGRESS("inprogress"), - DONE("done"); + DONE("done"); - private String value; + private String value; - TodoState(String value) { - this.value = value; - } + TodoState(String value) { + this.value = value; + } - @JsonValue - public String getValue() { - return value; - } + @JsonValue + public String getValue() { + return value; + } - @Override - public String toString() { - return String.valueOf(value); - } + @Override + public String toString() { + return String.valueOf(value); + } - @JsonCreator - public static TodoState fromValue(String value) { - for (TodoState b : TodoState.values()) { - if (b.value.equalsIgnoreCase(value)) { // ignore case - return b; - } - } - throw new IllegalArgumentException("Unexpected value '" + value + "'"); - } -} + @JsonCreator + public static TodoState fromValue(String value) { + for (TodoState b : TodoState.values()) { + if (b.value.equalsIgnoreCase(value)) { // ignore case + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java index dadeca8b8cf..db1c08e0ad2 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java @@ -9,23 +9,16 @@ public interface TodoItemRepository extends MongoRepository { - TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); + TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); - List findTodoItemsByListId(String listId); + List findTodoItemsByListId(String listId); - Optional findTodoItemByListIdAndId(String listId, String id); + Optional findTodoItemByListIdAndId(String listId, String id); - @Aggregation(pipeline = { - "{ '$match': { 'listId' : ?0 } }", - "{ '$skip': ?1 }", - "{ '$limit': ?2 }", - }) - List findTodoItemsByTodoList(String listId, int skip, int limit); + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0 } }", "{ '$skip': ?1 }", "{ '$limit': ?2 }", }) + List findTodoItemsByTodoList(String listId, int skip, int limit); + + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", "{ '$skip': ?2 }", "{ '$limit': ?3 }", }) + List findTodoItemsByTodoListAndState(String listId, String state, int skip, int limit); - @Aggregation(pipeline = { - "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", - "{ '$skip': ?2 }", - "{ '$limit': ?3 }", - }) - List findTodoItemsByTodoListAndState(String listId, String state, int skip, int limit); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java index 90e199a3210..5759c68ad3b 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java @@ -8,11 +8,10 @@ import org.springframework.data.mongodb.repository.MongoRepository; public interface TodoListRepository extends MongoRepository { - @Aggregation(pipeline = { - "{ '$skip': ?0 }", - "{ '$limit': ?1 }", - }) - List findAll(int skip, int limit); - TodoList deleteTodoListById(String id); + @Aggregation(pipeline = { "{ '$skip': ?0 }", "{ '$limit': ?1 }", }) + List findAll(int skip, int limit); + + TodoList deleteTodoListById(String id); + } From ce21ce43d988f22c73c12e8569e17e1afcab01f3 Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 18 Nov 2022 14:53:43 +0800 Subject: [PATCH 14/19] format OpenAPI generated code with `spring-javaformat` to avoid huge diff. --- templates/todo/api/java/pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index 1f8277c97e9..545c368be65 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -140,6 +140,18 @@ + + io.spring.javaformat + spring-javaformat-maven-plugin + 0.0.35 + + + + apply + + + + From c6fdca1817f3cc4e48a46465445bc86b6eca1cae Mon Sep 17 00:00:00 2001 From: Mingliang Wang Date: Fri, 18 Nov 2022 15:02:13 +0800 Subject: [PATCH 15/19] fix cspell error. --- .vscode/cspell-templates.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/cspell-templates.txt b/.vscode/cspell-templates.txt index 6d280d7c2af..bb030d0d927 100644 --- a/.vscode/cspell-templates.txt +++ b/.vscode/cspell-templates.txt @@ -24,6 +24,7 @@ immer inprogress INPROGRESS Instrumentor +javaformat mkdir mvnw networkidle From 35a96b40631eda2601f9932c60696a5f5481fd89 Mon Sep 17 00:00:00 2001 From: Wei Lim Date: Fri, 18 Nov 2022 13:20:19 -0800 Subject: [PATCH 16/19] Use prettier-java for formatting --- templates/todo/api/java/package-lock.json | 116 ++++++++++++++++++++++ templates/todo/api/java/package.json | 5 + templates/todo/api/java/pom.xml | 34 ++++++- 3 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 templates/todo/api/java/package-lock.json create mode 100644 templates/todo/api/java/package.json diff --git a/templates/todo/api/java/package-lock.json b/templates/todo/api/java/package-lock.json new file mode 100644 index 00000000000..d09fa5f415e --- /dev/null +++ b/templates/todo/api/java/package-lock.json @@ -0,0 +1,116 @@ +{ + "name": "java", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "prettier-plugin-java": "^1.6.2" + } + }, + "node_modules/chevrotain": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-6.5.0.tgz", + "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", + "dev": true, + "dependencies": { + "regexp-to-ast": "0.4.0" + } + }, + "node_modules/java-parser": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/java-parser/-/java-parser-2.0.2.tgz", + "integrity": "sha512-fwv1eDYE4OIAN+XS7cD8aB7UdQyAh3Uz36ydWqemvnDKXEdLbxq7qIbvsjpSvS1NHFR+r81N7AjGcpnamjVxJw==", + "dev": true, + "dependencies": { + "chevrotain": "6.5.0", + "lodash": "4.17.21" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, + "node_modules/prettier": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.1.tgz", + "integrity": "sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/prettier-plugin-java": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-java/-/prettier-plugin-java-1.6.2.tgz", + "integrity": "sha512-oVIUOkx50eb9skdRtEIU7MJUsizQ1ZocgXR1w1o8AnieNGpuPI/2pWnpjtbBm9wUG1dHtBGU8cVIr8h+xgzQIg==", + "dev": true, + "dependencies": { + "java-parser": "2.0.2", + "lodash": "4.17.21", + "prettier": "2.3.1" + } + }, + "node_modules/regexp-to-ast": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", + "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", + "dev": true + } + }, + "dependencies": { + "chevrotain": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-6.5.0.tgz", + "integrity": "sha512-BwqQ/AgmKJ8jcMEjaSnfMybnKMgGTrtDKowfTP3pX4jwVy0kNjRsT/AP6h+wC3+3NC+X8X15VWBnTCQlX+wQFg==", + "dev": true, + "requires": { + "regexp-to-ast": "0.4.0" + } + }, + "java-parser": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/java-parser/-/java-parser-2.0.2.tgz", + "integrity": "sha512-fwv1eDYE4OIAN+XS7cD8aB7UdQyAh3Uz36ydWqemvnDKXEdLbxq7qIbvsjpSvS1NHFR+r81N7AjGcpnamjVxJw==", + "dev": true, + "requires": { + "chevrotain": "6.5.0", + "lodash": "4.17.21" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true + }, + "prettier": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.1.tgz", + "integrity": "sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==", + "dev": true + }, + "prettier-plugin-java": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/prettier-plugin-java/-/prettier-plugin-java-1.6.2.tgz", + "integrity": "sha512-oVIUOkx50eb9skdRtEIU7MJUsizQ1ZocgXR1w1o8AnieNGpuPI/2pWnpjtbBm9wUG1dHtBGU8cVIr8h+xgzQIg==", + "dev": true, + "requires": { + "java-parser": "2.0.2", + "lodash": "4.17.21", + "prettier": "2.3.1" + } + }, + "regexp-to-ast": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/regexp-to-ast/-/regexp-to-ast-0.4.0.tgz", + "integrity": "sha512-4qf/7IsIKfSNHQXSwial1IFmfM1Cc/whNBQqRwe0V2stPe7KmN1U0tWQiIx6JiirgSrisjE0eECdNf7Tav1Ntw==", + "dev": true + } + } +} diff --git a/templates/todo/api/java/package.json b/templates/todo/api/java/package.json new file mode 100644 index 00000000000..b1607b07643 --- /dev/null +++ b/templates/todo/api/java/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "prettier-plugin-java": "^1.6.2" + } +} diff --git a/templates/todo/api/java/pom.xml b/templates/todo/api/java/pom.xml index 545c368be65..b9047ab1ce0 100644 --- a/templates/todo/api/java/pom.xml +++ b/templates/todo/api/java/pom.xml @@ -18,6 +18,11 @@ ${java.version} ${java.version} 1.6.11 + + write @@ -105,6 +110,27 @@ + + com.hubspot.maven.plugins + prettier-maven-plugin + 0.16 + + 1.5.0 + 125 + 4 + false + true + true + + + + validate + + ${plugin.prettier.goal} + + + + @@ -141,13 +167,13 @@ - io.spring.javaformat - spring-javaformat-maven-plugin - 0.0.35 + com.hubspot.maven.plugins + prettier-maven-plugin + compile - apply + ${plugin.prettier.goal} From b60c57e563aee7a681a8f5d2856c1dc438ec034a Mon Sep 17 00:00:00 2001 From: Wei Lim Date: Fri, 18 Nov 2022 13:20:30 -0800 Subject: [PATCH 17/19] Reformat existing --- .../simpletodo/SimpleTodoApplication.java | 12 +- .../azure/simpletodo/api/ApiUtil.java | 27 +- .../azure/simpletodo/api/ItemsApi.java | 553 ++++++++++-------- .../azure/simpletodo/api/ListsApi.java | 340 ++++++----- .../configuration/MongoDBConfiguration.java | 46 +- .../configuration/RFC3339DateFormat.java | 38 +- .../StringToTodoStateConverter.java | 9 +- .../configuration/WebConfiguration.java | 32 +- .../controller/TodoItemsController.java | 155 ++--- .../controller/TodoListsController.java | 90 +-- .../azure/simpletodo/model/TodoItem.java | 317 +++++----- .../azure/simpletodo/model/TodoList.java | 149 +++-- .../azure/simpletodo/model/TodoState.java | 51 +- .../repository/TodoItemRepository.java | 21 +- .../repository/TodoListRepository.java | 10 +- .../SimpleTodoApplicationTests.java | 6 +- 16 files changed, 998 insertions(+), 858 deletions(-) diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java index 6621a48edd4..1549d3d3049 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/SimpleTodoApplication.java @@ -1,17 +1,15 @@ package com.microsoft.azure.simpletodo; +import com.microsoft.applicationinsights.attach.ApplicationInsights; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.microsoft.applicationinsights.attach.ApplicationInsights; - @SpringBootApplication public class SimpleTodoApplication { - public static void main(String[] args) { - ApplicationInsights.attach(); - - new SpringApplication(SimpleTodoApplication.class).run(args); - } + public static void main(String[] args) { + ApplicationInsights.attach(); + new SpringApplication(SimpleTodoApplication.class).run(args); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java index 2e14019e867..cbcc964b124 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java @@ -1,22 +1,19 @@ package com.microsoft.azure.simpletodo.api; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import org.springframework.web.context.request.NativeWebRequest; public class ApiUtil { - public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { - try { - HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); - res.setCharacterEncoding("UTF-8"); - res.addHeader("Content-Type", contentType); - res.getWriter().print(example); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { + try { + HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java index 053ca26d017..3e32726959f 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java @@ -5,8 +5,6 @@ */ package com.microsoft.azure.simpletodo.api; -import java.math.BigDecimal; -import java.util.List; import com.microsoft.azure.simpletodo.model.TodoItem; import com.microsoft.azure.simpletodo.model.TodoState; import io.swagger.v3.oas.annotations.Operation; @@ -15,6 +13,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import java.math.BigDecimal; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import javax.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -22,248 +25,328 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; -import javax.validation.Valid; -import java.util.Optional; -import javax.annotation.Generated; - @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @Tag(name = "Items", description = "the Items API") public interface ItemsApi { + default Optional getRequest() { + return Optional.empty(); + } - default Optional getRequest() { - return Optional.empty(); - } - - /** - * POST /lists/{listId}/items : Creates a new Todo item within a list - * @param listId The Todo list unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 201) or Todo list not found (status code - * 404) - */ - @Operation(operationId = "createItem", summary = "Creates a new Todo item within a list", tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo item result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoItem.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list not found") }) - @RequestMapping(method = RequestMethod.POST, value = "/lists/{listId}/items", produces = { "application/json" }, - consumes = { "application/json" }) - default ResponseEntity createItem( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoItem", - description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @return Todo item deleted successfully (status code 204) or Todo list or item not - * found (status code 404) - */ - @Operation(operationId = "deleteItemById", summary = "Deletes a Todo item by unique identifier", tags = { "Items" }, - responses = { @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) - @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}/items/{itemId}") - default ResponseEntity deleteItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", - required = true) @PathVariable("itemId") String itemId) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @return A Todo item result (status code 200) or Todo list or item not found (status - * code 404) - */ - @Operation(operationId = "getItemById", summary = "Gets a Todo item by unique identifier", tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoItem.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) - @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" }) - default ResponseEntity getItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", - required = true) @PathVariable("itemId") String itemId) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * GET /lists/{listId}/items : Gets Todo items within the specified list - * @param listId The Todo list unique identifier (required) - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) or Todo list not found (status - * code 404) - */ - @Operation(operationId = "getItemsByListId", summary = "Gets Todo items within the specified list", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoItem.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list not found") }) - @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items", produces = { "application/json" }) - default ResponseEntity> getItemsByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "top", - description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", - required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", - description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", - required = false, defaultValue = "0") BigDecimal skip) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific - * state - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) or Todo list or item not found - * (status code 404) - */ - @Operation(operationId = "getItemsByListIdAndState", summary = "Gets a list of Todo items of a specific state", - tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "An array of Todo items", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoItem.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) - @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/state/{state}", - produces = { "application/json" }) - default ResponseEntity> getItemsByListIdAndState( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", - required = true) @PathVariable("state") TodoState state, - @Parameter(name = "top", - description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", - required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", - description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", - required = false, defaultValue = "0") BigDecimal skip) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * POST /lists/{listId}/items : Creates a new Todo item within a list + * @param listId The Todo list unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 201) or Todo list not found (status code + * 404) + */ + @Operation( + operationId = "createItem", + summary = "Creates a new Todo item within a list", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "201", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/lists/{listId}/items", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity createItem( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return Todo item deleted successfully (status code 204) or Todo list or item not + * found (status code 404) + */ + @Operation( + operationId = "deleteItemById", + summary = "Deletes a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "204", description = "Todo item deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}/items/{itemId}") + default ResponseEntity deleteItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - /** - * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier - * @param listId The Todo list unique identifier (required) - * @param itemId The Todo item unique identifier (required) - * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 200) or Todo item is invalid (status code - * 400) or Todo list or item not found (status code 404) - */ - @Operation(operationId = "updateItemById", summary = "Updates a Todo item by unique identifier", tags = { "Items" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo item result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoItem.class)) }), - @ApiResponse(responseCode = "400", description = "Todo item is invalid"), - @ApiResponse(responseCode = "404", description = "Todo list or item not found") }) - @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}/items/{itemId}", - produces = { "application/json" }, consumes = { "application/json" }) - default ResponseEntity updateItemById( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "itemId", description = "The Todo item unique identifier", - required = true) @PathVariable("itemId") String itemId, - @Parameter(name = "TodoItem", - description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @return A Todo item result (status code 200) or Todo list or item not found (status + * code 404) + */ + @Operation( + operationId = "getItemById", + summary = "Gets a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items/{itemId}", produces = { "application/json" }) + default ResponseEntity getItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * GET /lists/{listId}/items : Gets Todo items within the specified list + * @param listId The Todo list unique identifier (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) or Todo list not found (status + * code 404) + */ + @Operation( + operationId = "getItemsByListId", + summary = "Gets Todo items within the specified list", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "An array of Todo items", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}/items", produces = { "application/json" }) + default ResponseEntity> getItemsByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - /** - * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list - * items - * @param listId The Todo list unique identifier (required) - * @param state The Todo item state (required) - * @param requestBody unique identifiers of the Todo items to update (optional) - * @return Todo items updated (status code 204) or Update request is invalid (status - * code 400) - */ - @Operation(operationId = "updateItemsStateByListId", summary = "Changes the state of the specified list items", - tags = { "Items" }, - responses = { @ApiResponse(responseCode = "204", description = "Todo items updated"), - @ApiResponse(responseCode = "400", description = "Update request is invalid") }) - @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}/items/state/{state}", - consumes = { "application/json" }) - default ResponseEntity updateItemsStateByListId( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "state", description = "The Todo item state", - required = true) @PathVariable("state") TodoState state, - @Parameter(name = "request_body", - description = "unique identifiers of the Todo items to update") @Valid @RequestBody( - required = false) List requestBody) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific + * state + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo items (status code 200) or Todo list or item not found + * (status code 404) + */ + @Operation( + operationId = "getItemsByListIdAndState", + summary = "Gets a list of Todo items of a specific state", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "An array of Todo items", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/lists/{listId}/items/state/{state}", + produces = { "application/json" } + ) + default ResponseEntity> getItemsByListIdAndState( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable( + "state" + ) TodoState state, + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier + * @param listId The Todo list unique identifier (required) + * @param itemId The Todo item unique identifier (required) + * @param todoItem The Todo Item (optional) + * @return A Todo item result (status code 200) or Todo item is invalid (status code + * 400) or Todo list or item not found (status code 404) + */ + @Operation( + operationId = "updateItemById", + summary = "Updates a Todo item by unique identifier", + tags = { "Items" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo item result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoItem.class)) } + ), + @ApiResponse(responseCode = "400", description = "Todo item is invalid"), + @ApiResponse(responseCode = "404", description = "Todo list or item not found"), + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/{itemId}", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity updateItemById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "itemId", description = "The Todo item unique identifier", required = true) @PathVariable( + "itemId" + ) String itemId, + @Parameter(name = "TodoItem", description = "The Todo Item") @Valid @RequestBody(required = false) TodoItem todoItem + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = + "{ \"listId\" : \"listId\", \"dueDate\" : \"2000-01-23T04:56:07.000+00:00\", \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\", \"completedDate\" : \"2000-01-23T04:56:07.000+00:00\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list + * items + * @param listId The Todo list unique identifier (required) + * @param state The Todo item state (required) + * @param requestBody unique identifiers of the Todo items to update (optional) + * @return Todo items updated (status code 204) or Update request is invalid (status + * code 400) + */ + @Operation( + operationId = "updateItemsStateByListId", + summary = "Changes the state of the specified list items", + tags = { "Items" }, + responses = { + @ApiResponse(responseCode = "204", description = "Todo items updated"), + @ApiResponse(responseCode = "400", description = "Update request is invalid"), + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}/items/state/{state}", + consumes = { "application/json" } + ) + default ResponseEntity updateItemsStateByListId( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "state", description = "The Todo item state", required = true) @PathVariable( + "state" + ) TodoState state, + @Parameter( + name = "request_body", + description = "unique identifiers of the Todo items to update" + ) @Valid @RequestBody(required = false) List requestBody + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java index ba08676c321..323ca2d6b92 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java @@ -5,7 +5,6 @@ */ package com.microsoft.azure.simpletodo.api; -import java.math.BigDecimal; import com.microsoft.azure.simpletodo.model.TodoList; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -13,6 +12,11 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import java.math.BigDecimal; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import javax.validation.Valid; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -20,156 +24,204 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; -import javax.validation.Valid; -import java.util.List; -import java.util.Optional; -import javax.annotation.Generated; - @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @Tag(name = "Lists", description = "the Lists API") public interface ListsApi { + default Optional getRequest() { + return Optional.empty(); + } - default Optional getRequest() { - return Optional.empty(); - } - - /** - * POST /lists : Creates a new Todo list - * @param todoList The Todo List (optional) - * @return A Todo list result (status code 201) or Invalid request schema (status code - * 400) - */ - @Operation(operationId = "createList", summary = "Creates a new Todo list", tags = { "Lists" }, - responses = { - @ApiResponse(responseCode = "201", description = "A Todo list result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoList.class)) }), - @ApiResponse(responseCode = "400", description = "Invalid request schema") }) - @RequestMapping(method = RequestMethod.POST, value = "/lists", produces = { "application/json" }, - consumes = { "application/json" }) - default ResponseEntity createList(@Parameter(name = "TodoList", - description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * DELETE /lists/{listId} : Deletes a Todo list by unique identifier - * @param listId The Todo list unique identifier (required) - * @return Todo list deleted successfully (status code 204) or Todo list not found - * (status code 404) - */ - @Operation(operationId = "deleteListById", summary = "Deletes a Todo list by unique identifier", tags = { "Lists" }, - responses = { @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), - @ApiResponse(responseCode = "404", description = "Todo list not found") }) - @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}") - default ResponseEntity deleteListById(@Parameter(name = "listId", - description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * GET /lists/{listId} : Gets a Todo list by unique identifier - * @param listId The Todo list unique identifier (required) - * @return A Todo list result (status code 200) or Todo list not found (status code - * 404) - */ - @Operation(operationId = "getListById", summary = "Gets a Todo list by unique identifier", tags = { "Lists" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoList.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list not found") }) - @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}", produces = { "application/json" }) - default ResponseEntity getListById(@Parameter(name = "listId", - description = "The Todo list unique identifier", required = true) @PathVariable("listId") String listId) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } - - /** - * GET /lists : Gets an array of Todo lists - * @param top The max number of items to returns in a result (optional, default to 20) - * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo lists (status code 200) - */ - @Operation(operationId = "getLists", summary = "Gets an array of Todo lists", tags = { "Lists" }, - responses = { @ApiResponse(responseCode = "200", description = "An array of Todo lists", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoList.class)) }) }) - @RequestMapping(method = RequestMethod.GET, value = "/lists", produces = { "application/json" }) - default ResponseEntity> getLists( - @Parameter(name = "top", - description = "The max number of items to returns in a result") @Valid @RequestParam(value = "top", - required = false, defaultValue = "20") BigDecimal top, - @Parameter(name = "skip", - description = "The number of items to skip within the results") @Valid @RequestParam(value = "skip", - required = false, defaultValue = "0") BigDecimal skip) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * POST /lists : Creates a new Todo list + * @param todoList The Todo List (optional) + * @return A Todo list result (status code 201) or Invalid request schema (status code + * 400) + */ + @Operation( + operationId = "createList", + summary = "Creates a new Todo list", + tags = { "Lists" }, + responses = { + @ApiResponse( + responseCode = "201", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "400", description = "Invalid request schema"), + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/lists", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity createList( + @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * DELETE /lists/{listId} : Deletes a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @return Todo list deleted successfully (status code 204) or Todo list not found + * (status code 404) + */ + @Operation( + operationId = "deleteListById", + summary = "Deletes a Todo list by unique identifier", + tags = { "Lists" }, + responses = { + @ApiResponse(responseCode = "204", description = "Todo list deleted successfully"), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping(method = RequestMethod.DELETE, value = "/lists/{listId}") + default ResponseEntity deleteListById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - /** - * PUT /lists/{listId} : Updates a Todo list by unique identifier - * @param listId The Todo list unique identifier (required) - * @param todoList The Todo List (optional) - * @return A Todo list result (status code 200) or Todo list not found (status code - * 404) or Todo list is invalid (status code 400) - */ - @Operation(operationId = "updateListById", summary = "Updates a Todo list by unique identifier", tags = { "Lists" }, - responses = { - @ApiResponse(responseCode = "200", description = "A Todo list result", - content = { @Content(mediaType = "application/json", - schema = @Schema(implementation = TodoList.class)) }), - @ApiResponse(responseCode = "404", description = "Todo list not found"), - @ApiResponse(responseCode = "400", description = "Todo list is invalid") }) - @RequestMapping(method = RequestMethod.PUT, value = "/lists/{listId}", produces = { "application/json" }, - consumes = { "application/json" }) - default ResponseEntity updateListById( - @Parameter(name = "listId", description = "The Todo list unique identifier", - required = true) @PathVariable("listId") String listId, - @Parameter(name = "TodoList", - description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList) { - getRequest().ifPresent(request -> { - for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + /** + * GET /lists/{listId} : Gets a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @return A Todo list result (status code 200) or Todo list not found (status code + * 404) + */ + @Operation( + operationId = "getListById", + summary = "Gets a Todo list by unique identifier", + tags = { "Lists" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists/{listId}", produces = { "application/json" }) + default ResponseEntity getListById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } - } + /** + * GET /lists : Gets an array of Todo lists + * @param top The max number of items to returns in a result (optional, default to 20) + * @param skip The number of items to skip within the results (optional, default to 0) + * @return An array of Todo lists (status code 200) + */ + @Operation( + operationId = "getLists", + summary = "Gets an array of Todo lists", + tags = { "Lists" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "An array of Todo lists", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + } + ) + @RequestMapping(method = RequestMethod.GET, value = "/lists", produces = { "application/json" }) + default ResponseEntity> getLists( + @Parameter(name = "top", description = "The max number of items to returns in a result") @Valid @RequestParam( + value = "top", + required = false, + defaultValue = "20" + ) BigDecimal top, + @Parameter(name = "skip", description = "The number of items to skip within the results") @Valid @RequestParam( + value = "skip", + required = false, + defaultValue = "0" + ) BigDecimal skip + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + /** + * PUT /lists/{listId} : Updates a Todo list by unique identifier + * @param listId The Todo list unique identifier (required) + * @param todoList The Todo List (optional) + * @return A Todo list result (status code 200) or Todo list not found (status code + * 404) or Todo list is invalid (status code 400) + */ + @Operation( + operationId = "updateListById", + summary = "Updates a Todo list by unique identifier", + tags = { "Lists" }, + responses = { + @ApiResponse( + responseCode = "200", + description = "A Todo list result", + content = { @Content(mediaType = "application/json", schema = @Schema(implementation = TodoList.class)) } + ), + @ApiResponse(responseCode = "404", description = "Todo list not found"), + @ApiResponse(responseCode = "400", description = "Todo list is invalid"), + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/lists/{listId}", + produces = { "application/json" }, + consumes = { "application/json" } + ) + default ResponseEntity updateListById( + @Parameter(name = "listId", description = "The Todo list unique identifier", required = true) @PathVariable( + "listId" + ) String listId, + @Parameter(name = "TodoList", description = "The Todo List") @Valid @RequestBody(required = false) TodoList todoList + ) { + getRequest() + .ifPresent(request -> { + for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"name\" : \"name\", \"description\" : \"description\", \"id\" : \"id\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java index 20e9d27d738..2932eb3c1f0 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/MongoDBConfiguration.java @@ -12,28 +12,26 @@ @Configuration public class MongoDBConfiguration { - @Bean - public MongoCustomConversions mongoCustomConversions() { - return new MongoCustomConversions( - Arrays.asList(new OffsetDateTimeReadConverter(), new OffsetDateTimeWriteConverter())); - } - - static class OffsetDateTimeWriteConverter implements Converter { - - @Override - public Date convert(OffsetDateTime source) { - return Date.from(source.toInstant().atZone(ZoneOffset.UTC).toInstant()); - } - - } - - static class OffsetDateTimeReadConverter implements Converter { - - @Override - public OffsetDateTime convert(Date source) { - return source.toInstant().atOffset(ZoneOffset.UTC); - } - - } - + @Bean + public MongoCustomConversions mongoCustomConversions() { + return new MongoCustomConversions( + Arrays.asList(new OffsetDateTimeReadConverter(), new OffsetDateTimeWriteConverter()) + ); + } + + static class OffsetDateTimeWriteConverter implements Converter { + + @Override + public Date convert(OffsetDateTime source) { + return Date.from(source.toInstant().atZone(ZoneOffset.UTC).toInstant()); + } + } + + static class OffsetDateTimeReadConverter implements Converter { + + @Override + public OffsetDateTime convert(Date source) { + return source.toInstant().atOffset(ZoneOffset.UTC); + } + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java index a57f2a24539..49d09b27ea1 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/RFC3339DateFormat.java @@ -1,7 +1,6 @@ package com.microsoft.azure.simpletodo.configuration; import com.fasterxml.jackson.databind.util.StdDateFormat; - import java.text.DateFormat; import java.text.FieldPosition; import java.text.ParsePosition; @@ -11,29 +10,28 @@ public class RFC3339DateFormat extends DateFormat { - private static final long serialVersionUID = 1L; - - private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); + private static final long serialVersionUID = 1L; - private final StdDateFormat fmt = new StdDateFormat().withTimeZone(TIMEZONE_Z).withColonInTimeZone(true); + private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); - public RFC3339DateFormat() { - this.calendar = new GregorianCalendar(); - } + private final StdDateFormat fmt = new StdDateFormat().withTimeZone(TIMEZONE_Z).withColonInTimeZone(true); - @Override - public Date parse(String source, ParsePosition pos) { - return fmt.parse(source, pos); - } + public RFC3339DateFormat() { + this.calendar = new GregorianCalendar(); + } - @Override - public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { - return fmt.format(date, toAppendTo, fieldPosition); - } + @Override + public Date parse(String source, ParsePosition pos) { + return fmt.parse(source, pos); + } - @Override - public Object clone() { - return this; - } + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + return fmt.format(date, toAppendTo, fieldPosition); + } + @Override + public Object clone() { + return this; + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java index 7b30dfcc184..4a521df9604 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/StringToTodoStateConverter.java @@ -10,9 +10,8 @@ public class StringToTodoStateConverter implements Converter { - @Override - public TodoState convert(String source) { - return TodoState.fromValue(source); - } - + @Override + public TodoState convert(String source) { + return TodoState.fromValue(source); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java index 344d29761ec..855a4c38e09 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/configuration/WebConfiguration.java @@ -9,22 +9,20 @@ @Configuration public class WebConfiguration implements WebMvcConfigurer { - @Override - public void addFormatters(FormatterRegistry registry) { - // spring can not convert string "todo" to enum `TodoState.TODO` by itself without - // this converter. - registry.addConverter(new StringToTodoStateConverter()); - } - - @Bean - public WebMvcConfigurer webConfigurer() { - return new WebMvcConfigurer() { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*"); - } - }; - } + @Override + public void addFormatters(FormatterRegistry registry) { + // spring can not convert string "todo" to enum `TodoState.TODO` by itself without + // this converter. + registry.addConverter(new StringToTodoStateConverter()); + } + @Bean + public WebMvcConfigurer webConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*"); + } + }; + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java index 96c339e60ba..028cb92f71d 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoItemsController.java @@ -11,89 +11,110 @@ import com.microsoft.azure.simpletodo.model.TodoState; import com.microsoft.azure.simpletodo.repository.TodoItemRepository; import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import org.springframework.http.ResponseEntity; -import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - import java.math.BigDecimal; import java.net.URI; import java.util.List; import java.util.Optional; import java.util.stream.StreamSupport; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @RestController public class TodoItemsController implements ItemsApi { - private final TodoListRepository todoListRepository; - - private final TodoItemRepository todoItemRepository; + private final TodoListRepository todoListRepository; - public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { - this.todoListRepository = todoListRepository; - this.todoItemRepository = todoItemRepository; - } + private final TodoItemRepository todoItemRepository; - public ResponseEntity createItem(String listId, TodoItem todoItem) { - final Optional optionalTodoList = todoListRepository.findById(listId); - if (optionalTodoList.isPresent()) { - todoItem.setListId(listId); - final TodoItem savedTodoItem = todoItemRepository.save(todoItem); - final URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") - .buildAndExpand(savedTodoItem.getId()).toUri(); - return ResponseEntity.created(location).body(savedTodoItem); - } - else { - return ResponseEntity.notFound().build(); - } - } + public TodoItemsController(TodoListRepository todoListRepository, TodoItemRepository todoItemRepository) { + this.todoListRepository = todoListRepository; + this.todoItemRepository = todoItemRepository; + } - public ResponseEntity deleteItemById(String listId, String itemId) { - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId) - .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) - .map(i -> ResponseEntity.noContent().build()).orElse(ResponseEntity.notFound().build()); - } + public ResponseEntity createItem(String listId, TodoItem todoItem) { + final Optional optionalTodoList = todoListRepository.findById(listId); + if (optionalTodoList.isPresent()) { + todoItem.setListId(listId); + final TodoItem savedTodoItem = todoItemRepository.save(todoItem); + final URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoItem.getId()) + .toUri(); + return ResponseEntity.created(location).body(savedTodoItem); + } else { + return ResponseEntity.notFound().build(); + } + } - public ResponseEntity getItemById(String listId, String itemId) { - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId).map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity deleteItemById(String listId, String itemId) { + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(i -> todoItemRepository.deleteTodoItemByListIdAndId(i.getListId(), i.getId())) + .map(i -> ResponseEntity.noContent().build()) + .orElse(ResponseEntity.notFound().build()); + } - public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return todoListRepository.findById(listId) - .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) - .map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity getItemById(String listId, String itemId) { + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } - public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { - // make sure listId and itemId are set into the todoItem, otherwise it will create - // a new todo item. - todoItem.setId(itemId); - todoItem.setListId(listId); - return todoItemRepository.findTodoItemByListIdAndId(listId, itemId).map(t -> todoItemRepository.save(todoItem)) - .map(ResponseEntity::ok) // return the saved item. - .orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity> getItemsByListId(String listId, BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository + .findById(listId) + .map(l -> todoItemRepository.findTodoItemsByTodoList(l.getId(), skip.intValue(), top.intValue())) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } - public ResponseEntity> getItemsByListIdAndState(String listId, TodoState state, BigDecimal top, - BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return todoListRepository - .findById(listId).map(l -> todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), - skip.intValue(), top.intValue())) - .map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); - } + public ResponseEntity updateItemById(String listId, String itemId, TodoItem todoItem) { + // make sure listId and itemId are set into the todoItem, otherwise it will create + // a new todo item. + todoItem.setId(itemId); + todoItem.setListId(listId); + return todoItemRepository + .findTodoItemByListIdAndId(listId, itemId) + .map(t -> todoItemRepository.save(todoItem)) + .map(ResponseEntity::ok) // return the saved item. + .orElseGet(() -> ResponseEntity.notFound().build()); + } - public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { - // update all items in list with the given state if `itemIds` is not specified. - final List items = Optional.ofNullable(itemIds).filter(ids -> !CollectionUtils.isEmpty(ids)) - .map(ids -> StreamSupport.stream(todoItemRepository.findAllById(ids).spliterator(), false) - .filter(i -> listId.equalsIgnoreCase(i.getListId())).toList()) - .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); - items.forEach(item -> item.setState(state)); - todoItemRepository.saveAll(items); // save items in batch. - return ResponseEntity.noContent().build(); - } + public ResponseEntity> getItemsByListIdAndState( + String listId, + TodoState state, + BigDecimal top, + BigDecimal skip + ) { + // no need to check nullity of top and skip, because they have default values. + return todoListRepository + .findById(listId) + .map(l -> + todoItemRepository.findTodoItemsByTodoListAndState(l.getId(), state.name(), skip.intValue(), top.intValue()) + ) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + public ResponseEntity updateItemsStateByListId(String listId, TodoState state, List itemIds) { + // update all items in list with the given state if `itemIds` is not specified. + final List items = Optional + .ofNullable(itemIds) + .filter(ids -> !CollectionUtils.isEmpty(ids)) + .map(ids -> + StreamSupport + .stream(todoItemRepository.findAllById(ids).spliterator(), false) + .filter(i -> listId.equalsIgnoreCase(i.getListId())) + .toList() + ) + .orElseGet(() -> todoItemRepository.findTodoItemsByListId(listId)); + items.forEach(item -> item.setState(state)); + todoItemRepository.saveAll(items); // save items in batch. + return ResponseEntity.noContent().build(); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java index 31a7f98dddc..1a5c661721e 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/controller/TodoListsController.java @@ -3,52 +3,60 @@ import com.microsoft.azure.simpletodo.api.ListsApi; import com.microsoft.azure.simpletodo.model.TodoList; import com.microsoft.azure.simpletodo.repository.TodoListRepository; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -import javax.validation.constraints.NotNull; import java.math.BigDecimal; import java.net.URI; import java.util.List; +import javax.validation.constraints.NotNull; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @RestController public class TodoListsController implements ListsApi { - private final TodoListRepository todoListRepository; - - public TodoListsController(TodoListRepository todoListRepository) { - this.todoListRepository = todoListRepository; - } - - public ResponseEntity createList(TodoList todoList) { - final TodoList savedTodoList = todoListRepository.save(todoList); - URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") - .buildAndExpand(savedTodoList.getId()).toUri(); - return ResponseEntity.created(location).body(savedTodoList); - } - - public ResponseEntity deleteListById(String listId) { - return todoListRepository.findById(listId).map(l -> todoListRepository.deleteTodoListById(l.getId())) - .map(l -> ResponseEntity.noContent().build()).orElseGet(() -> ResponseEntity.notFound().build()); - } - - public ResponseEntity getListById(String listId) { - return todoListRepository.findById(listId).map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - - public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { - // no need to check nullity of top and skip, because they have default values. - return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); - } - - public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { - // make sure listId is set into the todoItem, otherwise it will create a new todo - // list. - todoList.setId(listId); - return todoListRepository.findById(listId).map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - + private final TodoListRepository todoListRepository; + + public TodoListsController(TodoListRepository todoListRepository) { + this.todoListRepository = todoListRepository; + } + + public ResponseEntity createList(TodoList todoList) { + final TodoList savedTodoList = todoListRepository.save(todoList); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path("/{id}") + .buildAndExpand(savedTodoList.getId()) + .toUri(); + return ResponseEntity.created(location).body(savedTodoList); + } + + public ResponseEntity deleteListById(String listId) { + return todoListRepository + .findById(listId) + .map(l -> todoListRepository.deleteTodoListById(l.getId())) + .map(l -> ResponseEntity.noContent().build()) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity getListById(String listId) { + return todoListRepository + .findById(listId) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + + public ResponseEntity> getLists(BigDecimal top, BigDecimal skip) { + // no need to check nullity of top and skip, because they have default values. + return ResponseEntity.ok(todoListRepository.findAll(skip.intValue(), top.intValue())); + } + + public ResponseEntity updateListById(String listId, @NotNull TodoList todoList) { + // make sure listId is set into the todoItem, otherwise it will create a new todo + // list. + todoList.setId(listId); + return todoListRepository + .findById(listId) + .map(t -> ResponseEntity.ok(todoListRepository.save(todoList))) + .orElseGet(() -> ResponseEntity.notFound().build()); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java index 85d35adfbe3..61dbc74e5b2 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java @@ -2,13 +2,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; -import org.springframework.format.annotation.DateTimeFormat; - +import java.time.OffsetDateTime; +import java.util.Objects; import javax.annotation.Generated; import javax.validation.Valid; import javax.validation.constraints.NotNull; -import java.time.OffsetDateTime; -import java.util.Objects; +import org.springframework.format.annotation.DateTimeFormat; /** * A task that needs to be completed @@ -18,155 +17,163 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoItem { - @JsonProperty("id") - private String id; - - @JsonProperty("listId") - private String listId; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - @JsonProperty("state") - private TodoState state; - - @JsonProperty("dueDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime dueDate; - - @JsonProperty("completedDate") - @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) - private OffsetDateTime completedDate; - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - /** - * Get listId - * @return listId - */ - @NotNull - @Schema(name = "listId", required = true) - public String getListId() { - return listId; - } - - public void setListId(String listId) { - this.listId = listId; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - /** - * Get description - * @return description - */ - @NotNull - @Schema(name = "description", required = true) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - /** - * Get state - * @return state - */ - @Valid - @Schema(name = "state", required = false) - public TodoState getState() { - return state; - } - - public void setState(TodoState state) { - this.state = state; - } - - /** - * Get dueDate - * @return dueDate - */ - @Valid - @Schema(name = "dueDate", required = false) - public OffsetDateTime getDueDate() { - return dueDate; - } - - public void setDueDate(OffsetDateTime dueDate) { - this.dueDate = dueDate; - } - - /** - * Get completedDate - * @return completedDate - */ - @Valid - @Schema(name = "completedDate", required = false) - public OffsetDateTime getCompletedDate() { - return completedDate; - } - - public void setCompletedDate(OffsetDateTime completedDate) { - this.completedDate = completedDate; - } - - public boolean equals(final Object o) { - // items are equal if they have the same `listId` and `id` - if (o == this) - return true; - if (!(o instanceof TodoItem)) - return false; - final TodoItem other = (TodoItem) o; - if (!((Object) this instanceof TodoItem)) - return false; - final Object this$id = this.getId(); - final Object other$id = other.getId(); - if (this$id == null ? other$id != null : !this$id.equals(other$id)) - return false; - final Object this$listId = this.getListId(); - final Object other$listId = other.getListId(); - if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) - return false; - return true; - } - - public int hashCode() { - return Objects.hash(this.listId, this.id); - } - - public String toString() { - return "TodoItem(id=" + this.getId() + ", listId=" + this.getListId() + ", name=" + this.getName() - + ", description=" + this.getDescription() + ", state=" + this.getState() + ", dueDate=" - + this.getDueDate() + ", completedDate=" + this.getCompletedDate() + ")"; - } - + @JsonProperty("id") + private String id; + + @JsonProperty("listId") + private String listId; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("state") + private TodoState state; + + @JsonProperty("dueDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime dueDate; + + @JsonProperty("completedDate") + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime completedDate; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get listId + * @return listId + */ + @NotNull + @Schema(name = "listId", required = true) + public String getListId() { + return listId; + } + + public void setListId(String listId) { + this.listId = listId; + } + + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + @NotNull + @Schema(name = "description", required = true) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + /** + * Get state + * @return state + */ + @Valid + @Schema(name = "state", required = false) + public TodoState getState() { + return state; + } + + public void setState(TodoState state) { + this.state = state; + } + + /** + * Get dueDate + * @return dueDate + */ + @Valid + @Schema(name = "dueDate", required = false) + public OffsetDateTime getDueDate() { + return dueDate; + } + + public void setDueDate(OffsetDateTime dueDate) { + this.dueDate = dueDate; + } + + /** + * Get completedDate + * @return completedDate + */ + @Valid + @Schema(name = "completedDate", required = false) + public OffsetDateTime getCompletedDate() { + return completedDate; + } + + public void setCompletedDate(OffsetDateTime completedDate) { + this.completedDate = completedDate; + } + + public boolean equals(final Object o) { + // items are equal if they have the same `listId` and `id` + if (o == this) return true; + if (!(o instanceof TodoItem)) return false; + final TodoItem other = (TodoItem) o; + if (!((Object) this instanceof TodoItem)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + final Object this$listId = this.getListId(); + final Object other$listId = other.getListId(); + if (this$listId == null ? other$listId != null : !this$listId.equals(other$listId)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.listId, this.id); + } + + public String toString() { + return ( + "TodoItem(id=" + + this.getId() + + ", listId=" + + this.getListId() + + ", name=" + + this.getName() + + ", description=" + + this.getDescription() + + ", state=" + + this.getState() + + ", dueDate=" + + this.getDueDate() + + ", completedDate=" + + this.getCompletedDate() + + ")" + ); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java index 561345c5479..19925fb56da 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java @@ -2,10 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; - +import java.util.Objects; import javax.annotation.Generated; import javax.validation.constraints.NotNull; -import java.util.Objects; /** * A list of related Todo items @@ -15,80 +14,74 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public class TodoList { - @JsonProperty("id") - private String id; - - @JsonProperty("name") - private String name; - - @JsonProperty("description") - private String description; - - /** - * Get id - * @return id - */ - - @Schema(name = "id", required = false) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - /** - * Get name - * @return name - */ - @NotNull - @Schema(name = "name", required = true) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - /** - * Get description - * @return description - */ - - @Schema(name = "description", required = false) - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean equals(final Object o) { - if (o == this) - return true; - if (!(o instanceof TodoList)) - return false; - final TodoList other = (TodoList) o; - if (!((Object) this instanceof TodoList)) - return false; - final Object this$id = this.getId(); - final Object other$id = other.getId(); - // lists are equal if they have the same id - if (this$id == null ? other$id != null : !this$id.equals(other$id)) - return false; - return true; - } - - public int hashCode() { - return Objects.hash(this.getId()); - } - - public String toString() { - return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() - + ")"; - } - + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + /** + * Get id + * @return id + */ + + @Schema(name = "id", required = false) + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get name + * @return name + */ + @NotNull + @Schema(name = "name", required = true) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Get description + * @return description + */ + + @Schema(name = "description", required = false) + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean equals(final Object o) { + if (o == this) return true; + if (!(o instanceof TodoList)) return false; + final TodoList other = (TodoList) o; + if (!((Object) this instanceof TodoList)) return false; + final Object this$id = this.getId(); + final Object other$id = other.getId(); + // lists are equal if they have the same id + if (this$id == null ? other$id != null : !this$id.equals(other$id)) return false; + return true; + } + + public int hashCode() { + return Objects.hash(this.getId()); + } + + public String toString() { + return "TodoList(id=" + this.getId() + ", name=" + this.getName() + ", description=" + this.getDescription() + ")"; + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java index 11b62fb1e89..c26fd86f824 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/model/TodoState.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; - import javax.annotation.Generated; /** @@ -11,37 +10,35 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") public enum TodoState { + TODO("todo"), - TODO("todo"), - - INPROGRESS("inprogress"), - - DONE("done"); + INPROGRESS("inprogress"), - private String value; + DONE("done"); - TodoState(String value) { - this.value = value; - } + private String value; - @JsonValue - public String getValue() { - return value; - } + TodoState(String value) { + this.value = value; + } - @Override - public String toString() { - return String.valueOf(value); - } + @JsonValue + public String getValue() { + return value; + } - @JsonCreator - public static TodoState fromValue(String value) { - for (TodoState b : TodoState.values()) { - if (b.value.equalsIgnoreCase(value)) { // ignore case - return b; - } - } - throw new IllegalArgumentException("Unexpected value '" + value + "'"); - } + @Override + public String toString() { + return String.valueOf(value); + } + @JsonCreator + public static TodoState fromValue(String value) { + for (TodoState b : TodoState.values()) { + if (b.value.equalsIgnoreCase(value)) { // ignore case + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java index db1c08e0ad2..1d374ff0d09 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoItemRepository.java @@ -1,24 +1,21 @@ package com.microsoft.azure.simpletodo.repository; import com.microsoft.azure.simpletodo.model.TodoItem; -import org.springframework.data.mongodb.repository.Aggregation; -import org.springframework.data.mongodb.repository.MongoRepository; - import java.util.List; import java.util.Optional; +import org.springframework.data.mongodb.repository.Aggregation; +import org.springframework.data.mongodb.repository.MongoRepository; public interface TodoItemRepository extends MongoRepository { + TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); - TodoItem deleteTodoItemByListIdAndId(String listId, String itemId); - - List findTodoItemsByListId(String listId); - - Optional findTodoItemByListIdAndId(String listId, String id); + List findTodoItemsByListId(String listId); - @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0 } }", "{ '$skip': ?1 }", "{ '$limit': ?2 }", }) - List findTodoItemsByTodoList(String listId, int skip, int limit); + Optional findTodoItemByListIdAndId(String listId, String id); - @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", "{ '$skip': ?2 }", "{ '$limit': ?3 }", }) - List findTodoItemsByTodoListAndState(String listId, String state, int skip, int limit); + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0 } }", "{ '$skip': ?1 }", "{ '$limit': ?2 }" }) + List findTodoItemsByTodoList(String listId, int skip, int limit); + @Aggregation(pipeline = { "{ '$match': { 'listId' : ?0, 'state' : ?1 } }", "{ '$skip': ?2 }", "{ '$limit': ?3 }" }) + List findTodoItemsByTodoListAndState(String listId, String state, int skip, int limit); } diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java index 5759c68ad3b..5dcc2b70eef 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/repository/TodoListRepository.java @@ -1,17 +1,13 @@ package com.microsoft.azure.simpletodo.repository; import com.microsoft.azure.simpletodo.model.TodoList; - import java.util.List; - import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; public interface TodoListRepository extends MongoRepository { + @Aggregation(pipeline = { "{ '$skip': ?0 }", "{ '$limit': ?1 }" }) + List findAll(int skip, int limit); - @Aggregation(pipeline = { "{ '$skip': ?0 }", "{ '$limit': ?1 }", }) - List findAll(int skip, int limit); - - TodoList deleteTodoListById(String id); - + TodoList deleteTodoListById(String id); } diff --git a/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java b/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java index 7e373c79969..8970dee090a 100644 --- a/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java +++ b/templates/todo/api/java/src/test/java/com/microsoft/azure/simpletodo/SimpleTodoApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class SimpleTodoApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } From 6997ddd81b8a640622a7e28197485bed4d81c693 Mon Sep 17 00:00:00 2001 From: Wei Lim Date: Fri, 18 Nov 2022 13:25:55 -0800 Subject: [PATCH 18/19] Reformat codegen --- .../todo/api/java/.openapi-generator/FILES | 1 + .../openapi.yaml-default.sha256 | 2 +- .../azure/simpletodo/api/ItemsApi.java | 48 ++++++++++++------- .../azure/simpletodo/api/ListsApi.java | 27 +++++++---- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/templates/todo/api/java/.openapi-generator/FILES b/templates/todo/api/java/.openapi-generator/FILES index 726c90a1f19..1596b4b1b10 100644 --- a/templates/todo/api/java/.openapi-generator/FILES +++ b/templates/todo/api/java/.openapi-generator/FILES @@ -1,4 +1,5 @@ src/main/java/com/microsoft/azure/simpletodo/api/ApiUtil.java +src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java src/main/java/com/microsoft/azure/simpletodo/model/TodoItem.java src/main/java/com/microsoft/azure/simpletodo/model/TodoList.java diff --git a/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 b/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 index 4bf5f74fc3c..59b3d7fcc12 100644 --- a/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 +++ b/templates/todo/api/java/.openapi-generator/openapi.yaml-default.sha256 @@ -1 +1 @@ -1e0347e24b739d303f3af0493d1e730e4ac47a27fdac1e8a151defcc745496f0 \ No newline at end of file +baa1ff1c1daf16544c5985f4e1240a6d5611af0bb2d5f4bf5b631de8d53a9e70 \ No newline at end of file diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java index 3e32726959f..8e006fed20f 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ItemsApi.java @@ -9,21 +9,27 @@ import com.microsoft.azure.simpletodo.model.TodoState; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import java.math.BigDecimal; import java.util.List; +import java.util.List; +import java.util.Map; import java.util.Optional; import javax.annotation.Generated; import javax.validation.Valid; +import javax.validation.constraints.*; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @@ -35,10 +41,11 @@ default Optional getRequest() { /** * POST /lists/{listId}/items : Creates a new Todo item within a list + * * @param listId The Todo list unique identifier (required) * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 201) or Todo list not found (status code - * 404) + * @return A Todo item result (status code 201) + * or Todo list not found (status code 404) */ @Operation( operationId = "createItem", @@ -81,10 +88,11 @@ default ResponseEntity createItem( /** * DELETE /lists/{listId}/items/{itemId} : Deletes a Todo item by unique identifier + * * @param listId The Todo list unique identifier (required) * @param itemId The Todo item unique identifier (required) - * @return Todo item deleted successfully (status code 204) or Todo list or item not - * found (status code 404) + * @return Todo item deleted successfully (status code 204) + * or Todo list or item not found (status code 404) */ @Operation( operationId = "deleteItemById", @@ -109,10 +117,11 @@ default ResponseEntity deleteItemById( /** * GET /lists/{listId}/items/{itemId} : Gets a Todo item by unique identifier + * * @param listId The Todo list unique identifier (required) * @param itemId The Todo item unique identifier (required) - * @return A Todo item result (status code 200) or Todo list or item not found (status - * code 404) + * @return A Todo item result (status code 200) + * or Todo list or item not found (status code 404) */ @Operation( operationId = "getItemById", @@ -152,11 +161,12 @@ default ResponseEntity getItemById( /** * GET /lists/{listId}/items : Gets Todo items within the specified list + * * @param listId The Todo list unique identifier (required) * @param top The max number of items to returns in a result (optional, default to 20) * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) or Todo list not found (status - * code 404) + * @return An array of Todo items (status code 200) + * or Todo list not found (status code 404) */ @Operation( operationId = "getItemsByListId", @@ -202,14 +212,14 @@ default ResponseEntity> getItemsByListId( } /** - * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific - * state + * GET /lists/{listId}/items/state/{state} : Gets a list of Todo items of a specific state + * * @param listId The Todo list unique identifier (required) * @param state The Todo item state (required) * @param top The max number of items to returns in a result (optional, default to 20) * @param skip The number of items to skip within the results (optional, default to 0) - * @return An array of Todo items (status code 200) or Todo list or item not found - * (status code 404) + * @return An array of Todo items (status code 200) + * or Todo list or item not found (status code 404) */ @Operation( operationId = "getItemsByListIdAndState", @@ -263,11 +273,13 @@ default ResponseEntity> getItemsByListIdAndState( /** * PUT /lists/{listId}/items/{itemId} : Updates a Todo item by unique identifier + * * @param listId The Todo list unique identifier (required) * @param itemId The Todo item unique identifier (required) * @param todoItem The Todo Item (optional) - * @return A Todo item result (status code 200) or Todo item is invalid (status code - * 400) or Todo list or item not found (status code 404) + * @return A Todo item result (status code 200) + * or Todo item is invalid (status code 400) + * or Todo list or item not found (status code 404) */ @Operation( operationId = "updateItemById", @@ -313,13 +325,13 @@ default ResponseEntity updateItemById( } /** - * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list - * items + * PUT /lists/{listId}/items/state/{state} : Changes the state of the specified list items + * * @param listId The Todo list unique identifier (required) * @param state The Todo item state (required) * @param requestBody unique identifiers of the Todo items to update (optional) - * @return Todo items updated (status code 204) or Update request is invalid (status - * code 400) + * @return Todo items updated (status code 204) + * or Update request is invalid (status code 400) */ @Operation( operationId = "updateItemsStateByListId", diff --git a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java index 323ca2d6b92..73104e8897b 100644 --- a/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java +++ b/templates/todo/api/java/src/main/java/com/microsoft/azure/simpletodo/api/ListsApi.java @@ -8,21 +8,26 @@ import com.microsoft.azure.simpletodo.model.TodoList; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import java.math.BigDecimal; import java.util.List; +import java.util.Map; import java.util.Optional; import javax.annotation.Generated; import javax.validation.Valid; +import javax.validation.constraints.*; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen") @Validated @@ -34,9 +39,10 @@ default Optional getRequest() { /** * POST /lists : Creates a new Todo list + * * @param todoList The Todo List (optional) - * @return A Todo list result (status code 201) or Invalid request schema (status code - * 400) + * @return A Todo list result (status code 201) + * or Invalid request schema (status code 400) */ @Operation( operationId = "createList", @@ -75,9 +81,10 @@ default ResponseEntity createList( /** * DELETE /lists/{listId} : Deletes a Todo list by unique identifier + * * @param listId The Todo list unique identifier (required) - * @return Todo list deleted successfully (status code 204) or Todo list not found - * (status code 404) + * @return Todo list deleted successfully (status code 204) + * or Todo list not found (status code 404) */ @Operation( operationId = "deleteListById", @@ -99,9 +106,10 @@ default ResponseEntity deleteListById( /** * GET /lists/{listId} : Gets a Todo list by unique identifier + * * @param listId The Todo list unique identifier (required) - * @return A Todo list result (status code 200) or Todo list not found (status code - * 404) + * @return A Todo list result (status code 200) + * or Todo list not found (status code 404) */ @Operation( operationId = "getListById", @@ -137,6 +145,7 @@ default ResponseEntity getListById( /** * GET /lists : Gets an array of Todo lists + * * @param top The max number of items to returns in a result (optional, default to 20) * @param skip The number of items to skip within the results (optional, default to 0) * @return An array of Todo lists (status code 200) @@ -181,10 +190,12 @@ default ResponseEntity> getLists( /** * PUT /lists/{listId} : Updates a Todo list by unique identifier + * * @param listId The Todo list unique identifier (required) * @param todoList The Todo List (optional) - * @return A Todo list result (status code 200) or Todo list not found (status code - * 404) or Todo list is invalid (status code 400) + * @return A Todo list result (status code 200) + * or Todo list not found (status code 404) + * or Todo list is invalid (status code 400) */ @Operation( operationId = "updateListById", From 9966e027bf8be8e43f9bee2b1cde7cde18e76558 Mon Sep 17 00:00:00 2001 From: Wei Lim Date: Fri, 18 Nov 2022 13:35:21 -0800 Subject: [PATCH 19/19] add cspell --- .vscode/cspell-templates.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/cspell-templates.txt b/.vscode/cspell-templates.txt index bb030d0d927..e40f3e9caa1 100644 --- a/.vscode/cspell-templates.txt +++ b/.vscode/cspell-templates.txt @@ -20,11 +20,11 @@ eastus envconfig ezfunc fasterxml +hubspot immer inprogress INPROGRESS Instrumentor -javaformat mkdir mvnw networkidle