add java8 and async options to springboot codegen

This commit is contained in:
cbornet 2016-06-10 17:12:56 +02:00
parent 851f2ef688
commit c2dbe44d08
16 changed files with 525 additions and 489 deletions

View File

@ -12,11 +12,15 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege
public static final String BASE_PACKAGE = "basePackage"; public static final String BASE_PACKAGE = "basePackage";
public static final String INTERFACE_ONLY = "interfaceOnly"; public static final String INTERFACE_ONLY = "interfaceOnly";
public static final String SINGLE_CONTENT_TYPES = "singleContentTypes"; 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 title = "Petstore Server";
protected String configPackage = ""; protected String configPackage = "";
protected String basePackage = ""; protected String basePackage = "";
protected boolean interfaceOnly = false; protected boolean interfaceOnly = false;
protected boolean singleContentTypes = false; protected boolean singleContentTypes = false;
protected boolean java8 = false;
protected boolean async = false;
protected String templateFileName = "api.mustache"; protected String templateFileName = "api.mustache";
public SpringBootServerCodegen() { 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(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(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(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.clear();
supportedLibraries.put(DEFAULT_LIBRARY, "Default Spring Boot server stub."); 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 " + 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 @Override
@ -92,11 +99,19 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege
this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString())); 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.clear();
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")); supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
if(!this.interfaceOnly) { if (!this.interfaceOnly) {
apiTemplateFiles.put("apiController.mustache", "Controller.java"); apiTemplateFiles.put("apiController.mustache", "Controller.java");
supportingFiles.add(new SupportingFile("apiException.mustache", supportingFiles.add(new SupportingFile("apiException.mustache",
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java")); (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", supportingFiles.add(new SupportingFile("application.properties",
("src.main.resources").replace(".", java.io.File.separator), "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 @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; return objs;
} }
@ -266,14 +277,16 @@ public class SpringBootServerCodegen extends JavaClientCodegen implements Codege
this.basePackage = configPackage; this.basePackage = configPackage;
} }
public void setInterfaceOnly(boolean interfaceOnly) { public void setInterfaceOnly(boolean interfaceOnly) { this.interfaceOnly = interfaceOnly; }
this.interfaceOnly = interfaceOnly;
}
public void setSingleContentTypes(boolean singleContentTypes) { public void setSingleContentTypes(boolean singleContentTypes) {
this.singleContentTypes = singleContentTypes; this.singleContentTypes = singleContentTypes;
} }
public void setJava8(boolean java8) { this.java8 = java8; }
public void setAsync(boolean async) { this.async = async; }
@Override @Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) { public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// remove the import of "Object" to avoid compilation error // remove the import of "Object" to avoid compilation error

View File

@ -1,12 +1,12 @@
package {{apiPackage}}; package {{apiPackage}};
import {{modelPackage}}.*;
{{#imports}}import {{import}}; {{#imports}}import {{import}};
{{/imports}} {{/imports}}
import io.swagger.annotations.*; import io.swagger.annotations.*;
{{#java8}}
import org.springframework.http.HttpStatus;
{{/java8}}
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; 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 org.springframework.web.multipart.MultipartFile;
import java.util.List; 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}} {{>generatedAnnotation}}
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
{{#operations}} {{#operations}}
public interface {{classname}} { public interface {{classname}} {
{{#operation}} {{#operation}}
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = { @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = { {{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}}, {{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
{{/hasMore}}{{/scopes}} {{/hasMore}}{{/scopes}}
}{{/isOAuth}}){{#hasMore}}, }{{/isOAuth}}){{#hasMore}},
{{/hasMore}}{{/authMethods}} {{/hasMore}}{{/authMethods}}
}{{/hasAuthMethods}}) }{{/hasAuthMethods}})
@ApiResponses(value = { {{#responses}} @ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} }) @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} })
@RequestMapping(value = "{{{path}}}",{{#singleContentTypes}} @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}
produces = "{{{vendorExtensions.x-accepts}}}", produces = "{{{vendorExtensions.x-accepts}}}",
consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}} consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
method = RequestMethod.{{httpMethod}}) method = RequestMethod.{{httpMethod}})
ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{#java8}}default {{/java8}}{{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
{{/hasMore}}{{/allParams}}); {{/hasMore}}{{/allParams}}){{^java8}};{{/java8}}{{#java8}} {
// do some magic!
return {{#async}}() -> {{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
}{{/java8}}
{{/operation}} {{/operation}}
} }
{{/operations}} {{/operations}}

View File

@ -1,7 +1,6 @@
package {{apiPackage}}; package {{apiPackage}};
import {{modelPackage}}.*; {{^java8}}
{{#imports}}import {{import}}; {{#imports}}import {{import}};
{{/imports}} {{/imports}}
@ -9,7 +8,9 @@ import io.swagger.annotations.*;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
{{/java8}}
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
{{^java8}}
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; 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 org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
{{#async}}
import java.util.concurrent.Callable;
{{/async}}{{/java8}}
@Controller
{{>generatedAnnotation}} {{>generatedAnnotation}}
@Controller
{{#operations}} {{#operations}}
public class {{classname}}Controller implements {{classname}} { public class {{classname}}Controller implements {{classname}} {
{{#operation}} {{^java8}}{{#operation}}
public ResponseEntity<{{>returnTypes}}> {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
{{/hasMore}}{{/allParams}}) { {{/hasMore}}{{/allParams}}) {
// do some magic! // do some magic!{{^async}}
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK); return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/async}}{{#async}}
} return new Callable<ResponseEntity<{{>returnTypes}}>>() {
@Override
{{/operation}} public ResponseEntity<{{>returnTypes}}> call() throws Exception {
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
}
};{{/async}}
}
{{/operation}}{{/java8}}
} }
{{/operations}} {{/operations}}

View File

@ -1,63 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>{{groupId}}</groupId> <groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId> <artifactId>{{artifactId}}</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>{{artifactId}}</name> <name>{{artifactId}}</name>
<version>{{artifactVersion}}</version> <version>{{artifactVersion}}</version>
<properties> <properties>
<springfox-version>2.4.0</springfox-version> <springfox-version>2.4.0</springfox-version>
</properties> {{#java8}}
<parent> <maven.compiler.source>1.8</maven.compiler.source>
<groupId>org.springframework.boot</groupId> <maven.compiler.target>1.8</maven.compiler.target>
<artifactId>spring-boot-starter-parent</artifactId> {{/java8}}
<version>1.3.3.RELEASE</version> </properties>
</parent> <parent>
<build> <groupId>org.springframework.boot</groupId>
<sourceDirectory>src/main/java</sourceDirectory>{{^interfaceOnly}} <artifactId>spring-boot-starter-parent</artifactId>
<plugins> <version>1.3.3.RELEASE</version>
<plugin> </parent>
<groupId>org.springframework.boot</groupId> <build>
<artifactId>spring-boot-maven-plugin</artifactId> <sourceDirectory>src/main/java</sourceDirectory>
<executions> {{^interfaceOnly}}
<execution> <plugins>
<goals> <plugin>
<goal>repackage</goal> <groupId>org.springframework.boot</groupId>
</goals> <artifactId>spring-boot-maven-plugin</artifactId>
</execution> <executions>
</executions> <execution>
</plugin> <goals>
</plugins>{{/interfaceOnly}} <goal>repackage</goal>
</build> </goals>
<dependencies> </execution>
<dependency> </executions>
<groupId>org.springframework.boot</groupId> </plugin>
<artifactId>spring-boot-starter-web</artifactId> </plugins>
</dependency> {{/interfaceOnly}}
<dependency> </build>
<groupId>org.springframework.boot</groupId> <dependencies>
<artifactId>spring-boot-starter-tomcat</artifactId> <dependency>
<scope>provided</scope> <groupId>org.springframework.boot</groupId>
</dependency> <artifactId>spring-boot-starter-web</artifactId>
<!--SpringFox dependencies --> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
<version>${springfox-version}</version> <scope>provided</scope>
</dependency> </dependency>
<dependency> <!--SpringFox dependencies -->
<groupId>io.springfox</groupId> <dependency>
<artifactId>springfox-swagger-ui</artifactId> <groupId>io.springfox</groupId>
<version>${springfox-version}</version> <artifactId>springfox-swagger2</artifactId>
</dependency> <version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
{{#java8}}
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
</dependency> </dependency>
<dependency> {{/java8}}
<groupId>joda-time</groupId> {{^java8}}
<artifactId>joda-time</artifactId>
</dependency> <dependency>
</dependencies> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
{{/java8}}
</dependencies>
</project> </project>

View File

@ -30,13 +30,15 @@ public class SwaggerDocumentationConfig {
@Bean @Bean
public Docket customImplementation(){ public Docket customImplementation(){
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.select() .select()
.apis(RequestHandlerSelectors.basePackage("{{apiPackage}}")) .apis(RequestHandlerSelectors.basePackage("{{apiPackage}}"))
.build() .build(){{#java8}}
.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class){{/java8}}{{^java8}}
.apiInfo(apiInfo()); .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class){{/java8}}
.apiInfo(apiInfo());
} }
} }

View File

@ -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 LIBRARY_VALUE = "j8-async"; //FIXME hidding value from super class
public static final String INTERFACE_ONLY = "true"; public static final String INTERFACE_ONLY = "true";
public static final String SINGLE_CONTENT_TYPES = "true"; public static final String SINGLE_CONTENT_TYPES = "true";
public static final String JAVA_8 = "true";
public static final String ASYNC = "true";
@Override @Override
public String getLanguage() { public String getLanguage() {
@ -26,6 +28,8 @@ public class SpringBootServerOptionsProvider extends JavaOptionsProvider {
options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE); options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE);
options.put(SpringBootServerCodegen.INTERFACE_ONLY, INTERFACE_ONLY); options.put(SpringBootServerCodegen.INTERFACE_ONLY, INTERFACE_ONLY);
options.put(SpringBootServerCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES); options.put(SpringBootServerCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES);
options.put(SpringBootServerCodegen.JAVA_8, JAVA_8);
options.put(SpringBootServerCodegen.ASYNC, ASYNC);
return options; return options;
} }

View File

@ -58,6 +58,10 @@ public class SpringBootServerOptionsTest extends JavaClientOptionsTest {
times = 1; times = 1;
clientCodegen.setSingleContentTypes(Boolean.valueOf(SpringBootServerOptionsProvider.SINGLE_CONTENT_TYPES)); clientCodegen.setSingleContentTypes(Boolean.valueOf(SpringBootServerOptionsProvider.SINGLE_CONTENT_TYPES));
times = 1; times = 1;
clientCodegen.setJava8(Boolean.valueOf(SpringBootServerOptionsProvider.JAVA_8));
times = 1;
clientCodegen.setAsync(Boolean.valueOf(SpringBootServerOptionsProvider.ASYNC));
times = 1;
}}; }};
} }

View File

@ -1,63 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-springboot-server</artifactId> <artifactId>swagger-springboot-server</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>swagger-springboot-server</name> <name>swagger-springboot-server</name>
<version>1.0.0</version> <version>1.0.0</version>
<properties> <properties>
<springfox-version>2.4.0</springfox-version> <springfox-version>2.4.0</springfox-version>
</properties> </properties>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version> <version>1.3.3.RELEASE</version>
</parent> </parent>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<goals> <goals>
<goal>repackage</goal> <goal>repackage</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--SpringFox dependencies --> <!--SpringFox dependencies -->
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version> <version>${springfox-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId> <artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version> <version>${springfox-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId> <artifactId>jackson-datatype-joda</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,13 +1,10 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import io.swagger.model.Pet; import io.swagger.model.Pet;
import io.swagger.model.ModelApiResponse; import io.swagger.model.ModelApiResponse;
import java.io.File; import java.io.File;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -20,133 +17,131 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import static org.springframework.http.MediaType.*;
@Api(value = "pet", description = "the pet API") @Api(value = "pet", description = "the pet API")
public interface PetApi { public interface PetApi {
@ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class, authorizations = { @ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class, authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) @ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
@RequestMapping(value = "/pet", @RequestMapping(value = "/pet",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/json", "application/xml" }, consumes = { "application/json", "application/xml" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body); ResponseEntity<Void> 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 = { @ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) }) @ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) })
@RequestMapping(value = "/pet/{petId}", @RequestMapping(value = "/pet/{petId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
ResponseEntity<Void> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId, ResponseEntity<Void> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId,
@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey); @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 = { @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 = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class), @ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) }) @ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) })
@RequestMapping(value = "/pet/findByStatus", @RequestMapping(value = "/pet/findByStatus",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<List<Pet>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> status); ResponseEntity<List<Pet>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> 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 = { @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 = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class), @ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) }) @ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) })
@RequestMapping(value = "/pet/findByTags", @RequestMapping(value = "/pet/findByTags",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<List<Pet>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags); ResponseEntity<List<Pet>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags);
@ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = { @ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = {
@Authorization(value = "api_key") @Authorization(value = "api_key")
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class), @ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class), @ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class),
@ApiResponse(code = 404, message = "Pet not found", response = Pet.class) }) @ApiResponse(code = 404, message = "Pet not found", response = Pet.class) })
@RequestMapping(value = "/pet/{petId}", @RequestMapping(value = "/pet/{petId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<Pet> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId); ResponseEntity<Pet> 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 = { @ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
@ApiResponse(code = 404, message = "Pet not found", response = Void.class), @ApiResponse(code = 404, message = "Pet not found", response = Void.class),
@ApiResponse(code = 405, message = "Validation exception", response = Void.class) }) @ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
@RequestMapping(value = "/pet", @RequestMapping(value = "/pet",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/json", "application/xml" }, consumes = { "application/json", "application/xml" },
method = RequestMethod.PUT) method = RequestMethod.PUT)
ResponseEntity<Void> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body); ResponseEntity<Void> 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 = { @ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input", response = Void.class) }) @ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
@RequestMapping(value = "/pet/{petId}", @RequestMapping(value = "/pet/{petId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/x-www-form-urlencoded" }, consumes = { "application/x-www-form-urlencoded" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Void> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId, ResponseEntity<Void> 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 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); @ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status);
@ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = { @ApiOperation(value = "uploads an image", notes = "", response = ModelApiResponse.class, authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {
@AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
@AuthorizationScope(scope = "read:pets", description = "read your pets") @AuthorizationScope(scope = "read:pets", description = "read your pets")
}) })
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) }) @ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })
@RequestMapping(value = "/pet/{petId}/uploadImage", @RequestMapping(value = "/pet/{petId}/uploadImage",
produces = { "application/json" }, produces = { "application/json" },
consumes = { "multipart/form-data" }, consumes = { "multipart/form-data" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, ResponseEntity<ModelApiResponse> 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 = "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);
} }

View File

@ -1,7 +1,5 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import io.swagger.model.Pet; import io.swagger.model.Pet;
import io.swagger.model.ModelApiResponse; import io.swagger.model.ModelApiResponse;
import java.io.File; import java.io.File;
@ -20,52 +18,54 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@Controller
@Controller
public class PetApiController implements PetApi { public class PetApiController implements PetApi {
public ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { public ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId, public ResponseEntity<Void> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId,
@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) { @ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<List<Pet>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> status) { public ResponseEntity<List<Pet>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> status) {
// do some magic! // do some magic!
return new ResponseEntity<List<Pet>>(HttpStatus.OK); return new ResponseEntity<List<Pet>>(HttpStatus.OK);
} }
public ResponseEntity<List<Pet>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags) { public ResponseEntity<List<Pet>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags) {
// do some magic! // do some magic!
return new ResponseEntity<List<Pet>>(HttpStatus.OK); return new ResponseEntity<List<Pet>>(HttpStatus.OK);
} }
public ResponseEntity<Pet> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) { public ResponseEntity<Pet> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) {
// do some magic! // do some magic!
return new ResponseEntity<Pet>(HttpStatus.OK); return new ResponseEntity<Pet>(HttpStatus.OK);
} }
public ResponseEntity<Void> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { public ResponseEntity<Void> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId, public ResponseEntity<Void> 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 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) { @ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, public ResponseEntity<ModelApiResponse> 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 = "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) {
// do some magic! // do some magic!
return new ResponseEntity<ModelApiResponse>(HttpStatus.OK); return new ResponseEntity<ModelApiResponse>(HttpStatus.OK);
} }
} }

View File

@ -1,12 +1,9 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import java.util.Map; import java.util.Map;
import io.swagger.model.Order; import io.swagger.model.Order;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -19,51 +16,49 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import static org.springframework.http.MediaType.*;
@Api(value = "store", description = "the store API") @Api(value = "store", description = "the store API")
public interface StoreApi { 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) @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 = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class), @ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
@ApiResponse(code = 404, message = "Order not found", response = Void.class) }) @ApiResponse(code = 404, message = "Order not found", response = Void.class) })
@RequestMapping(value = "/store/order/{orderId}", @RequestMapping(value = "/store/order/{orderId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId); ResponseEntity<Void> 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 = { @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") @Authorization(value = "api_key")
}) })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) @ApiResponse(code = 200, message = "successful operation", response = Integer.class) })
@RequestMapping(value = "/store/inventory", @RequestMapping(value = "/store/inventory",
produces = { "application/json" }, produces = { "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<Map<String, Integer>> getInventory(); ResponseEntity<Map<String, Integer>> 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) @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 = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class), @ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class), @ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class),
@ApiResponse(code = 404, message = "Order not found", response = Order.class) }) @ApiResponse(code = 404, message = "Order not found", response = Order.class) })
@RequestMapping(value = "/store/order/{orderId}", @RequestMapping(value = "/store/order/{orderId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<Order> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId); ResponseEntity<Order> 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) @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class), @ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) })
@RequestMapping(value = "/store/order", @RequestMapping(value = "/store/order",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body); ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body);
} }

View File

@ -1,7 +1,5 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import java.util.Map; import java.util.Map;
import io.swagger.model.Order; import io.swagger.model.Order;
@ -19,27 +17,29 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@Controller
@Controller
public class StoreApiController implements StoreApi { public class StoreApiController implements StoreApi {
public ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId) { public ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Map<String, Integer>> getInventory() { public ResponseEntity<Map<String, Integer>> getInventory() {
// do some magic! // do some magic!
return new ResponseEntity<Map<String, Integer>>(HttpStatus.OK); return new ResponseEntity<Map<String, Integer>>(HttpStatus.OK);
} }
public ResponseEntity<Order> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) { public ResponseEntity<Order> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) {
// do some magic! // do some magic!
return new ResponseEntity<Order>(HttpStatus.OK); return new ResponseEntity<Order>(HttpStatus.OK);
} }
public ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) { public ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) {
// do some magic! // do some magic!
return new ResponseEntity<Order>(HttpStatus.OK); return new ResponseEntity<Order>(HttpStatus.OK);
} }
} }

View File

@ -1,12 +1,9 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import io.swagger.model.User; import io.swagger.model.User;
import java.util.List; import java.util.List;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -19,88 +16,86 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import static org.springframework.http.MediaType.*;
@Api(value = "user", description = "the user API") @Api(value = "user", description = "the user API")
public interface UserApi { public interface UserApi {
@ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class) @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @ApiResponse(code = 200, message = "successful operation", response = Void.class) })
@RequestMapping(value = "/user", @RequestMapping(value = "/user",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body); ResponseEntity<Void> 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) @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @ApiResponse(code = 200, message = "successful operation", response = Void.class) })
@RequestMapping(value = "/user/createWithArray", @RequestMapping(value = "/user/createWithArray",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Void> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body); ResponseEntity<Void> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
@ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class) @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @ApiResponse(code = 200, message = "successful operation", response = Void.class) })
@RequestMapping(value = "/user/createWithList", @RequestMapping(value = "/user/createWithList",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
ResponseEntity<Void> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body); ResponseEntity<Void> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
@ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class) @ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid username supplied", response = Void.class), @ApiResponse(code = 400, message = "Invalid username supplied", response = Void.class),
@ApiResponse(code = 404, message = "User not found", response = Void.class) }) @ApiResponse(code = 404, message = "User not found", response = Void.class) })
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
ResponseEntity<Void> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username); ResponseEntity<Void> 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) @ApiOperation(value = "Get user by user name", notes = "", response = User.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = User.class), @ApiResponse(code = 200, message = "successful operation", response = User.class),
@ApiResponse(code = 400, message = "Invalid username supplied", response = User.class), @ApiResponse(code = 400, message = "Invalid username supplied", response = User.class),
@ApiResponse(code = 404, message = "User not found", response = User.class) }) @ApiResponse(code = 404, message = "User not found", response = User.class) })
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<User> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username); ResponseEntity<User> 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) @ApiOperation(value = "Logs user into the system", notes = "", response = String.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class), @ApiResponse(code = 200, message = "successful operation", response = String.class),
@ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) }) @ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) })
@RequestMapping(value = "/user/login", @RequestMapping(value = "/user/login",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<String> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, ResponseEntity<String> 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); @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) @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Void.class) }) @ApiResponse(code = 200, message = "successful operation", response = Void.class) })
@RequestMapping(value = "/user/logout", @RequestMapping(value = "/user/logout",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
ResponseEntity<Void> logoutUser(); ResponseEntity<Void> logoutUser();
@ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class) @ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class)
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class), @ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class),
@ApiResponse(code = 404, message = "User not found", response = Void.class) }) @ApiResponse(code = 404, message = "User not found", response = Void.class) })
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.PUT) method = RequestMethod.PUT)
ResponseEntity<Void> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, ResponseEntity<Void> 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); @ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body);
} }

View File

@ -1,7 +1,5 @@
package io.swagger.api; package io.swagger.api;
import io.swagger.model.*;
import io.swagger.model.User; import io.swagger.model.User;
import java.util.List; import java.util.List;
@ -19,49 +17,51 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@Controller
@Controller
public class UserApiController implements UserApi { public class UserApiController implements UserApi {
public ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) { public ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) { public ResponseEntity<Void> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) { public ResponseEntity<Void> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username) { public ResponseEntity<Void> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<User> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) { public ResponseEntity<User> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) {
// do some magic! // do some magic!
return new ResponseEntity<User>(HttpStatus.OK); return new ResponseEntity<User>(HttpStatus.OK);
} }
public ResponseEntity<String> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, public ResponseEntity<String> 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) { @ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password) {
// do some magic! // do some magic!
return new ResponseEntity<String>(HttpStatus.OK); return new ResponseEntity<String>(HttpStatus.OK);
} }
public ResponseEntity<Void> logoutUser() { public ResponseEntity<Void> logoutUser() {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
public ResponseEntity<Void> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, public ResponseEntity<Void> 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) { @ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body) {
// do some magic! // do some magic!
return new ResponseEntity<Void>(HttpStatus.OK); return new ResponseEntity<Void>(HttpStatus.OK);
} }
} }

View File

@ -30,13 +30,13 @@ public class SwaggerDocumentationConfig {
@Bean @Bean
public Docket customImplementation(){ public Docket customImplementation(){
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.select() .select()
.apis(RequestHandlerSelectors.basePackage("io.swagger.api")) .apis(RequestHandlerSelectors.basePackage("io.swagger.api"))
.build() .build()
.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class)
.apiInfo(apiInfo()); .apiInfo(apiInfo());
} }
} }