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