diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache index 945e0c06eec..49d82ea73b2 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache @@ -50,7 +50,7 @@ public interface {{classname}} { produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} method = RequestMethod.{{httpMethod}}) - {{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{#examples}}throws IOException{{/examples}}{{^jdk8}};{{/jdk8}}{{#jdk8}} { + {{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{#examples}}{{#-first}} throws IOException{{/-first}}{{/examples}}{{^jdk8}};{{/jdk8}}{{#jdk8}} { // do some magic! return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}}; }{{/jdk8}} diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/apiController.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/apiController.mustache index 8dfa6d8a1e9..95162cbd0b9 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpring/apiController.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpring/apiController.mustache @@ -38,27 +38,45 @@ public class {{classname}}Controller implements {{classname}} { @org.springframework.beans.factory.annotation.Autowired public {{classname}}Controller({{classname}}Delegate delegate) { this.delegate = delegate; - }{{/isDelegate}} + } -{{^jdk8-no-delegate}}{{#operation}} +{{/isDelegate}} +{{^jdk8-no-delegate}} +{{#operation}} public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}) {{#examples}}throws IOException{{/examples}} { - // do some magic!{{^isDelegate}}{{^async}} - + {{/hasMore}}{{/allParams}}){{#examples}}{{#-first}} throws IOException{{/-first}}{{/examples}} { + // do some magic! + {{^isDelegate}} + {{^async}} {{#examples}} + {{#-first}} + ObjectMapper objectMapper = new ObjectMapper(); - return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue({{{example}}},{{>exampleReturnTypes}}.class), HttpStatus.OK); + + {{/-first}} + if ("{{{contentType}}}".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{{example}}}",{{>exampleReturnTypes}}.class), HttpStatus.OK); + } + {{/examples}} {{^examples}} - return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/examples}}{{/async}}{{#async}} + return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); + {{/examples}} + {{/async}} + {{#async}} return new CallablereturnTypes}}>>() { @Override public ResponseEntity<{{>returnTypes}}> call() throws Exception { return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); } - };{{/async}}{{/isDelegate}}{{#isDelegate}} - return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/isDelegate}} + }; + {{/async}} + {{/isDelegate}} + {{#isDelegate}} + return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{/isDelegate}} } -{{/operation}}{{/jdk8-no-delegate}} +{{/operation}} +{{/jdk8-no-delegate}} } {{/operations}} diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApi.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApi.java index b0ed6f9a514..05783d1f44b 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApi.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApi.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import javax.validation.constraints.*; @@ -31,7 +32,7 @@ public interface FakeApi { produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.PATCH) - ResponseEntity testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body); + ResponseEntity testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body) throws IOException; @ApiOperation(value = "Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 ", notes = "Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 ", response = Void.class, authorizations = { diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApiController.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApiController.java index 5cf609a4ae0..920f8a2274f 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApiController.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/FakeApiController.java @@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.List; @@ -24,14 +26,18 @@ import javax.validation.Valid; @Controller public class FakeApiController implements FakeApi { - - - - public ResponseEntity testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body) { + public ResponseEntity testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "client" : "aeiou" +}",Client.class), HttpStatus.OK); + } + + } public ResponseEntity testEndpointParameters(@ApiParam(value = "None", required=true) @RequestPart(value="number", required=true) BigDecimal number, @ApiParam(value = "None", required=true) @RequestPart(value="double", required=true) Double _double, @ApiParam(value = "None", required=true) @RequestPart(value="pattern_without_delimiter", required=true) String patternWithoutDelimiter, @@ -49,7 +55,6 @@ public class FakeApiController implements FakeApi { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity testEnumParameters(@ApiParam(value = "Form parameter enum test (string array)", allowableValues=">, $") @RequestPart(value="enum_form_string_array", required=false) List enumFormStringArray, @ApiParam(value = "Form parameter enum test (string)", allowableValues="_abc, -efg, (xyz)", defaultValue="-efg") @RequestPart(value="enum_form_string", required=false) String enumFormString, @ApiParam(value = "Header parameter enum test (string array)" , allowableValues=">, $") @RequestHeader(value="enum_header_string_array", required=false) List enumHeaderStringArray, @@ -61,5 +66,4 @@ public class FakeApiController implements FakeApi { // do some magic! return new ResponseEntity(HttpStatus.OK); } - } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApi.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApi.java index 3cf98279345..59846383b86 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApi.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApi.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import javax.validation.constraints.*; @@ -66,7 +67,7 @@ public interface PetApi { @RequestMapping(value = "/pet/findByStatus", produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - 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); + 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) throws IOException; @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 = { @@ -82,7 +83,7 @@ public interface PetApi { @RequestMapping(value = "/pet/findByTags", produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags); + ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags) throws IOException; @ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { @@ -96,7 +97,7 @@ public interface PetApi { @RequestMapping(value = "/pet/{petId}", produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId); + ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) throws IOException; @ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = { @@ -146,6 +147,6 @@ public interface PetApi { 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,@ApiParam(value = "Additional data to pass to server") @RequestPart(value="additionalMetadata", required=false) String additionalMetadata,@ApiParam(value = "file detail") @RequestPart("file") MultipartFile file); + 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) throws IOException; } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApiController.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApiController.java index 973055a2f11..04fe59a4db4 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApiController.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/PetApiController.java @@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.List; @@ -23,52 +25,147 @@ import javax.validation.Valid; @Controller public class PetApiController implements PetApi { - - - public ResponseEntity addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId, @ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - - 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) { + 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) throws IOException { // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); - public ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags) { + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity>(objectMapper.readValue(" + 123456789 + doggie + + aeiou + + + + aeiou +",List.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity>(objectMapper.readValue("[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "aeiou", + "id" : 6 + }, + "tags" : [ { + "name" : "aeiou", + "id" : 1 + } ], + "status" : "available" +} ]",List.class), HttpStatus.OK); + } + + } + public ResponseEntity> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags) throws IOException { // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); - public ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) { + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity>(objectMapper.readValue(" + 123456789 + doggie + + aeiou + + + + aeiou +",List.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity>(objectMapper.readValue("[ { + "photoUrls" : [ "aeiou" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "aeiou", + "id" : 6 + }, + "tags" : [ { + "name" : "aeiou", + "id" : 1 + } ], + "status" : "available" +} ]",List.class), HttpStatus.OK); + } + + } + public ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue(" + 123456789 + doggie + + aeiou + + + + aeiou +",Pet.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "photoUrls" : [ "aeiou" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "aeiou", + "id" : 6 + }, + "tags" : [ { + "name" : "aeiou", + "id" : 1 + } ], + "status" : "available" +}",Pet.class), HttpStatus.OK); + } + + } public ResponseEntity updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @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") 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, @ApiParam(value = "Additional data to pass to server") @RequestPart(value="additionalMetadata", required=false) String additionalMetadata, - @ApiParam(value = "file detail") @RequestPart("file") MultipartFile file) { + @ApiParam(value = "file detail") @RequestPart("file") MultipartFile file) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "code" : 0, + "type" : "aeiou", + "message" : "aeiou" +}",ModelApiResponse.class), HttpStatus.OK); + } + + } } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApi.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApi.java index 8b080a440dd..7301912a9c8 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApi.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApi.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import javax.validation.constraints.*; @@ -41,7 +42,7 @@ public interface StoreApi { @RequestMapping(value = "/store/inventory", produces = { "application/json" }, method = RequestMethod.GET) - ResponseEntity> getInventory(); + ResponseEntity> getInventory() throws IOException; @ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", }) @@ -53,7 +54,7 @@ public interface StoreApi { @RequestMapping(value = "/store/order/{order_id}", produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("order_id") Long orderId); + ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("order_id") Long orderId) throws IOException; @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", }) @@ -64,6 +65,6 @@ public interface StoreApi { @RequestMapping(value = "/store/order", produces = { "application/xml", "application/json" }, method = RequestMethod.POST) - ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body); + ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body) throws IOException; } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApiController.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApiController.java index 472bda2ada0..0c6cea2a4a6 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApiController.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/StoreApiController.java @@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.List; @@ -22,27 +24,76 @@ import javax.validation.Valid; @Controller public class StoreApiController implements StoreApi { - - - public ResponseEntity deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("order_id") String orderId) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - - public ResponseEntity> getInventory() { + public ResponseEntity> getInventory() throws IOException { // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); - public ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("order_id") Long orderId) { + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity>(objectMapper.readValue("{ + "key" : 0 +}",Map.class), HttpStatus.OK); + } + + } + public ResponseEntity getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("order_id") Long orderId) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); - public ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body) { + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue(" + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +",Order.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" +}",Order.class), HttpStatus.OK); + } + + } + public ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue(" + 123456789 + 123456789 + 123 + 2000-01-23T04:56:07.000Z + aeiou + true +",Order.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" +}",Order.class), HttpStatus.OK); + } + + } } diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApi.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApi.java index 4993fa21bfd..7d6729c23b9 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApi.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApi.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import javax.validation.constraints.*; @@ -71,7 +72,7 @@ public interface UserApi { @RequestMapping(value = "/user/{username}", 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); + ResponseEntity getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) throws IOException; @ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", }) @@ -82,7 +83,7 @@ public interface UserApi { @RequestMapping(value = "/user/login", produces = { "application/xml", "application/json" }, method = RequestMethod.GET) - 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); + 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) throws IOException; @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class, tags={ "user", }) diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApiController.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApiController.java index 00d7e5deba1..c1a4eaf41f5 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApiController.java +++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/api/UserApiController.java @@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.List; @@ -22,49 +24,76 @@ import javax.validation.Valid; @Controller public class UserApiController implements UserApi { - - - public ResponseEntity createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody User body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody List body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody List body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - - public ResponseEntity getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) { + public ResponseEntity getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue(" + 123456789 + aeiou + aeiou + aeiou + aeiou + aeiou + aeiou + 123 +",User.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("{ + "firstName" : "aeiou", + "lastName" : "aeiou", + "password" : "aeiou", + "userStatus" : 6, + "phone" : "aeiou", + "id" : 0, + "email" : "aeiou", + "username" : "aeiou" +}",User.class), HttpStatus.OK); + } + + } 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) { + @NotNull @ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password) throws IOException { // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + + ObjectMapper objectMapper = new ObjectMapper(); + if ("application/xml".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue("aeiou",String.class), HttpStatus.OK); + } + + if ("application/json".equals("")) { //TODO need to compare HTTP request "Accept" + return new ResponseEntity(objectMapper.readValue(""aeiou"",String.class), HttpStatus.OK); + } + + } public ResponseEntity logoutUser() { // do some magic! return new ResponseEntity(HttpStatus.OK); } - public ResponseEntity updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, @ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody User body) { // do some magic! return new ResponseEntity(HttpStatus.OK); } - }