From c2dbe44d0887b5ee07354d165f7f0a0bd5a6efd9 Mon Sep 17 00:00:00 2001 From: cbornet Date: Fri, 10 Jun 2016 17:12:56 +0200 Subject: [PATCH] add java8 and async options to springboot codegen --- .../languages/SpringBootServerCodegen.java | 57 +++-- .../resources/JavaSpringBoot/api.mustache | 54 +++-- .../JavaSpringBoot/apiController.mustache | 31 ++- .../resources/JavaSpringBoot/pom.mustache | 135 ++++++----- .../swaggerDocumentationConfig.mustache | 16 +- .../SpringBootServerOptionsProvider.java | 4 + .../SpringBootServerOptionsTest.java | 4 + samples/server/petstore/springboot/pom.xml | 120 +++++----- .../java/io/swagger/Swagger2SpringBoot.java | 2 +- .../src/main/java/io/swagger/api/PetApi.java | 221 +++++++++--------- .../java/io/swagger/api/PetApiController.java | 64 ++--- .../main/java/io/swagger/api/StoreApi.java | 73 +++--- .../io/swagger/api/StoreApiController.java | 30 +-- .../src/main/java/io/swagger/api/UserApi.java | 131 +++++------ .../io/swagger/api/UserApiController.java | 58 ++--- .../SwaggerDocumentationConfig.java | 14 +- 16 files changed, 525 insertions(+), 489 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringBootServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringBootServerCodegen.java index dbed6bc98c4..4b30062d799 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringBootServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SpringBootServerCodegen.java @@ -12,11 +12,15 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege public static final String BASE_PACKAGE = "basePackage"; public static final String INTERFACE_ONLY = "interfaceOnly"; public static final String SINGLE_CONTENT_TYPES = "singleContentTypes"; + public static final String JAVA_8 = "java8"; + public static final String ASYNC = "async"; protected String title = "Petstore Server"; protected String configPackage = ""; protected String basePackage = ""; protected boolean interfaceOnly = false; protected boolean singleContentTypes = false; + protected boolean java8 = false; + protected boolean async = false; protected String templateFileName = "api.mustache"; public SpringBootServerCodegen() { @@ -45,11 +49,14 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege cliOptions.add(new CliOption(BASE_PACKAGE, "base package for generated code")); cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.")); cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.")); + cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface")); + cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers")); supportedLibraries.clear(); supportedLibraries.put(DEFAULT_LIBRARY, "Default Spring Boot server stub."); supportedLibraries.put("j8-async", "Use async servlet feature and Java 8's default interface. Generating interface with service " + - "declaration is useful when using Maven plugin. Just provide a implementation with @Controller to instantiate service."); + "declaration is useful when using Maven plugin. Just provide a implementation with @Controller to instantiate service." + + "(DEPRECATED: use -Djava8=true,async=true instead)"); } @Override @@ -92,11 +99,19 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString())); } + if (additionalProperties.containsKey(JAVA_8)) { + this.setJava8(Boolean.valueOf(additionalProperties.get(JAVA_8).toString())); + } + + if (additionalProperties.containsKey(ASYNC)) { + this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString())); + } + supportingFiles.clear(); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - if(!this.interfaceOnly) { + if (!this.interfaceOnly) { apiTemplateFiles.put("apiController.mustache", "Controller.java"); supportingFiles.add(new SupportingFile("apiException.mustache", (sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java")); @@ -115,6 +130,19 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege supportingFiles.add(new SupportingFile("application.properties", ("src.main.resources").replace(".", java.io.File.separator), "application.properties")); } + + if ("j8-async".equals(getLibrary())) { + setJava8(true); + setAsync(true); + } + + if (this.java8) { + additionalProperties.put("javaVersion", "1.8"); + typeMapping.put("date", "LocalDate"); + typeMapping.put("DateTime", "OffsetDateTime"); + importMapping.put("LocalDate", "java.time.LocalDate"); + importMapping.put("OffsetDateTime", "java.time.OffsetDateTime"); + } } @Override @@ -228,23 +256,6 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege } } } - if("j8-async".equals(getLibrary())) { - apiTemplateFiles.remove(this.templateFileName); - this.templateFileName = "api-j8-async.mustache"; - apiTemplateFiles.put(this.templateFileName, ".java"); - - int originalPomFileIdx = -1; - for (int i = 0; i < supportingFiles.size(); i++) { - if ("pom.xml".equals(supportingFiles.get(i).destinationFilename)) { - originalPomFileIdx = i; - break; - } - } - if (originalPomFileIdx > -1) { - supportingFiles.remove(originalPomFileIdx); - } - supportingFiles.add(new SupportingFile("pom-j8-async.mustache", "", "pom.xml")); - } return objs; } @@ -266,13 +277,15 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege this.basePackage = configPackage; } - public void setInterfaceOnly(boolean interfaceOnly) { - this.interfaceOnly = interfaceOnly; - } + public void setInterfaceOnly(boolean interfaceOnly) { this.interfaceOnly = interfaceOnly; } public void setSingleContentTypes(boolean singleContentTypes) { this.singleContentTypes = singleContentTypes; } + + public void setJava8(boolean java8) { this.java8 = java8; } + + public void setAsync(boolean async) { this.async = async; } @Override public Map postProcessModels(Map objs) { diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/api.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/api.mustache index bd0d7180529..c3b3bb66908 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/api.mustache @@ -1,12 +1,12 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - {{#imports}}import {{import}}; {{/imports}} import io.swagger.annotations.*; - +{{#java8}} +import org.springframework.http.HttpStatus; +{{/java8}} import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -18,33 +18,37 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; import java.util.List; +{{#async}} +import java.util.concurrent.Callable; +{{/async}} -import static org.springframework.http.MediaType.*; - -@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API") {{>generatedAnnotation}} +@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API") {{#operations}} public interface {{classname}} { - {{#operation}} +{{#operation}} - @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { - {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { - {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, - {{/hasMore}}{{/scopes}} - }{{/isOAuth}}){{#hasMore}}, - {{/hasMore}}{{/authMethods}} - }{{/hasAuthMethods}}) - @ApiResponses(value = { {{#responses}} - @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} }) - @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}} - produces = "{{{vendorExtensions.x-accepts}}}", - consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}} - produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} - consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} - method = RequestMethod.{{httpMethod}}) - ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}); + @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { + {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { + {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, + {{/hasMore}}{{/scopes}} + }{{/isOAuth}}){{#hasMore}}, + {{/hasMore}}{{/authMethods}} + }{{/hasAuthMethods}}) + @ApiResponses(value = { {{#responses}} + @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} }) + @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}} + produces = "{{{vendorExtensions.x-accepts}}}", + consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}} + produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} + consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} + method = RequestMethod.{{httpMethod}}) + {{#java8}}default {{/java8}}{{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, + {{/hasMore}}{{/allParams}}){{^java8}};{{/java8}}{{#java8}} { + // do some magic! + return {{#async}}() -> {{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); + }{{/java8}} - {{/operation}} +{{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/apiController.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/apiController.mustache index 0cde913d660..f9c03faafc1 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/apiController.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/apiController.mustache @@ -1,7 +1,6 @@ package {{apiPackage}}; -import {{modelPackage}}.*; - +{{^java8}} {{#imports}}import {{import}}; {{/imports}} @@ -9,7 +8,9 @@ import io.swagger.annotations.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +{{/java8}} import org.springframework.stereotype.Controller; +{{^java8}} import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -18,18 +19,26 @@ import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; import java.util.List; +{{#async}} +import java.util.concurrent.Callable; +{{/async}}{{/java8}} -@Controller {{>generatedAnnotation}} +@Controller {{#operations}} public class {{classname}}Controller implements {{classname}} { - {{#operation}} - public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, - {{/hasMore}}{{/allParams}}) { - // do some magic! - return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); - } - - {{/operation}} +{{^java8}}{{#operation}} + public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, + {{/hasMore}}{{/allParams}}) { + // do some magic!{{^async}} + return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/async}}{{#async}} + return new CallablereturnTypes}}>>() { + @Override + public ResponseEntity<{{>returnTypes}}> call() throws Exception { + return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); + } + };{{/async}} + } +{{/operation}}{{/java8}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/pom.mustache index 53c3652cb45..d3b0cbfd467 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/pom.mustache @@ -1,63 +1,78 @@ - 4.0.0 - {{groupId}} - {{artifactId}} - jar - {{artifactId}} - {{artifactVersion}} - - 2.4.0 - - - org.springframework.boot - spring-boot-starter-parent - 1.3.3.RELEASE - - - src/main/java{{^interfaceOnly}} - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - {{/interfaceOnly}} - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - io.springfox - springfox-swagger2 - ${springfox-version} - - - io.springfox - springfox-swagger-ui - ${springfox-version} - + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + 2.4.0 + {{#java8}} + 1.8 + 1.8 + {{/java8}} + + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + src/main/java + {{^interfaceOnly}} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + {{/interfaceOnly}} + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + io.springfox + springfox-swagger2 + ${springfox-version} + + + io.springfox + springfox-swagger-ui + ${springfox-version} + + {{#java8}} - - com.fasterxml.jackson.datatype - jackson-datatype-joda - - - joda-time - joda-time - - + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + {{/java8}} + {{^java8}} + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + + + joda-time + joda-time + + {{/java8}} + \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/swaggerDocumentationConfig.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/swaggerDocumentationConfig.mustache index 970739e1b97..fc4af3892c6 100644 --- a/modules/swagger-codegen/src/main/resources/JavaSpringBoot/swaggerDocumentationConfig.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaSpringBoot/swaggerDocumentationConfig.mustache @@ -30,13 +30,15 @@ public class SwaggerDocumentationConfig { @Bean public Docket customImplementation(){ - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage("{{apiPackage}}")) - .build() - .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) - .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) - .apiInfo(apiInfo()); + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("{{apiPackage}}")) + .build(){{#java8}} + .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class) + .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class){{/java8}}{{^java8}} + .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) + .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class){{/java8}} + .apiInfo(apiInfo()); } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/SpringBootServerOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/SpringBootServerOptionsProvider.java index c4b1281c1dc..a4b703d4d07 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/SpringBootServerOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/SpringBootServerOptionsProvider.java @@ -12,6 +12,8 @@ public class SpringBootServerOptionsProvider extends JavaOptionsProvider { public static final String LIBRARY_VALUE = "j8-async"; //FIXME hidding value from super class public static final String INTERFACE_ONLY = "true"; public static final String SINGLE_CONTENT_TYPES = "true"; + public static final String JAVA_8 = "true"; + public static final String ASYNC = "true"; @Override public String getLanguage() { @@ -26,6 +28,8 @@ public class SpringBootServerOptionsProvider extends JavaOptionsProvider { options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE); options.put(SpringBootServerCodegen.INTERFACE_ONLY, INTERFACE_ONLY); options.put(SpringBootServerCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES); + options.put(SpringBootServerCodegen.JAVA_8, JAVA_8); + options.put(SpringBootServerCodegen.ASYNC, ASYNC); return options; } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/springboot/SpringBootServerOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/springboot/SpringBootServerOptionsTest.java index c60ac3a582d..376a44a60b8 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/springboot/SpringBootServerOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/springboot/SpringBootServerOptionsTest.java @@ -58,6 +58,10 @@ public class SpringBootServerOptionsTest extends JavaClientOptionsTest { times = 1; clientCodegen.setSingleContentTypes(Boolean.valueOf(SpringBootServerOptionsProvider.SINGLE_CONTENT_TYPES)); times = 1; + clientCodegen.setJava8(Boolean.valueOf(SpringBootServerOptionsProvider.JAVA_8)); + times = 1; + clientCodegen.setAsync(Boolean.valueOf(SpringBootServerOptionsProvider.ASYNC)); + times = 1; }}; } diff --git a/samples/server/petstore/springboot/pom.xml b/samples/server/petstore/springboot/pom.xml index 0002871db8f..65c935c9ef6 100644 --- a/samples/server/petstore/springboot/pom.xml +++ b/samples/server/petstore/springboot/pom.xml @@ -1,63 +1,63 @@ - 4.0.0 - io.swagger - swagger-springboot-server - jar - swagger-springboot-server - 1.0.0 - - 2.4.0 - - - org.springframework.boot - spring-boot-starter-parent - 1.3.3.RELEASE - - - src/main/java - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - provided - - - - io.springfox - springfox-swagger2 - ${springfox-version} - - - io.springfox - springfox-swagger-ui - ${springfox-version} - + 4.0.0 + io.swagger + swagger-springboot-server + jar + swagger-springboot-server + 1.0.0 + + 2.4.0 + + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + io.springfox + springfox-swagger2 + ${springfox-version} + + + io.springfox + springfox-swagger-ui + ${springfox-version} + - - com.fasterxml.jackson.datatype - jackson-datatype-joda - - - joda-time - joda-time - - + + com.fasterxml.jackson.datatype + jackson-datatype-joda + + + joda-time + joda-time + + \ No newline at end of file diff --git a/samples/server/petstore/springboot/src/main/java/io/swagger/Swagger2SpringBoot.java b/samples/server/petstore/springboot/src/main/java/io/swagger/Swagger2SpringBoot.java index 4317ba2f1a6..2cc65db2b81 100644 --- a/samples/server/petstore/springboot/src/main/java/io/swagger/Swagger2SpringBoot.java +++ b/samples/server/petstore/springboot/src/main/java/io/swagger/Swagger2SpringBoot.java @@ -33,4 +33,4 @@ public class Swagger2SpringBoot implements CommandLineRunner { } } -} +} \ 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 bb63b7e11d6..f0f76394bf3 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,13 +1,10 @@ package io.swagger.api; -import io.swagger.model.*; - import io.swagger.model.Pet; import io.swagger.model.ModelApiResponse; import java.io.File; import io.swagger.annotations.*; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -20,133 +17,131 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -import static org.springframework.http.MediaType.*; @Api(value = "pet", description = "the pet API") - public interface PetApi { - @ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.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") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) - @RequestMapping(value = "/pet", - 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" ,required=true ) @RequestBody Pet body); + @ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.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") + }) + }) + @ApiResponses(value = { + @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) + @RequestMapping(value = "/pet", + 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" ,required=true ) @RequestBody Pet body); - @ApiOperation(value = "Deletes a pet", notes = "", response = Void.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") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) }) - @RequestMapping(value = "/pet/{petId}", - 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); + @ApiOperation(value = "Deletes a pet", notes = "", response = Void.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") + }) + }) + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) }) + @RequestMapping(value = "/pet/{petId}", + 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); - @ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }) - @ApiResponses(value = { - @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/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List status); + @ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + }) + @ApiResponses(value = { + @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/xml", "application/json" }, + method = RequestMethod.GET) + ResponseEntity> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @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 = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }) - @ApiResponses(value = { - @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/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags); + @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 = { + @Authorization(value = "petstore_auth", scopes = { + @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), + @AuthorizationScope(scope = "read:pets", description = "read your pets") + }) + }) + @ApiResponses(value = { + @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/xml", "application/json" }, + method = RequestMethod.GET) + ResponseEntity> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags); - @ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { - @Authorization(value = "api_key") - }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @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/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId); + @ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { + @Authorization(value = "api_key") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Pet.class), + @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/xml", "application/json" }, + method = RequestMethod.GET) + 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 = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), - @ApiResponse(code = 404, message = "Pet not found", response = Void.class), - @ApiResponse(code = 405, message = "Validation exception", response = Void.class) }) - @RequestMapping(value = "/pet", - 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" ,required=true ) @RequestBody Pet body); + @ApiOperation(value = "Update an existing pet", notes = "", response = Void.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") + }) + }) + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), + @ApiResponse(code = 404, message = "Pet not found", response = Void.class), + @ApiResponse(code = 405, message = "Validation exception", response = Void.class) }) + @RequestMapping(value = "/pet", + 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" ,required=true ) @RequestBody Pet body); - @ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.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") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) - @RequestMapping(value = "/pet/{petId}", - 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") 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 = "Updates a pet in the store with form data", notes = "", response = Void.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") + }) + }) + @ApiResponses(value = { + @ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) + @RequestMapping(value = "/pet/{petId}", + 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") 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 = 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") - }) - }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) }) - @RequestMapping(value = "/pet/{petId}/uploadImage", - 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); + @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") + }) + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) }) + @RequestMapping(value = "/pet/{petId}/uploadImage", + 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); } 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 ec3bbf3e747..3a2dcab47b6 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,7 +1,5 @@ package io.swagger.api; -import io.swagger.model.*; - import io.swagger.model.Pet; import io.swagger.model.ModelApiResponse; import java.io.File; @@ -20,52 +18,54 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -@Controller + +@Controller public class PetApiController implements PetApi { + 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); - } + // 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); - } + @ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) { + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List status) { - // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity>(HttpStatus.OK); + } public ResponseEntity> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List tags) { - // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity>(HttpStatus.OK); + } public ResponseEntity getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } 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); - } + // 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); - } + @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) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + @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); + } } 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 2fb7585dbdd..f67745dfa32 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 @@ -1,12 +1,9 @@ package io.swagger.api; -import io.swagger.model.*; - import java.util.Map; import io.swagger.model.Order; import io.swagger.annotations.*; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -19,51 +16,49 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -import static org.springframework.http.MediaType.*; @Api(value = "store", description = "the store API") - public interface StoreApi { - @ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class) - @ApiResponses(value = { - @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/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); + @ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class) + @ApiResponses(value = { + @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/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); - @ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = { - @Authorization(value = "api_key") - }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) - @RequestMapping(value = "/store/inventory", - produces = { "application/json" }, - method = RequestMethod.GET) - ResponseEntity> getInventory(); + @ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = { + @Authorization(value = "api_key") + }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) + @RequestMapping(value = "/store/inventory", + produces = { "application/json" }, + method = RequestMethod.GET) + ResponseEntity> getInventory(); - @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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Order.class), - @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/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId); + @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) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Order.class), + @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/xml", "application/json" }, + method = RequestMethod.GET) + ResponseEntity getOrderById(@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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Order.class), - @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) - @RequestMapping(value = "/store/order", - produces = { "application/xml", "application/json" }, - method = RequestMethod.POST) - ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body); + @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Order.class), + @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) + @RequestMapping(value = "/store/order", + produces = { "application/xml", "application/json" }, + method = RequestMethod.POST) + 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 92de5eb86b4..bd582ae1a94 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 @@ -1,7 +1,5 @@ package io.swagger.api; -import io.swagger.model.*; - import java.util.Map; import io.swagger.model.Order; @@ -19,27 +17,29 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -@Controller + +@Controller public class StoreApiController implements StoreApi { + public ResponseEntity deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity> getInventory() { - // do some magic! - return new ResponseEntity>(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity>(HttpStatus.OK); + } public ResponseEntity getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // 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 3877be4e8ad..508a5c1863d 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 @@ -1,12 +1,9 @@ package io.swagger.api; -import io.swagger.model.*; - import io.swagger.model.User; import java.util.List; import io.swagger.annotations.*; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -19,88 +16,86 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -import static org.springframework.http.MediaType.*; @Api(value = "user", description = "the user API") - public interface UserApi { - @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) - @RequestMapping(value = "/user", - produces = { "application/xml", "application/json" }, - method = RequestMethod.POST) - ResponseEntity createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body); + @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) + @RequestMapping(value = "/user", + produces = { "application/xml", "application/json" }, + method = RequestMethod.POST) + 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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) - @RequestMapping(value = "/user/createWithArray", - produces = { "application/xml", "application/json" }, - method = RequestMethod.POST) - 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) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) + @RequestMapping(value = "/user/createWithArray", + produces = { "application/xml", "application/json" }, + method = RequestMethod.POST) + 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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) - @RequestMapping(value = "/user/createWithList", - produces = { "application/xml", "application/json" }, - method = RequestMethod.POST) - ResponseEntity createUsersWithListInput(@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) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) + @RequestMapping(value = "/user/createWithList", + produces = { "application/xml", "application/json" }, + method = RequestMethod.POST) + 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) - @ApiResponses(value = { - @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/xml", "application/json" }, - method = RequestMethod.DELETE) - ResponseEntity deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username); + @ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { + @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/xml", "application/json" }, + method = RequestMethod.DELETE) + ResponseEntity deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username); - @ApiOperation(value = "Get user by user name", notes = "", response = User.class) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = User.class), - @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/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); + @ApiOperation(value = "Get user by user name", notes = "", response = User.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = User.class), + @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/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); - @ApiOperation(value = "Logs user into the system", notes = "", response = String.class) - @ApiResponses(value = { - @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/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, - @ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password); + @ApiOperation(value = "Logs user into the system", notes = "", response = String.class) + @ApiResponses(value = { + @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/xml", "application/json" }, + method = RequestMethod.GET) + ResponseEntity loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, + @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) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) - @RequestMapping(value = "/user/logout", - produces = { "application/xml", "application/json" }, - method = RequestMethod.GET) - ResponseEntity logoutUser(); + @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = Void.class) }) + @RequestMapping(value = "/user/logout", + produces = { "application/xml", "application/json" }, + method = RequestMethod.GET) + ResponseEntity logoutUser(); - @ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class) - @ApiResponses(value = { - @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/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" ,required=true ) @RequestBody User body); + @ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { + @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/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" ,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 f855d358ea5..a5a6d4d4505 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 @@ -1,7 +1,5 @@ package io.swagger.api; -import io.swagger.model.*; - import io.swagger.model.User; import java.util.List; @@ -19,49 +17,51 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; -@Controller + +@Controller public class UserApiController implements UserApi { + public ResponseEntity createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List body) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // 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); - } + // 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) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // do some magic! + return new ResponseEntity(HttpStatus.OK); + } public ResponseEntity loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, - @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); - } + @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); + } public ResponseEntity logoutUser() { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + // 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 ) @RequestBody User body) { - // do some magic! - return new ResponseEntity(HttpStatus.OK); - } + @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 282773a2d30..29c6a7bf85f 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 @@ -30,13 +30,13 @@ public class SwaggerDocumentationConfig { @Bean public Docket customImplementation(){ - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage("io.swagger.api")) - .build() - .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) - .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) - .apiInfo(apiInfo()); + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("io.swagger.api")) + .build() + .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) + .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) + .apiInfo(apiInfo()); } }