From b439494f060e971734454a3c6c2e34a4ecc85256 Mon Sep 17 00:00:00 2001 From: "J. Fiala" Date: Mon, 6 Feb 2017 22:36:40 +0100 Subject: [PATCH] update templates and samples for spring-boot #4719 --- .../JavaSpring/beanValidation.mustache | 51 +------------------ .../JavaSpring/beanValidationCore.mustache | 20 ++++++++ .../beanValidationPathParams.mustache | 2 +- .../beanValidationQueryParams.mustache | 2 +- samples/server/petstore/springboot/pom.xml | 6 +-- .../src/main/java/io/swagger/api/PetApi.java | 41 +++++++-------- .../java/io/swagger/api/PetApiController.java | 17 ++++--- .../main/java/io/swagger/api/StoreApi.java | 12 ++--- .../io/swagger/api/StoreApiController.java | 4 +- .../src/main/java/io/swagger/api/UserApi.java | 28 +++++----- .../io/swagger/api/UserApiController.java | 12 ++--- .../SwaggerDocumentationConfig.java | 4 +- .../java/io/swagger/model/Capitalization.java | 2 +- .../java/io/swagger/model/FormatTest.java | 26 +++------- .../src/main/java/io/swagger/model/Order.java | 2 +- 15 files changed, 93 insertions(+), 136 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationCore.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidation.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidation.mustache index 079eab89d1a..c8c6946fef6 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidation.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidation.mustache @@ -1,53 +1,4 @@ {{#required}} @NotNull {{/required}} -{{#pattern}} - @Pattern(regexp="{{pattern}}") -{{/pattern}} -{{#minLength}} -{{#maxLength}} - @Size(min={{minLength}},max={{maxLength}}) -{{/maxLength}} -{{/minLength}} -{{#minLength}} -{{^maxLength}} - @Size(min={{minLength}}) -{{/maxLength}} -{{/minLength}} -{{^minLength}} -{{#maxLength}} - @Size(max={{maxLength}}) - {{/maxLength}} - {{/minLength}} -{{#minItems}} -{{#maxItems}} - @Size(min={{minItems}},max={{maxItems}}) -{{/maxItems}} -{{/minItems}} -{{#minItems}} -{{^maxItems}} - @Size(min={{minItems}}) -{{/maxItems}} -{{/minItems}} -{{^minItems}} -{{#maxItems}} - @Size(max={{maxItems}}) -{{/maxItems}} -{{/minItems}} -{{! check for integer / number=decimal type}} -{{#isInteger}} -{{#minimum}} - @Min({{minimum}}) -{{/minimum}} -{{#maximum}} - @Max({{maximum}}) -{{/maximum}} -{{/isInteger}} -{{^isInteger}} -{{#minimum}} - @DecimalMin("{{minimum}}") -{{/minimum}} -{{#maximum}} - @DecimalMax("{{maximum}}") -{{/maximum}} -{{/isInteger}} \ No newline at end of file +{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationCore.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationCore.mustache new file mode 100644 index 00000000000..dc7a8392216 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationCore.mustache @@ -0,0 +1,20 @@ +{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{! +minLength && maxLength set +}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +minLength set, maxLength not +}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{! +minLength not set, maxLength set +}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{! +@Size: minItems && maxItems set +}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems set, maxItems not +}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{! +@Size: minItems not set && maxItems set +}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! +check for integer or long / all others=decimal type with @Decimal* +isInteger set +}}{{#isInteger}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/isInteger}}{{! +isLong set +}}{{#isLong}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/isLong}}{{! +Not Integer, not Long => we have a decimal value! +}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isLong}}{{/isInteger}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationPathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationPathParams.mustache index e3060fa6c6a..051bd53c0a5 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationPathParams.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationPathParams.mustache @@ -1 +1 @@ -{{! PathParam is always required, no @NotNull necessary }}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file +{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationQueryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationQueryParams.mustache index 52440b12218..f8eef8f94c7 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationQueryParams.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/beanValidationQueryParams.mustache @@ -1 +1 @@ -{{#required}} @NotNull{{/required}}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} \ No newline at end of file +{{#required}} @NotNull{{/required}}{{>beanValidationCore}} \ No newline at end of file diff --git a/samples/server/petstore/springboot/pom.xml b/samples/server/petstore/springboot/pom.xml index 9ba170a11a5..d777f7d31f1 100644 --- a/samples/server/petstore/springboot/pom.xml +++ b/samples/server/petstore/springboot/pom.xml @@ -1,9 +1,9 @@ 4.0.0 io.swagger - swagger-boot + swagger-spring jar - swagger-boot + swagger-spring 1.0.0 1.7 @@ -70,4 +70,4 @@ provided - + \ No newline at end of file diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApi.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApi.java index a70f2a1a0db..dcd4a0f8b8c 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApi.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApi.java @@ -1,6 +1,7 @@ package io.swagger.api; import java.io.File; +import io.swagger.model.ModelApiResponse; import io.swagger.model.Pet; import io.swagger.annotations.*; @@ -29,10 +30,10 @@ public interface PetApi { @ApiResponses(value = { @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) @RequestMapping(value = "/pet", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" }, method = RequestMethod.POST) - ResponseEntity addPet(@ApiParam(value = "Pet object that needs to be added to the store" ) @RequestBody Pet body); + ResponseEntity addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body); @ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = { @@ -44,7 +45,7 @@ public interface PetApi { @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) }) @RequestMapping(value = "/pet/{petId}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.DELETE) ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey); @@ -60,9 +61,9 @@ ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=tru @ApiResponse(code = 200, message = "successful operation", response = Pet.class), @ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) }) @RequestMapping(value = "/pet/findByStatus", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity> findPetsByStatus( @ApiParam(value = "Status values that need to be considered for filter", allowableValues = "AVAILABLE, PENDING, SOLD", defaultValue = "available") @RequestParam(value = "status", required = false, defaultValue="available") List status); + ResponseEntity> findPetsByStatus( @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "AVAILABLE, PENDING, SOLD") @RequestParam(value = "status", required = true) List status); @ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = { @@ -75,16 +76,12 @@ ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=tru @ApiResponse(code = 200, message = "successful operation", response = Pet.class), @ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) }) @RequestMapping(value = "/pet/findByTags", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity> findPetsByTags( @ApiParam(value = "Tags to filter by") @RequestParam(value = "tags", required = false) List tags); + ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags); - @ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class, authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }), + @ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { @Authorization(value = "api_key") }, tags={ "pet", }) @ApiResponses(value = { @@ -92,9 +89,9 @@ ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=tru @ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class), @ApiResponse(code = 404, message = "Pet not found", response = Pet.class) }) @RequestMapping(value = "/pet/{petId}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity getPetById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("petId") Long petId); + ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId); @ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = { @@ -108,10 +105,10 @@ ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=tru @ApiResponse(code = 404, message = "Pet not found", response = Void.class), @ApiResponse(code = 405, message = "Validation exception", response = Void.class) }) @RequestMapping(value = "/pet", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" }, method = RequestMethod.PUT) - ResponseEntity updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ) @RequestBody Pet body); + ResponseEntity updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body); @ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = { @@ -123,27 +120,27 @@ ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=tru @ApiResponses(value = { @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) @RequestMapping(value = "/pet/{petId}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, consumes = { "application/x-www-form-urlencoded" }, method = RequestMethod.POST) - ResponseEntity updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") String petId, + ResponseEntity updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "Updated name of the pet" ) @RequestPart(value="name", required=false) String name, @ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status); - @ApiOperation(value = "uploads an image", notes = "", response = Void.class, authorizations = { + @ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = { @Authorization(value = "petstore_auth", scopes = { @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "read:pets", description = "read your pets") }) }, tags={ "pet", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) + @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) }) @RequestMapping(value = "/pet/{petId}/uploadImage", - produces = { "application/json", "application/xml" }, + produces = { "application/json" }, consumes = { "multipart/form-data" }, method = RequestMethod.POST) - ResponseEntity uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, + ResponseEntity uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "Additional data to pass to server" ) @RequestPart(value="additionalMetadata", required=false) String additionalMetadata, @ApiParam(value = "file detail") @RequestPart("file") MultipartFile file); diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApiController.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApiController.java index 2b18a2354d2..847b24e1a80 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApiController.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/PetApiController.java @@ -1,6 +1,7 @@ package io.swagger.api; import java.io.File; +import io.swagger.model.ModelApiResponse; import io.swagger.model.Pet; import io.swagger.annotations.*; @@ -24,7 +25,7 @@ public class PetApiController implements PetApi { - public ResponseEntity addPet(@ApiParam(value = "Pet object that needs to be added to the store" ) @RequestBody Pet body) { + public ResponseEntity addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } @@ -35,38 +36,38 @@ public ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",requi return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity> findPetsByStatus( @ApiParam(value = "Status values that need to be considered for filter", allowableValues = "AVAILABLE, PENDING, SOLD", defaultValue = "available") @RequestParam(value = "status", required = false, defaultValue="available") List status) { + public ResponseEntity> findPetsByStatus( @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "AVAILABLE, PENDING, SOLD") @RequestParam(value = "status", required = true) List status) { // do some magic! return new ResponseEntity>(HttpStatus.OK); } - public ResponseEntity> findPetsByTags( @ApiParam(value = "Tags to filter by") @RequestParam(value = "tags", required = false) List tags) { + public ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags) { // do some magic! return new ResponseEntity>(HttpStatus.OK); } - public ResponseEntity getPetById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("petId") Long petId) { + public ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ) @RequestBody Pet body) { + public ResponseEntity updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") String petId, + public ResponseEntity updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "Updated name of the pet" ) @RequestPart(value="name", required=false) String name, @ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, + public ResponseEntity uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "Additional data to pass to server" ) @RequestPart(value="additionalMetadata", required=false) String additionalMetadata, @ApiParam(value = "file detail") @RequestPart("file") MultipartFile file) { // do some magic! - return new ResponseEntity(HttpStatus.OK); + return new ResponseEntity(HttpStatus.OK); } } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApi.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApi.java index f4dd5a1be7e..47c2c561ff1 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApi.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApi.java @@ -25,7 +25,7 @@ public interface StoreApi { @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), @ApiResponse(code = 404, message = "Order not found", response = Void.class) }) @RequestMapping(value = "/store/order/{orderId}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.DELETE) ResponseEntity deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId); @@ -36,7 +36,7 @@ public interface StoreApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) @RequestMapping(value = "/store/inventory", - produces = { "application/json", "application/xml" }, + produces = { "application/json" }, method = RequestMethod.GET) ResponseEntity> getInventory(); @@ -47,9 +47,9 @@ public interface StoreApi { @ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class), @ApiResponse(code = 404, message = "Order not found", response = Order.class) }) @RequestMapping(value = "/store/order/{orderId}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") String orderId); + ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId); @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", }) @@ -57,8 +57,8 @@ public interface StoreApi { @ApiResponse(code = 200, message = "successful operation", response = Order.class), @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) @RequestMapping(value = "/store/order", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.POST) - ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ) @RequestBody Order body); + ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body); } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApiController.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApiController.java index f08a84a1699..97a1b7e5129 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApiController.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/StoreApiController.java @@ -34,12 +34,12 @@ public ResponseEntity> getInventory() { return new ResponseEntity>(HttpStatus.OK); } - public ResponseEntity getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") String orderId) { + public ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ) @RequestBody Order body) { + public ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApi.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApi.java index dbef9cd70d6..2d15d4b071a 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApi.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApi.java @@ -24,27 +24,27 @@ public interface UserApi { @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @RequestMapping(value = "/user", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.POST) - ResponseEntity createUser(@ApiParam(value = "Created user object" ) @RequestBody User body); + ResponseEntity createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body); @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @RequestMapping(value = "/user/createWithArray", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.POST) - ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ) @RequestBody List body); + ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body); @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @RequestMapping(value = "/user/createWithList", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.POST) - ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ) @RequestBody List body); + ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body); @ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", }) @@ -52,7 +52,7 @@ public interface UserApi { @ApiResponse(code = 400, message = "Invalid username supplied", response = Void.class), @ApiResponse(code = 404, message = "User not found", response = Void.class) }) @RequestMapping(value = "/user/{username}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.DELETE) ResponseEntity deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username); @@ -63,7 +63,7 @@ public interface UserApi { @ApiResponse(code = 400, message = "Invalid username supplied", response = User.class), @ApiResponse(code = 404, message = "User not found", response = User.class) }) @RequestMapping(value = "/user/{username}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) ResponseEntity getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username); @@ -73,17 +73,17 @@ public interface UserApi { @ApiResponse(code = 200, message = "successful operation", response = String.class), @ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) }) @RequestMapping(value = "/user/login", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity loginUser( @ApiParam(value = "The user name for login") @RequestParam(value = "username", required = false) String username, - @ApiParam(value = "The password for login in clear text") @RequestParam(value = "password", required = false) String password); + ResponseEntity loginUser( @NotNull @ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, + @NotNull @ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password); @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class, tags={ "user", }) @ApiResponses(value = { @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @RequestMapping(value = "/user/logout", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.GET) ResponseEntity logoutUser(); @@ -93,9 +93,9 @@ ResponseEntity loginUser( @ApiParam(value = "The user name for login") @ @ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class), @ApiResponse(code = 404, message = "User not found", response = Void.class) }) @RequestMapping(value = "/user/{username}", - produces = { "application/json", "application/xml" }, + produces = { "application/xml", "application/json" }, method = RequestMethod.PUT) ResponseEntity updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, - @ApiParam(value = "Updated user object" ) @RequestBody User body); + @ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body); } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApiController.java b/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApiController.java index ff3559427f7..c321750e95e 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApiController.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/api/UserApiController.java @@ -24,17 +24,17 @@ public class UserApiController implements UserApi { - public ResponseEntity createUser(@ApiParam(value = "Created user object" ) @RequestBody User body) { + public ResponseEntity createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ) @RequestBody List body) { + public ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ) @RequestBody List body) { + public ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } @@ -49,8 +49,8 @@ public ResponseEntity getUserByName(@ApiParam(value = "The name that needs return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity loginUser( @ApiParam(value = "The user name for login") @RequestParam(value = "username", required = false) String username, - @ApiParam(value = "The password for login in clear text") @RequestParam(value = "password", required = false) String password) { + public ResponseEntity loginUser( @NotNull @ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, + @NotNull @ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password) { // do some magic! return new ResponseEntity(HttpStatus.OK); } @@ -61,7 +61,7 @@ public ResponseEntity logoutUser() { } public ResponseEntity updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, - @ApiParam(value = "Updated user object" ) @RequestBody User body) { + @ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/configuration/SwaggerDocumentationConfig.java b/samples/server/petstore/springboot/src/main/java/io/swagger/configuration/SwaggerDocumentationConfig.java index 0652e2d736b..5658793e134 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/configuration/SwaggerDocumentationConfig.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/configuration/SwaggerDocumentationConfig.java @@ -17,12 +17,12 @@ public class SwaggerDocumentationConfig { ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Swagger Petstore") - .description("This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters") + .description("This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\") .license("Apache 2.0") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .termsOfServiceUrl("") .version("1.0.0") - .contact(new Contact("","", "apiteam@wordnik.com")) + .contact(new Contact("","", "apiteam@swagger.io")) .build(); } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/model/Capitalization.java b/samples/server/petstore/springboot/src/main/java/io/swagger/model/Capitalization.java index 94cb9977104..d7ad5642ccf 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/model/Capitalization.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/model/Capitalization.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; - +import javax.validation.constraints.*; /** * Capitalization */ diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/model/FormatTest.java b/samples/server/petstore/springboot/src/main/java/io/swagger/model/FormatTest.java index d48282d2d73..51e0c4cf734 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/model/FormatTest.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/model/FormatTest.java @@ -65,9 +65,7 @@ public FormatTest integer(Integer integer) { * @return integer **/ @ApiModelProperty(value = "") - @Min(10) - @Max(100) - public Integer getInteger() { + @Min(10) @Max(100) public Integer getInteger() { return integer; } @@ -87,9 +85,7 @@ public FormatTest int32(Integer int32) { * @return int32 **/ @ApiModelProperty(value = "") - @Min(20) - @Max(200) - public Integer getInt32() { + @Min(20) @Max(200) public Integer getInt32() { return int32; } @@ -128,9 +124,7 @@ public FormatTest number(BigDecimal number) { **/ @ApiModelProperty(required = true, value = "") @NotNull - @DecimalMin("32.1") - @DecimalMax("543.2") - public BigDecimal getNumber() { + @DecimalMin("32.1") @DecimalMax("543.2") public BigDecimal getNumber() { return number; } @@ -150,9 +144,7 @@ public FormatTest _float(Float _float) { * @return _float **/ @ApiModelProperty(value = "") - @DecimalMin("54.3") - @DecimalMax("987.6") - public Float getFloat() { + @DecimalMin("54.3") @DecimalMax("987.6") public Float getFloat() { return _float; } @@ -172,9 +164,7 @@ public FormatTest _double(Double _double) { * @return _double **/ @ApiModelProperty(value = "") - @DecimalMin("67.8") - @DecimalMax("123.4") - public Double getDouble() { + @DecimalMin("67.8") @DecimalMax("123.4") public Double getDouble() { return _double; } @@ -192,8 +182,7 @@ public FormatTest string(String string) { * @return string **/ @ApiModelProperty(value = "") - @Pattern(regexp="/[a-z]/i") - public String getString() { + @Pattern(regexp="/[a-z]/i") public String getString() { return string; } @@ -304,8 +293,7 @@ public FormatTest password(String password) { **/ @ApiModelProperty(required = true, value = "") @NotNull - @Size(min=10,max=64) - public String getPassword() { + @Size(min=10,max=64) public String getPassword() { return password; } diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/model/Order.java b/samples/server/petstore/springboot/src/main/java/io/swagger/model/Order.java index a5833514b10..41dec079587 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/model/Order.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/model/Order.java @@ -62,7 +62,7 @@ public static StatusEnum fromValue(String text) { private StatusEnum status = null; @JsonProperty("complete") - private Boolean complete = null; + private Boolean complete = false; public Order id(Long id) { this.id = id;