diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java index ef87ed93b05..c8043f5b867 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaPlayFrameworkCodegen.java @@ -1,7 +1,11 @@ package io.swagger.codegen.languages; +import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.codegen.*; import io.swagger.codegen.languages.features.BeanValidationFeatures; +import io.swagger.models.Model; +import io.swagger.models.Swagger; +import io.swagger.util.Json; import java.io.File; import java.util.List; @@ -13,18 +17,16 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea public static final String CONFIG_PACKAGE = "configPackage"; public static final String BASE_PACKAGE = "basePackage"; public static final String CONTROLLER_ONLY = "controllerOnly"; - public static final String SINGLE_CONTENT_TYPES = "singleContentTypes"; - public static final String RESPONSE_WRAPPER = "responseWrapper"; - public static final String USE_TAGS = "useTags"; + public static final String USE_INTERFACES = "useInterfaces"; + public static final String HANDLE_EXCEPTIONS = "handleExceptions"; protected String title = "swagger-petstore"; protected String configPackage = "io.swagger.configuration"; protected String basePackage = "io.swagger"; protected boolean controllerOnly = false; - protected boolean singleContentTypes = false; - protected String responseWrapper = ""; - protected boolean useTags = false; + protected boolean useInterfaces = true; protected boolean useBeanValidation = true; + protected boolean handleExceptions = true; public JavaPlayFrameworkCodegen() { super(); @@ -49,11 +51,12 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea cliOptions.add(new CliOption(TITLE, "server title name or client service name")); cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code")); cliOptions.add(new CliOption(BASE_PACKAGE, "base package for generated code")); - cliOptions.add(CliOption.newBoolean(CONTROLLER_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(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)")); - cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames")); - cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations")); + + //Custom options for this generator + cliOptions.add(createBooleanCliWithDefault(CONTROLLER_ONLY, "Whether to generate only API interface stubs without the server files.", controllerOnly)); + cliOptions.add(createBooleanCliWithDefault(USE_BEANVALIDATION, "Use BeanValidation API annotations", useBeanValidation)); + cliOptions.add(createBooleanCliWithDefault(USE_INTERFACES, "Makes the controllerImp implements an interface to facilitate automatic completion when updating from version x to y of your spec", useInterfaces)); + cliOptions.add(createBooleanCliWithDefault(HANDLE_EXCEPTIONS, "Add a wrapper to each controller to handle exceptions that pop in the controller", handleExceptions)); } @Override @@ -94,33 +97,38 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea } if (additionalProperties.containsKey(CONTROLLER_ONLY)) { - this.setControllerOnly(Boolean.valueOf(additionalProperties.get(CONTROLLER_ONLY).toString())); - } - - if (additionalProperties.containsKey(SINGLE_CONTENT_TYPES)) { - this.setSingleContentTypes(Boolean.valueOf(additionalProperties.get(SINGLE_CONTENT_TYPES).toString())); - } - - if (additionalProperties.containsKey(RESPONSE_WRAPPER)) { - this.setResponseWrapper((String) additionalProperties.get(RESPONSE_WRAPPER)); - } - - if (additionalProperties.containsKey(USE_TAGS)) { - this.setUseTags(Boolean.valueOf(additionalProperties.get(USE_TAGS).toString())); + this.setControllerOnly(convertPropertyToBoolean(CONTROLLER_ONLY)); + } else { + writePropertyBack(CONTROLLER_ONLY, controllerOnly); } if (additionalProperties.containsKey(USE_BEANVALIDATION)) { this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION)); - } - - if (useBeanValidation) { + } else { writePropertyBack(USE_BEANVALIDATION, useBeanValidation); } + if (additionalProperties.containsKey(USE_INTERFACES)) { + this.setUseInterfaces(convertPropertyToBoolean(USE_INTERFACES)); + } else { + writePropertyBack(USE_INTERFACES, useInterfaces); + } + + if (additionalProperties.containsKey(HANDLE_EXCEPTIONS)) { + this.setHandleExceptions(convertPropertyToBoolean(HANDLE_EXCEPTIONS)); + } else { + writePropertyBack(HANDLE_EXCEPTIONS, handleExceptions); + } + + //We don't use annotation anymore + importMapping.remove("ApiModelProperty"); + importMapping.remove("ApiModel"); + //Root folder supportingFiles.add(new SupportingFile("README.mustache", "", "README")); supportingFiles.add(new SupportingFile("LICENSE.mustache", "", "LICENSE")); supportingFiles.add(new SupportingFile("build.mustache", "", "build.sbt")); + supportingFiles.add(new SupportingFile("swagger.mustache", "public", "swagger.json")); //Project folder supportingFiles.add(new SupportingFile("buildproperties.mustache", "project", "build.properties")); @@ -133,6 +141,9 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea //App/Utils folder supportingFiles.add(new SupportingFile("swaggerUtils.mustache", "app/swagger", "SwaggerUtils.java")); + if (this.handleExceptions) { + supportingFiles.add(new SupportingFile("apiCall.mustache", "app/swagger", "ApiCall.java")); + } //App/Controllers supportingFiles.add(new SupportingFile("apiDocController.mustache", "app/controllers", "ApiDocController.java")); @@ -143,6 +154,9 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea if (!this.controllerOnly) { apiTemplateFiles.put("newApi.mustache", "ControllerImp.java"); } + if (this.useInterfaces) { + apiTemplateFiles.put("newApiInterface.mustache", "ControllerImpInterface.java"); + } additionalProperties.put("javaVersion", "1.8"); additionalProperties.put("jdk8", "true"); @@ -150,17 +164,24 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea typeMapping.put("DateTime", "OffsetDateTime"); importMapping.put("LocalDate", "java.time.LocalDate"); importMapping.put("OffsetDateTime", "java.time.OffsetDateTime"); + } - // Some well-known Spring or Spring-Cloud response wrappers - switch (this.responseWrapper) { - case "Future": - case "Callable": - case "CompletableFuture": - additionalProperties.put(RESPONSE_WRAPPER, "java.util.concurrent" + this.responseWrapper); - break; - default: - break; + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + + //We don't use annotation anymore + model.imports.remove("ApiModelProperty"); + model.imports.remove("ApiModel"); + } + + @Override + public CodegenModel fromModel(String name, Model model, Map allDefinitions) { + CodegenModel codegenModel = super.fromModel(name, model, allDefinitions); + if(codegenModel.description != null) { + codegenModel.imports.remove("ApiModel"); } + return codegenModel; } public void setTitle(String title) { @@ -177,14 +198,16 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea public void setControllerOnly(boolean controllerOnly) { this.controllerOnly = controllerOnly; } - public void setSingleContentTypes(boolean singleContentTypes) { - this.singleContentTypes = singleContentTypes; + public void setUseInterfaces(boolean useInterfaces) { + this.useInterfaces = useInterfaces; } - public void setResponseWrapper(String responseWrapper) { this.responseWrapper = responseWrapper; } + public void setUseBeanValidation(boolean useBeanValidation) { + this.useBeanValidation = useBeanValidation; + } - public void setUseTags(boolean useTags) { - this.useTags = useTags; + public void setHandleExceptions(boolean handleExceptions) { + this.handleExceptions = handleExceptions; } @Override @@ -242,7 +265,23 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea return objs; } - public void setUseBeanValidation(boolean useBeanValidation) { - this.useBeanValidation = useBeanValidation; + private CliOption createBooleanCliWithDefault(String optionName, String description, boolean defaultValue) { + CliOption defaultOption = CliOption.newBoolean(optionName, description); + defaultOption.setDefault(Boolean.toString(defaultValue)); + return defaultOption; + } + + @Override + public Map postProcessSupportingFileData(Map objs) { + Swagger swagger = (Swagger)objs.get("swagger"); + System.out.println("swagger" + swagger.toString()); + if(swagger != null) { + try { + objs.put("swagger-json", Json.pretty().writeValueAsString(swagger)); + } catch (JsonProcessingException e) { + LOGGER.error(e.getMessage(), e); + } + } + return super.postProcessSupportingFileData(objs); } } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiCall.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiCall.mustache new file mode 100644 index 00000000000..51492a54ded --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiCall.mustache @@ -0,0 +1,30 @@ +package swagger; + +import com.google.inject.Inject; +import play.mvc.Action; +import play.mvc.Http; +import play.mvc.Result; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +public class ApiCall extends Action { + + @Inject + private ApiCall() {} + + public CompletionStage call(Http.Context ctx) { + try { + //TODO: Do stuff you want to handle with each API call (metrics, logging, etc..) + return delegate.call(ctx); + } catch (Throwable t) { + //TODO: handle error the way you want + return CompletableFuture.completedFuture(handleExceptions(t)); + } + } + + private Result handleExceptions(Throwable t) { + //TODO: Handle exception that need special response (return a special apimodel, etc..) + return ok(); + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache index 60534355ae3..53536fd2418 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/apiDocController.mustache @@ -10,6 +10,6 @@ public class ApiDocController extends Controller { } public Result api() { - return redirect(String.format("/assets/lib/swagger-ui/index.html?/url=%s/api-docs", "")); + return redirect("/assets/lib/swagger-ui/index.html?/url=/assets/swagger.json"); } } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache index d6d9e9fa92b..c69d0c9154d 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/application.mustache @@ -1,9 +1,3 @@ -springfox.documentation.swagger.v2.path=/api-docs -server.contextPath={{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}} -server.port={{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}9000{{/serverPort}} -spring.jackson.date-format={{basePackage}}.RFC3339DateFormat -spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false - # This is the main configuration file for the application. # https://www.playframework.com/documentation/latest/ConfigFile # ~~~~~ @@ -64,9 +58,6 @@ play.modules { # By default, Play will load any class called Module that is defined # in the root package (the "app" directory), or you can define them # explicitly below. -# If there are any built-in modules that you want to disable, you can list them here. -enabled += "play.modules.swagger.SwaggerModule" - # If there are any built-in modules that you want to disable, you can list them here. #disabled += "" } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParamsNoDoc.mustache rename to modules/swagger-codegen/src/main/resources/JavaPlayFramework/bodyParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache index 3c7ba4b08ea..e3fb024daa5 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/build.mustache @@ -10,8 +10,7 @@ libraryDependencies ++= Seq( javaJdbc, cache, javaWs, -"io.swagger" %% "swagger-play2" % "1.5.3", -"org.webjars" % "swagger-ui" % "2.2.8"{{#useBeanValidation}}, +"org.webjars" % "swagger-ui" % "2.2.10-1"{{#useBeanValidation}}, "javax.validation" % "validation-api" % "1.1.0.Final" {{/useBeanValidation}} ) diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParamsNoDoc.mustache rename to modules/swagger-codegen/src/main/resources/JavaPlayFramework/formParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParamsNoDoc.mustache rename to modules/swagger-codegen/src/main/resources/JavaPlayFramework/headerParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache index e19bbf893cb..d95580df003 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApi.mustache @@ -12,9 +12,9 @@ import javax.validation.constraints.*; {{/useBeanValidation}} {{>generatedAnnotation}} {{#operations}} -public class {{classname}}ControllerImp { +public class {{classname}}ControllerImp {{#useInterfaces}}implements {{classname}}ControllerImpInterface{{/useInterfaces}} { {{#operation}} - {{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParamsNoDoc}}{{>queryParamsNoDoc}}{{>bodyParamsNoDoc}}{{>formParamsNoDoc}}{{>headerParamsNoDoc}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + public {{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { //Do your magic!!! {{#returnType}}return new {{>returnTypesNoVoidNoAbstract}}();{{/returnType}} } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache index bd76a507cae..61e64c68687 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiController.mustache @@ -3,7 +3,6 @@ package {{package}}; {{#imports}}import {{import}}; {{/imports}} -import io.swagger.annotations.*; import play.mvc.Controller; import play.mvc.Result; import play.mvc.Http; @@ -14,15 +13,17 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.inject.Inject; import java.io.IOException; import swagger.SwaggerUtils; -import javafx.util.Pair; import com.fasterxml.jackson.core.type.TypeReference; {{#useBeanValidation}} import javax.validation.constraints.*; {{/useBeanValidation}} +{{#handleExceptions}} +import swagger.SwaggerUtils.ApiAction; +{{/handleExceptions}} + {{>generatedAnnotation}} -@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API") {{#operations}} public class {{classname}}Controller extends Controller { @@ -37,21 +38,7 @@ public class {{classname}}Controller extends Controller { {{#operation}} - @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}"{{#returnType}}, response = {{{returnType}}}.class{{/returnType}}{{#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}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) - @ApiResponses(value = { {{#responses}} - @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#returnType}}, response = {{{returnType}}}.class{{/returnType}}){{#hasMore}}, {{/hasMore}}{{/responses}} }) - {{#hasParams}} - @ApiImplicitParams({ - {{#allParams}}{{^isPathParam}}@ApiImplicitParam(name = "{{baseName}}", value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#defaultValue}}, defaultValue = "{{{defaultValue}}}"{{/defaultValue}}, dataType = "{{{dataTypeForImplicitParam}}}", paramType = "{{>paramType}}"){{#hasMore}}, - {{/hasMore}}{{/isPathParam}}{{/allParams}} - }) - {{/hasParams}} + {{#handleExceptions}}@ApiAction{{/handleExceptions}} public Result {{operationId}}({{#pathParams}}{{>pathParams}}{{#hasMore}},{{/hasMore}}{{/pathParams}}) {{#bodyParams}}throws IOException{{/bodyParams}} { {{#bodyParams}} {{#collectionFormat}} @@ -64,7 +51,7 @@ public class {{classname}}Controller extends Controller { {{^required}} if (node{{paramName}} != null) { {{paramName}} = mapper.readValue(node{{paramName}}.toString(), {{#isMapContainer}}new TypeReference>(){}{{/isMapContainer}}{{#isListContainer}}new TypeReference>(){}{{/isListContainer}}{{^isListContainer}}{{^isMapContainer}}{{{dataType}}}.class{{/isMapContainer}}{{/isListContainer}});{{/required}} - {{#required}}{{paramName}} = mapper.readValue(node{{paramName}}.toString(), {{{dataType}}}.class);{{/required}} + {{#required}}{{paramName}} = mapper.readValue(node{{paramName}}.toString(), {{#isMapContainer}}new TypeReference>(){}{{/isMapContainer}}{{#isListContainer}}new TypeReference>(){}{{/isListContainer}}{{^isListContainer}}{{^isMapContainer}}{{{dataType}}}.class{{/isMapContainer}}{{/isListContainer}});{{/required}} {{^required}} } else { {{paramName}} = null; diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiInterface.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiInterface.mustache new file mode 100644 index 00000000000..367c16f3586 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/newApiInterface.mustache @@ -0,0 +1,22 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +import play.mvc.Http; +import java.util.List; +import java.util.ArrayList; +import java.util.HashMap; + +{{#useBeanValidation}} +import javax.validation.constraints.*; +{{/useBeanValidation}} + +{{#operations}} +public interface {{classname}}ControllerImpInterface { +{{#operation}} + {{>returnTypes}} {{operationId}}({{#allParams}}{{>pathParams}}{{>queryParams}}{{>bodyParams}}{{>formParams}}{{>headerParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache deleted file mode 100644 index 1bd5e207d7b..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/notFoundException.mustache +++ /dev/null @@ -1,10 +0,0 @@ -package {{apiPackage}}; - -{{>generatedAnnotation}} -public class NotFoundException extends ApiException { - private int code; - public NotFoundException (int code, String msg) { - super(code, msg); - this.code = code; - } -} diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache index 190ebbb3fe2..07b519cba5e 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParams.mustache @@ -1 +1 @@ -{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file +{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache deleted file mode 100644 index 4dce26e1cea..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pathParamsNoDoc.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache index d1422e2b1fc..dc9d4bc5c47 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/pojo.mustache @@ -1,7 +1,6 @@ /** * {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}} - */{{#description}} -@ApiModel(description = "{{{description}}}"){{/description}} + */ {{>generatedAnnotation}} public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { {{#vars}} @@ -64,7 +63,6 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{#vendorExtensions.extraAnnotation}} {{{vendorExtensions.extraAnnotation}}} {{/vendorExtensions.extraAnnotation}} - @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; } diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties deleted file mode 100644 index a8c2f849be3..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.12.0 diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt deleted file mode 100644 index 713b7f3e993..00000000000 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/project/plugins.sbt +++ /dev/null @@ -1,9 +0,0 @@ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4") - -libraryDependencies <+= sbtVersion(v => v match { - case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8" - case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10" - case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11" - case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1" - case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1" -}) \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParamsNoDoc.mustache rename to modules/swagger-codegen/src/main/resources/JavaPlayFramework/queryParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache index 2ed34dbcd1d..c6ae5178dd3 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/routes.mustache @@ -10,18 +10,11 @@ GET /api controllers.ApiDocController.api #Functions for {{{baseName}}} API {{#operations}} {{#operation}} -{{httpMethod}} {{path}} controllers.{{classname}}Controller.{{operationId}}({{#pathParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/pathParams}}) +{{httpMethod}} {{contextPath}}{{path}} controllers.{{classname}}Controller.{{operationId}}({{#pathParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/pathParams}}) {{/operation}} {{/operations}} {{/apis}} {{/apiInfo}} # Map static resources from the /public folder to the /assets URL path -GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) - -GET /api-docs controllers.ApiHelpController.getResources -{{#apiInfo}} -{{#apis}} -GET /api-docs.json/{{{baseName}}} controllers.ApiHelpController.getResource(path = "/{{{baseName}}}") -{{/apis}} -{{/apiInfo}} \ No newline at end of file +GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swagger.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swagger.mustache new file mode 100644 index 00000000000..0a7a2006155 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swagger.mustache @@ -0,0 +1 @@ +{{{swagger-json}}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache index 99f8d84b739..9a732b2933f 100644 --- a/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaPlayFramework/swaggerUtils.mustache @@ -1,108 +1,101 @@ package swagger; -import javafx.util.Pair; +import play.mvc.With; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.List; +import java.util.HashMap; +import java.util.Map; public class SwaggerUtils { - /** - * Format to {@code Pair} objects. - * - * @param collectionFormat collection format (e.g. csv, tsv) - * @param name Name - * @param value Value - * @return A list of Pair objects - */ - public static List parameterToPairs(String collectionFormat, String name, Object value){ - List params = new ArrayList(); +{{#handleExceptions}} + @With(ApiCall.class) + @Target({ ElementType.TYPE, ElementType.METHOD }) + @Retention(RetentionPolicy.RUNTIME) + public @interface ApiAction { + } +{{/handleExceptions}} - // preconditions - if (name == null || name.isEmpty() || value == null) return params; + public static Map parameterToPairs(String collectionFormat, String name, Object value){ + Map params = new HashMap<>(); - Collection valueCollection = null; - if (value instanceof Collection) { - valueCollection = (Collection) value; - } else { - params.add(new Pair(name, parameterToString(value))); - return params; - } + // preconditions + if (name == null || name.isEmpty() || value == null) return params; - if (valueCollection.isEmpty()){ - return params; - } + Collection valueCollection = null; + if (value instanceof Collection) { + valueCollection = (Collection) value; + } else { + params.put(name, parameterToString(value)); + return params; + } - // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + if (valueCollection.isEmpty()){ + return params; + } - // create the params based on the collection format - if (collectionFormat.equals("multi")) { - for (Object item : valueCollection) { - params.add(new Pair(name, parameterToString(item))); - } + // get the collection format + collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv - return params; - } + // create the params based on the collection format + if (collectionFormat.equals("multi")) { + for (Object item : valueCollection) { + params.put(name, parameterToString(item)); + } - String delimiter = ","; + return params; + } - if (collectionFormat.equals("csv")) { - delimiter = ","; - } else if (collectionFormat.equals("ssv")) { - delimiter = " "; - } else if (collectionFormat.equals("tsv")) { - delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { - delimiter = "|"; - } + String delimiter = ","; - StringBuilder sb = new StringBuilder() ; - for (Object item : valueCollection) { - sb.append(delimiter); - sb.append(parameterToString(item)); - } + if (collectionFormat.equals("csv")) { + delimiter = ","; + } else if (collectionFormat.equals("ssv")) { + delimiter = " "; + } else if (collectionFormat.equals("tsv")) { + delimiter = "\t"; + } else if (collectionFormat.equals("pipes")) { + delimiter = "|"; + } - params.add(new Pair(name, sb.substring(1))); + StringBuilder sb = new StringBuilder() ; + for (Object item : valueCollection) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } - return params; - } + params.put(name, sb.substring(1)); - /** - * Format the given parameter object into string. - * - * @param param Parameter - * @return String representation of the parameter - */ - public static String parameterToString(Object param) { - if (param == null) { - return ""; - } else if (param instanceof Date) { - return formatDatetime((Date) param); - } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); - for (Object o : (Collection)param) { - if (b.length() > 0) { - b.append(","); - } - b.append(String.valueOf(o)); - } - return b.toString(); - } else { - return String.valueOf(param); - } - } + return params; + } - /** - * Format the given Date object into string (Datetime format). - * - * @param date Date object - * @return Formatted datetime in string representation - */ - public static String formatDatetime(Date date) { - return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date); - } + public static String parameterToString(Object param) { + if (param == null) { + return ""; + } else if (param instanceof Date) { + return formatDatetime((Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for (Object o : (Collection)param) { + if (b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + + return b.toString(); + } else { + return String.valueOf(param); + } + } + + public static String formatDatetime(Date date) { + return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date); + } } \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java index a6873db28ad..6866074ba93 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/javaPlayFramework/JavaPlayFrameworkOptionsTest.java @@ -55,14 +55,12 @@ public class JavaPlayFrameworkOptionsTest extends JavaClientOptionsTest { times = 1; clientCodegen.setControllerOnly(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.CONTROLLER_ONLY)); times = 1; - clientCodegen.setSingleContentTypes(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.SINGLE_CONTENT_TYPES)); - times = 1; - clientCodegen.setResponseWrapper(JavaPlayFrameworkOptionsProvider.RESPONSE_WRAPPER); - times = 1; - clientCodegen.setUseTags(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.USE_TAGS)); - times = 1; clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.USE_BEANVALIDATION)); times = 1; + clientCodegen.setUseInterfaces(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.USE_INTERFACES)); + times = 1; + clientCodegen.setHandleExceptions(Boolean.valueOf(JavaPlayFrameworkOptionsProvider.HANDLE_EXCEPTIONS)); + times = 1; }}; } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java index b0971b2e475..5ca000025cd 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaPlayFrameworkOptionsProvider.java @@ -9,15 +9,14 @@ public class JavaPlayFrameworkOptionsProvider extends JavaOptionsProvider { public static final String TITLE = "swagger"; public static final String CONFIG_PACKAGE_VALUE = "configPackage"; public static final String BASE_PACKAGE_VALUE = "basePackage"; - public static final String CONTROLLER_ONLY = "true"; - public static final String SINGLE_CONTENT_TYPES = "true"; - public static final String RESPONSE_WRAPPER = "Callable"; - public static final String USE_TAGS = "useTags"; + public static final String CONTROLLER_ONLY = "false"; public static final String USE_BEANVALIDATION = "true"; + public static final String USE_INTERFACES = "true"; + public static final String HANDLE_EXCEPTIONS = "true"; @Override public String getLanguage() { - return "javaPlayFramework"; + return "java-play-framework"; } @Override @@ -27,10 +26,9 @@ public class JavaPlayFrameworkOptionsProvider extends JavaOptionsProvider { options.put(JavaPlayFrameworkCodegen.CONFIG_PACKAGE, CONFIG_PACKAGE_VALUE); options.put(JavaPlayFrameworkCodegen.BASE_PACKAGE, BASE_PACKAGE_VALUE); options.put(JavaPlayFrameworkCodegen.CONTROLLER_ONLY, CONTROLLER_ONLY); - options.put(JavaPlayFrameworkCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES); - options.put(JavaPlayFrameworkCodegen.RESPONSE_WRAPPER, RESPONSE_WRAPPER); - options.put(JavaPlayFrameworkCodegen.USE_TAGS, USE_TAGS); options.put(JavaPlayFrameworkCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION); + options.put(JavaPlayFrameworkCodegen.USE_INTERFACES, USE_INTERFACES); + options.put(JavaPlayFrameworkCodegen.HANDLE_EXCEPTIONS, HANDLE_EXCEPTIONS); return options; } diff --git a/samples/server/petstore/java-play-framework/app/apimodels/Category.java b/samples/server/petstore/java-play-framework/app/apimodels/Category.java index bde93b1ceb8..4c764fd81f8 100644 --- a/samples/server/petstore/java-play-framework/app/apimodels/Category.java +++ b/samples/server/petstore/java-play-framework/app/apimodels/Category.java @@ -1,8 +1,6 @@ package apimodels; import java.util.Objects; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.*; import com.fasterxml.jackson.annotation.*; /** @@ -25,7 +23,6 @@ public class Category { * Get id * @return id **/ - @ApiModelProperty(value = "") public Long getId() { return id; } @@ -43,7 +40,6 @@ public class Category { * Get name * @return name **/ - @ApiModelProperty(value = "") public String getName() { return name; } diff --git a/samples/server/petstore/java-play-framework/app/apimodels/Order.java b/samples/server/petstore/java-play-framework/app/apimodels/Order.java index 6d8b7abf1bc..055cef75516 100644 --- a/samples/server/petstore/java-play-framework/app/apimodels/Order.java +++ b/samples/server/petstore/java-play-framework/app/apimodels/Order.java @@ -1,8 +1,6 @@ package apimodels; import java.util.Objects; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import java.time.OffsetDateTime; import javax.validation.constraints.*; import com.fasterxml.jackson.annotation.*; @@ -71,7 +69,6 @@ public class Order { * Get id * @return id **/ - @ApiModelProperty(value = "") public Long getId() { return id; } @@ -89,7 +86,6 @@ public class Order { * Get petId * @return petId **/ - @ApiModelProperty(value = "") public Long getPetId() { return petId; } @@ -107,7 +103,6 @@ public class Order { * Get quantity * @return quantity **/ - @ApiModelProperty(value = "") public Integer getQuantity() { return quantity; } @@ -125,7 +120,6 @@ public class Order { * Get shipDate * @return shipDate **/ - @ApiModelProperty(value = "") public OffsetDateTime getShipDate() { return shipDate; } @@ -143,7 +137,6 @@ public class Order { * Order Status * @return status **/ - @ApiModelProperty(value = "Order Status") public StatusEnum getStatus() { return status; } @@ -161,7 +154,6 @@ public class Order { * Get complete * @return complete **/ - @ApiModelProperty(value = "") public Boolean getComplete() { return complete; } diff --git a/samples/server/petstore/java-play-framework/app/apimodels/Pet.java b/samples/server/petstore/java-play-framework/app/apimodels/Pet.java index a9bf2532e7e..a20a1462eb6 100644 --- a/samples/server/petstore/java-play-framework/app/apimodels/Pet.java +++ b/samples/server/petstore/java-play-framework/app/apimodels/Pet.java @@ -3,8 +3,6 @@ package apimodels; import java.util.Objects; import apimodels.Category; import apimodels.Tag; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import java.util.ArrayList; import java.util.List; import javax.validation.constraints.*; @@ -74,7 +72,6 @@ public class Pet { * Get id * @return id **/ - @ApiModelProperty(value = "") public Long getId() { return id; } @@ -92,7 +89,6 @@ public class Pet { * Get category * @return category **/ - @ApiModelProperty(value = "") public Category getCategory() { return category; } @@ -110,7 +106,6 @@ public class Pet { * Get name * @return name **/ - @ApiModelProperty(example = "doggie", required = true, value = "") @NotNull public String getName() { return name; @@ -134,7 +129,6 @@ public class Pet { * Get photoUrls * @return photoUrls **/ - @ApiModelProperty(required = true, value = "") @NotNull public List getPhotoUrls() { return photoUrls; @@ -158,7 +152,6 @@ public class Pet { * Get tags * @return tags **/ - @ApiModelProperty(value = "") public List getTags() { return tags; } @@ -176,7 +169,6 @@ public class Pet { * pet status in the store * @return status **/ - @ApiModelProperty(value = "pet status in the store") public StatusEnum getStatus() { return status; } diff --git a/samples/server/petstore/java-play-framework/app/apimodels/Tag.java b/samples/server/petstore/java-play-framework/app/apimodels/Tag.java index 4c6effbdec6..803f3932c33 100644 --- a/samples/server/petstore/java-play-framework/app/apimodels/Tag.java +++ b/samples/server/petstore/java-play-framework/app/apimodels/Tag.java @@ -1,8 +1,6 @@ package apimodels; import java.util.Objects; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.*; import com.fasterxml.jackson.annotation.*; /** @@ -25,7 +23,6 @@ public class Tag { * Get id * @return id **/ - @ApiModelProperty(value = "") public Long getId() { return id; } @@ -43,7 +40,6 @@ public class Tag { * Get name * @return name **/ - @ApiModelProperty(value = "") public String getName() { return name; } diff --git a/samples/server/petstore/java-play-framework/app/apimodels/User.java b/samples/server/petstore/java-play-framework/app/apimodels/User.java index 9426d1b0356..9c47fe087ff 100644 --- a/samples/server/petstore/java-play-framework/app/apimodels/User.java +++ b/samples/server/petstore/java-play-framework/app/apimodels/User.java @@ -1,8 +1,6 @@ package apimodels; import java.util.Objects; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import javax.validation.constraints.*; import com.fasterxml.jackson.annotation.*; /** @@ -43,7 +41,6 @@ public class User { * Get id * @return id **/ - @ApiModelProperty(value = "") public Long getId() { return id; } @@ -61,7 +58,6 @@ public class User { * Get username * @return username **/ - @ApiModelProperty(value = "") public String getUsername() { return username; } @@ -79,7 +75,6 @@ public class User { * Get firstName * @return firstName **/ - @ApiModelProperty(value = "") public String getFirstName() { return firstName; } @@ -97,7 +92,6 @@ public class User { * Get lastName * @return lastName **/ - @ApiModelProperty(value = "") public String getLastName() { return lastName; } @@ -115,7 +109,6 @@ public class User { * Get email * @return email **/ - @ApiModelProperty(value = "") public String getEmail() { return email; } @@ -133,7 +126,6 @@ public class User { * Get password * @return password **/ - @ApiModelProperty(value = "") public String getPassword() { return password; } @@ -151,7 +143,6 @@ public class User { * Get phone * @return phone **/ - @ApiModelProperty(value = "") public String getPhone() { return phone; } @@ -169,7 +160,6 @@ public class User { * User Status * @return userStatus **/ - @ApiModelProperty(value = "User Status") public Integer getUserStatus() { return userStatus; } diff --git a/samples/server/petstore/java-play-framework/app/controllers/ApiDocController.java b/samples/server/petstore/java-play-framework/app/controllers/ApiDocController.java index 60534355ae3..53536fd2418 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/ApiDocController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/ApiDocController.java @@ -10,6 +10,6 @@ public class ApiDocController extends Controller { } public Result api() { - return redirect(String.format("/assets/lib/swagger-ui/index.html?/url=%s/api-docs", "")); + return redirect("/assets/lib/swagger-ui/index.html?/url=/assets/swagger.json"); } } diff --git a/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java b/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java index b707b720c7b..357f3f1bbbb 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/PetApiController.java @@ -3,7 +3,6 @@ package controllers; import java.io.File; import apimodels.Pet; -import io.swagger.annotations.*; import play.mvc.Controller; import play.mvc.Result; import play.mvc.Http; @@ -14,13 +13,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.inject.Inject; import java.io.IOException; import swagger.SwaggerUtils; -import javafx.util.Pair; import com.fasterxml.jackson.core.type.TypeReference; import javax.validation.constraints.*; +import swagger.SwaggerUtils.ApiAction; + -@Api(value = "Pet", description = "the Pet API") public class PetApiController extends Controller { private PetApiControllerImp imp; @@ -33,17 +32,7 @@ public class PetApiController extends Controller { } - @ApiOperation(value = "Add a new pet to the store", notes = "", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "Pet object that needs to be added to the store", dataType = "apimodels.Pet", paramType = "body") - }) + @ApiAction public Result addPet() throws IOException { JsonNode nodebody = request().body().asJson(); Pet body; @@ -58,18 +47,8 @@ public class PetApiController extends Controller { return ok(); } - @ApiOperation(value = "Deletes a pet", notes = "", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid pet value") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "api_key", value = "", dataType = "String", paramType = "header") - }) - public Result deletePet(@ApiParam(value = "Pet id to delete", required = true ) Long petId) { + @ApiAction + public Result deletePet(Long petId) { String valueapiKey = request().getHeader("api_key"); String apiKey; if (valueapiKey != null) { @@ -83,18 +62,7 @@ public class PetApiController extends Controller { return ok(); } - @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") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "status", value = "Status values that need to be considered for filter", defaultValue = "available", dataType = "List", paramType = "query") - }) + @ApiAction public Result findPetsByStatus() { //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? @@ -110,18 +78,7 @@ public class PetApiController extends Controller { } - @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") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Pet.class), - @ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "tags", value = "Tags to filter by", dataType = "List", paramType = "query") - }) + @ApiAction public Result findPetsByTags() { //TODO: Maybe implement this in the future if we can support collection in the body params: see bug in swagger-play: https://github.com/swagger-api/swagger-play/issues/130 //TODO: Tt seems it is not detected that it's a list based on the collectionFormat field? @@ -137,40 +94,15 @@ public class PetApiController extends Controller { } - @ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class, authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }), - @Authorization(value = "api_key") - }, tags={ }) - @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) }) - @ApiImplicitParams({ - - }) - public Result getPetById(@ApiParam(value = "ID of pet that needs to be fetched", required = true ) Long petId) { + @ApiAction + public Result getPetById(Long petId) { Pet obj = imp.getPetById(petId); JsonNode result = mapper.valueToTree(obj); return ok(result); } - @ApiOperation(value = "Update an existing pet", notes = "", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Pet not found"), - @ApiResponse(code = 405, message = "Validation exception") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "Pet object that needs to be added to the store", dataType = "apimodels.Pet", paramType = "body") - }) + @ApiAction public Result updatePet() throws IOException { JsonNode nodebody = request().body().asJson(); Pet body; @@ -185,19 +117,8 @@ public class PetApiController extends Controller { return ok(); } - @ApiOperation(value = "Updates a pet in the store with form data", notes = "", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 405, message = "Invalid input") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "Updated name of the pet", dataType = "String", paramType = "form"), - @ApiImplicitParam(name = "status", value = "Updated status of the pet", dataType = "String", paramType = "form") - }) - public Result updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required = true ) String petId) { + @ApiAction + public Result updatePetWithForm(String petId) { String valuename = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("name"))[0]; String name; if (valuename != null) { @@ -219,19 +140,8 @@ public class PetApiController extends Controller { return ok(); } - @ApiOperation(value = "uploads an image", notes = "", authorizations = { - @Authorization(value = "petstore_auth", scopes = { - @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), - @AuthorizationScope(scope = "read:pets", description = "read your pets") - }) - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 0, message = "successful operation") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "additionalMetadata", value = "Additional data to pass to server", dataType = "String", paramType = "form"), - @ApiImplicitParam(name = "file", value = "file to upload", dataType = "apimodels.File", paramType = "form") - }) - public Result uploadFile(@ApiParam(value = "ID of pet to update", required = true ) Long petId) { + @ApiAction + public Result uploadFile(Long petId) { String valueadditionalMetadata = ((String[]) request().body().asMultipartFormData().asFormUrlEncoded().get("additionalMetadata"))[0]; String additionalMetadata; if (valueadditionalMetadata != null) { diff --git a/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImp.java b/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImp.java index 70c34a3a867..f3f1b829b7b 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImp.java +++ b/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImp.java @@ -9,43 +9,43 @@ import java.util.ArrayList; import java.util.HashMap; import javax.validation.constraints.*; -public class PetApiControllerImp { - void addPet(Pet body) { +public class PetApiControllerImp implements PetApiControllerImpInterface { + public void addPet(Pet body) { //Do your magic!!! } - void deletePet( Long petId, String apiKey) { + public void deletePet(Long petId, String apiKey) { //Do your magic!!! } - List findPetsByStatus( List status) { + public List findPetsByStatus( List status) { //Do your magic!!! return new ArrayList(); } - List findPetsByTags( List tags) { + public List findPetsByTags( List tags) { //Do your magic!!! return new ArrayList(); } - Pet getPetById( Long petId) { + public Pet getPetById(Long petId) { //Do your magic!!! return new Pet(); } - void updatePet(Pet body) { + public void updatePet(Pet body) { //Do your magic!!! } - void updatePetWithForm( String petId, String name, String status) { + public void updatePetWithForm(String petId, String name, String status) { //Do your magic!!! } - void uploadFile( Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) { + public void uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file) { //Do your magic!!! } diff --git a/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImpInterface.java b/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImpInterface.java index c52bedf522c..00f0964f107 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImpInterface.java +++ b/samples/server/petstore/java-play-framework/app/controllers/PetApiControllerImpInterface.java @@ -3,27 +3,28 @@ package controllers; import java.io.File; import apimodels.Pet; +import play.mvc.Http; import java.util.List; import java.util.ArrayList; import java.util.HashMap; -import play.mvc.Http; +import javax.validation.constraints.*; public interface PetApiControllerImpInterface { void addPet(Pet body); - void deletePet( Long petId, String apiKey); + void deletePet(Long petId, String apiKey); List findPetsByStatus( List status); List findPetsByTags( List tags); - Pet getPetById( Long petId); + Pet getPetById(Long petId); void updatePet(Pet body); - void updatePetWithForm( String petId, String name, String status); + void updatePetWithForm(String petId, String name, String status); - void uploadFile( Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file); + void uploadFile(Long petId, String additionalMetadata, Http.MultipartFormData.FilePart file); } diff --git a/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java b/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java index 02d1c118ec7..ec44ea87d18 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/StoreApiController.java @@ -3,7 +3,6 @@ package controllers; import java.util.Map; import apimodels.Order; -import io.swagger.annotations.*; import play.mvc.Controller; import play.mvc.Result; import play.mvc.Http; @@ -14,13 +13,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.inject.Inject; import java.io.IOException; import swagger.SwaggerUtils; -import javafx.util.Pair; import com.fasterxml.jackson.core.type.TypeReference; import javax.validation.constraints.*; +import swagger.SwaggerUtils.ApiAction; + -@Api(value = "Store", description = "the Store API") public class StoreApiController extends Controller { private StoreApiControllerImp imp; @@ -33,24 +32,14 @@ public class StoreApiController extends Controller { } - @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", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid ID supplied"), - @ApiResponse(code = 404, message = "Order not found") }) - @ApiImplicitParams({ - - }) - public Result deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required = true ) String orderId) { + @ApiAction + public Result deleteOrder(String orderId) { imp.deleteOrder(orderId); return ok(); } - @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") - }, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Integer.class) }) + @ApiAction public Result getInventory() { Map obj = imp.getInventory(); JsonNode result = mapper.valueToTree(obj); @@ -58,28 +47,15 @@ public class StoreApiController extends Controller { } - @ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ }) - @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) }) - @ApiImplicitParams({ - - }) - public Result getOrderById(@ApiParam(value = "ID of pet that needs to be fetched", required = true ) String orderId) { + @ApiAction + public Result getOrderById(String orderId) { Order obj = imp.getOrderById(orderId); JsonNode result = mapper.valueToTree(obj); return ok(result); } - @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = Order.class), - @ApiResponse(code = 400, message = "Invalid Order", response = Order.class) }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "order placed for purchasing the pet", dataType = "apimodels.Order", paramType = "body") - }) + @ApiAction public Result placeOrder() throws IOException { JsonNode nodebody = request().body().asJson(); Order body; diff --git a/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImp.java b/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImp.java index d2add2ecc87..6ff8ca7b8f1 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImp.java +++ b/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImp.java @@ -9,23 +9,23 @@ import java.util.ArrayList; import java.util.HashMap; import javax.validation.constraints.*; -public class StoreApiControllerImp { - void deleteOrder( String orderId) { +public class StoreApiControllerImp implements StoreApiControllerImpInterface { + public void deleteOrder(String orderId) { //Do your magic!!! } - Map getInventory() { + public Map getInventory() { //Do your magic!!! return new HashMap(); } - Order getOrderById( String orderId) { + public Order getOrderById(String orderId) { //Do your magic!!! return new Order(); } - Order placeOrder(Order body) { + public Order placeOrder(Order body) { //Do your magic!!! return new Order(); } diff --git a/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImpInterface.java b/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImpInterface.java index 2d0f8b941a9..9640da22e6b 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImpInterface.java +++ b/samples/server/petstore/java-play-framework/app/controllers/StoreApiControllerImpInterface.java @@ -3,16 +3,19 @@ package controllers; import java.util.Map; import apimodels.Order; +import play.mvc.Http; import java.util.List; import java.util.ArrayList; import java.util.HashMap; +import javax.validation.constraints.*; + public interface StoreApiControllerImpInterface { - void deleteOrder( String orderId); + void deleteOrder(String orderId); Map getInventory(); - Order getOrderById( String orderId); + Order getOrderById(String orderId); Order placeOrder(Order body); diff --git a/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java b/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java index 5693ac81fbd..7db5c2f2bff 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java +++ b/samples/server/petstore/java-play-framework/app/controllers/UserApiController.java @@ -3,7 +3,6 @@ package controllers; import java.util.List; import apimodels.User; -import io.swagger.annotations.*; import play.mvc.Controller; import play.mvc.Result; import play.mvc.Http; @@ -14,13 +13,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.inject.Inject; import java.io.IOException; import swagger.SwaggerUtils; -import javafx.util.Pair; import com.fasterxml.jackson.core.type.TypeReference; import javax.validation.constraints.*; +import swagger.SwaggerUtils.ApiAction; + -@Api(value = "User", description = "the User API") public class UserApiController extends Controller { private UserApiControllerImp imp; @@ -33,12 +32,7 @@ public class UserApiController extends Controller { } - @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 0, message = "successful operation") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "Created user object", dataType = "apimodels.User", paramType = "body") - }) + @ApiAction public Result createUser() throws IOException { JsonNode nodebody = request().body().asJson(); User body; @@ -53,12 +47,7 @@ public class UserApiController extends Controller { return ok(); } - @ApiOperation(value = "Creates list of users with given input array", notes = "", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 0, message = "successful operation") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "List of user object", dataType = "List", paramType = "body") - }) + @ApiAction public Result createUsersWithArrayInput() throws IOException { JsonNode nodebody = request().body().asJson(); List body; @@ -73,12 +62,7 @@ public class UserApiController extends Controller { return ok(); } - @ApiOperation(value = "Creates list of users with given input array", notes = "", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 0, message = "successful operation") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "List of user object", dataType = "List", paramType = "body") - }) + @ApiAction public Result createUsersWithListInput() throws IOException { JsonNode nodebody = request().body().asJson(); List body; @@ -93,42 +77,22 @@ public class UserApiController extends Controller { return ok(); } - @ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid username supplied"), - @ApiResponse(code = 404, message = "User not found") }) - @ApiImplicitParams({ - - }) - public Result deleteUser(@ApiParam(value = "The name that needs to be deleted", required = true ) String username) { + @ApiAction + public Result deleteUser(String username) { imp.deleteUser(username); return ok(); } - @ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ }) - @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) }) - @ApiImplicitParams({ - - }) - public Result getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ", required = true ) String username) { + @ApiAction + public Result getUserByName(String username) { User obj = imp.getUserByName(username); JsonNode result = mapper.valueToTree(obj); return ok(result); } - @ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = String.class), - @ApiResponse(code = 400, message = "Invalid username/password supplied", response = String.class) }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "username", value = "The user name for login", dataType = "String", paramType = "query"), - @ApiImplicitParam(name = "password", value = "The password for login in clear text", dataType = "String", paramType = "query") - }) + @ApiAction public Result loginUser() { String valueusername = request().getQueryString("username"); String username; @@ -152,23 +116,15 @@ public class UserApiController extends Controller { } - @ApiOperation(value = "Logs out current logged in user session", notes = "", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 0, message = "successful operation") }) + @ApiAction public Result logoutUser() { imp.logoutUser(); return ok(); } - @ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", tags={ }) - @ApiResponses(value = { - @ApiResponse(code = 400, message = "Invalid user supplied"), - @ApiResponse(code = 404, message = "User not found") }) - @ApiImplicitParams({ - @ApiImplicitParam(name = "body", value = "Updated user object", dataType = "apimodels.User", paramType = "body") - }) - public Result updateUser(@ApiParam(value = "name that need to be deleted", required = true ) String username) throws IOException { + @ApiAction + public Result updateUser(String username) throws IOException { JsonNode nodebody = request().body().asJson(); User body; if (nodebody != null) { diff --git a/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImp.java b/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImp.java index 2c2180af5d0..74c0739c4f5 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImp.java +++ b/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImp.java @@ -9,43 +9,43 @@ import java.util.ArrayList; import java.util.HashMap; import javax.validation.constraints.*; -public class UserApiControllerImp { - void createUser(User body) { +public class UserApiControllerImp implements UserApiControllerImpInterface { + public void createUser(User body) { //Do your magic!!! } - void createUsersWithArrayInput(List body) { + public void createUsersWithArrayInput(List body) { //Do your magic!!! } - void createUsersWithListInput(List body) { + public void createUsersWithListInput(List body) { //Do your magic!!! } - void deleteUser( String username) { + public void deleteUser(String username) { //Do your magic!!! } - User getUserByName( String username) { + public User getUserByName(String username) { //Do your magic!!! return new User(); } - String loginUser( String username, String password) { + public String loginUser( String username, String password) { //Do your magic!!! return new String(); } - void logoutUser() { + public void logoutUser() { //Do your magic!!! } - void updateUser( String username, User body) { + public void updateUser(String username, User body) { //Do your magic!!! } diff --git a/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImpInterface.java b/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImpInterface.java index 3d5f4034848..7d5af6fe41e 100644 --- a/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImpInterface.java +++ b/samples/server/petstore/java-play-framework/app/controllers/UserApiControllerImpInterface.java @@ -3,10 +3,13 @@ package controllers; import java.util.List; import apimodels.User; +import play.mvc.Http; import java.util.List; import java.util.ArrayList; import java.util.HashMap; +import javax.validation.constraints.*; + public interface UserApiControllerImpInterface { void createUser(User body); @@ -14,14 +17,14 @@ public interface UserApiControllerImpInterface { void createUsersWithListInput(List body); - void deleteUser( String username); + void deleteUser(String username); - User getUserByName( String username); + User getUserByName(String username); String loginUser( String username, String password); void logoutUser(); - void updateUser( String username, User body); + void updateUser(String username, User body); } diff --git a/samples/server/petstore/java-play-framework/app/swagger/ApiCall.java b/samples/server/petstore/java-play-framework/app/swagger/ApiCall.java new file mode 100644 index 00000000000..51492a54ded --- /dev/null +++ b/samples/server/petstore/java-play-framework/app/swagger/ApiCall.java @@ -0,0 +1,30 @@ +package swagger; + +import com.google.inject.Inject; +import play.mvc.Action; +import play.mvc.Http; +import play.mvc.Result; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +public class ApiCall extends Action { + + @Inject + private ApiCall() {} + + public CompletionStage call(Http.Context ctx) { + try { + //TODO: Do stuff you want to handle with each API call (metrics, logging, etc..) + return delegate.call(ctx); + } catch (Throwable t) { + //TODO: handle error the way you want + return CompletableFuture.completedFuture(handleExceptions(t)); + } + } + + private Result handleExceptions(Throwable t) { + //TODO: Handle exception that need special response (return a special apimodel, etc..) + return ok(); + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/app/swagger/SwaggerUtils.java b/samples/server/petstore/java-play-framework/app/swagger/SwaggerUtils.java index 99f8d84b739..1c9660906b3 100644 --- a/samples/server/petstore/java-play-framework/app/swagger/SwaggerUtils.java +++ b/samples/server/petstore/java-play-framework/app/swagger/SwaggerUtils.java @@ -1,108 +1,99 @@ package swagger; -import javafx.util.Pair; +import play.mvc.With; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.List; +import java.util.HashMap; +import java.util.Map; public class SwaggerUtils { - /** - * Format to {@code Pair} objects. - * - * @param collectionFormat collection format (e.g. csv, tsv) - * @param name Name - * @param value Value - * @return A list of Pair objects - */ - public static List parameterToPairs(String collectionFormat, String name, Object value){ - List params = new ArrayList(); + @With(ApiCall.class) + @Target({ ElementType.TYPE, ElementType.METHOD }) + @Retention(RetentionPolicy.RUNTIME) + public @interface ApiAction { + } - // preconditions - if (name == null || name.isEmpty() || value == null) return params; + public static Map parameterToPairs(String collectionFormat, String name, Object value){ + Map params = new HashMap<>(); - Collection valueCollection = null; - if (value instanceof Collection) { - valueCollection = (Collection) value; - } else { - params.add(new Pair(name, parameterToString(value))); - return params; - } + // preconditions + if (name == null || name.isEmpty() || value == null) return params; - if (valueCollection.isEmpty()){ - return params; - } + Collection valueCollection = null; + if (value instanceof Collection) { + valueCollection = (Collection) value; + } else { + params.put(name, parameterToString(value)); + return params; + } - // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + if (valueCollection.isEmpty()){ + return params; + } - // create the params based on the collection format - if (collectionFormat.equals("multi")) { - for (Object item : valueCollection) { - params.add(new Pair(name, parameterToString(item))); - } + // get the collection format + collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv - return params; - } + // create the params based on the collection format + if (collectionFormat.equals("multi")) { + for (Object item : valueCollection) { + params.put(name, parameterToString(item)); + } - String delimiter = ","; + return params; + } - if (collectionFormat.equals("csv")) { - delimiter = ","; - } else if (collectionFormat.equals("ssv")) { - delimiter = " "; - } else if (collectionFormat.equals("tsv")) { - delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { - delimiter = "|"; - } + String delimiter = ","; - StringBuilder sb = new StringBuilder() ; - for (Object item : valueCollection) { - sb.append(delimiter); - sb.append(parameterToString(item)); - } + if (collectionFormat.equals("csv")) { + delimiter = ","; + } else if (collectionFormat.equals("ssv")) { + delimiter = " "; + } else if (collectionFormat.equals("tsv")) { + delimiter = "\t"; + } else if (collectionFormat.equals("pipes")) { + delimiter = "|"; + } - params.add(new Pair(name, sb.substring(1))); + StringBuilder sb = new StringBuilder() ; + for (Object item : valueCollection) { + sb.append(delimiter); + sb.append(parameterToString(item)); + } - return params; - } + params.put(name, sb.substring(1)); - /** - * Format the given parameter object into string. - * - * @param param Parameter - * @return String representation of the parameter - */ - public static String parameterToString(Object param) { - if (param == null) { - return ""; - } else if (param instanceof Date) { - return formatDatetime((Date) param); - } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); - for (Object o : (Collection)param) { - if (b.length() > 0) { - b.append(","); - } - b.append(String.valueOf(o)); - } - return b.toString(); - } else { - return String.valueOf(param); - } - } + return params; + } - /** - * Format the given Date object into string (Datetime format). - * - * @param date Date object - * @return Formatted datetime in string representation - */ - public static String formatDatetime(Date date) { - return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date); - } + public static String parameterToString(Object param) { + if (param == null) { + return ""; + } else if (param instanceof Date) { + return formatDatetime((Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for (Object o : (Collection)param) { + if (b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + + return b.toString(); + } else { + return String.valueOf(param); + } + } + + public static String formatDatetime(Date date) { + return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(date); + } } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/build.sbt b/samples/server/petstore/java-play-framework/build.sbt index 6d54164e40e..4fd985e578f 100644 --- a/samples/server/petstore/java-play-framework/build.sbt +++ b/samples/server/petstore/java-play-framework/build.sbt @@ -10,7 +10,6 @@ libraryDependencies ++= Seq( javaJdbc, cache, javaWs, -"io.swagger" %% "swagger-play2" % "1.5.3", -"org.webjars" % "swagger-ui" % "2.2.8", +"org.webjars" % "swagger-ui" % "2.2.10-1", "javax.validation" % "validation-api" % "1.1.0.Final" ) diff --git a/samples/server/petstore/java-play-framework/conf/application.conf b/samples/server/petstore/java-play-framework/conf/application.conf index 56ec60e771a..c69d0c9154d 100644 --- a/samples/server/petstore/java-play-framework/conf/application.conf +++ b/samples/server/petstore/java-play-framework/conf/application.conf @@ -1,9 +1,3 @@ -springfox.documentation.swagger.v2.path=/api-docs -server.contextPath=/ -server.port=9000 -spring.jackson.date-format=io.swagger.RFC3339DateFormat -spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false - # This is the main configuration file for the application. # https://www.playframework.com/documentation/latest/ConfigFile # ~~~~~ @@ -64,9 +58,6 @@ play.modules { # By default, Play will load any class called Module that is defined # in the root package (the "app" directory), or you can define them # explicitly below. -# If there are any built-in modules that you want to disable, you can list them here. -enabled += "play.modules.swagger.SwaggerModule" - # If there are any built-in modules that you want to disable, you can list them here. #disabled += "" } diff --git a/samples/server/petstore/java-play-framework/conf/routes b/samples/server/petstore/java-play-framework/conf/routes index 25f8880e2d5..959827bae04 100644 --- a/samples/server/petstore/java-play-framework/conf/routes +++ b/samples/server/petstore/java-play-framework/conf/routes @@ -6,35 +6,30 @@ GET /api controllers.ApiDocController.api #Functions for Pet API -POST /pet controllers.PetApiController.addPet() -DELETE /pet/:petId controllers.PetApiController.deletePet(petId: Long) -GET /pet/findByStatus controllers.PetApiController.findPetsByStatus() -GET /pet/findByTags controllers.PetApiController.findPetsByTags() -GET /pet/:petId controllers.PetApiController.getPetById(petId: Long) -PUT /pet controllers.PetApiController.updatePet() -POST /pet/:petId controllers.PetApiController.updatePetWithForm(petId: String) -POST /pet/:petId/uploadImage controllers.PetApiController.uploadFile(petId: Long) +POST /v2/pet controllers.PetApiController.addPet() +DELETE /v2/pet/:petId controllers.PetApiController.deletePet(petId: Long) +GET /v2/pet/findByStatus controllers.PetApiController.findPetsByStatus() +GET /v2/pet/findByTags controllers.PetApiController.findPetsByTags() +GET /v2/pet/:petId controllers.PetApiController.getPetById(petId: Long) +PUT /v2/pet controllers.PetApiController.updatePet() +POST /v2/pet/:petId controllers.PetApiController.updatePetWithForm(petId: String) +POST /v2/pet/:petId/uploadImage controllers.PetApiController.uploadFile(petId: Long) #Functions for Store API -DELETE /store/order/:orderId controllers.StoreApiController.deleteOrder(orderId: String) -GET /store/inventory controllers.StoreApiController.getInventory() -GET /store/order/:orderId controllers.StoreApiController.getOrderById(orderId: String) -POST /store/order controllers.StoreApiController.placeOrder() +DELETE /v2/store/order/:orderId controllers.StoreApiController.deleteOrder(orderId: String) +GET /v2/store/inventory controllers.StoreApiController.getInventory() +GET /v2/store/order/:orderId controllers.StoreApiController.getOrderById(orderId: String) +POST /v2/store/order controllers.StoreApiController.placeOrder() #Functions for User API -POST /user controllers.UserApiController.createUser() -POST /user/createWithArray controllers.UserApiController.createUsersWithArrayInput() -POST /user/createWithList controllers.UserApiController.createUsersWithListInput() -DELETE /user/:username controllers.UserApiController.deleteUser(username: String) -GET /user/:username controllers.UserApiController.getUserByName(username: String) -GET /user/login controllers.UserApiController.loginUser() -GET /user/logout controllers.UserApiController.logoutUser() -PUT /user/:username controllers.UserApiController.updateUser(username: String) +POST /v2/user controllers.UserApiController.createUser() +POST /v2/user/createWithArray controllers.UserApiController.createUsersWithArrayInput() +POST /v2/user/createWithList controllers.UserApiController.createUsersWithListInput() +DELETE /v2/user/:username controllers.UserApiController.deleteUser(username: String) +GET /v2/user/:username controllers.UserApiController.getUserByName(username: String) +GET /v2/user/login controllers.UserApiController.loginUser() +GET /v2/user/logout controllers.UserApiController.logoutUser() +PUT /v2/user/:username controllers.UserApiController.updateUser(username: String) # Map static resources from the /public folder to the /assets URL path -GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) - -GET /api-docs controllers.ApiHelpController.getResources -GET /api-docs.json/Pet controllers.ApiHelpController.getResource(path = "/Pet") -GET /api-docs.json/Store controllers.ApiHelpController.getResource(path = "/Store") -GET /api-docs.json/User controllers.ApiHelpController.getResource(path = "/User") +GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/public/swagger.json b/samples/server/petstore/java-play-framework/public/swagger.json new file mode 100644 index 00000000000..72461ab5d3d --- /dev/null +++ b/samples/server/petstore/java-play-framework/public/swagger.json @@ -0,0 +1,808 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "termsOfService" : "http://helloreverb.com/terms/", + "contact" : { + "email" : "apiteam@wordnik.com" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : false, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : false, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByStatus" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by status", + "description" : "Multiple status values can be provided with comma separated strings", + "operationId" : "findPetsByStatus", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : false, + "type" : "array", + "items" : { + "type" : "string", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "multi", + "default" : "available" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + }, + "examples" : { + "application/json" : { + "name" : "Puma", + "type" : "Dog", + "color" : "Black", + "gender" : "Female", + "breed" : "Mixed" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : false, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "multi" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", + "operationId" : "getPetById", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Pet" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "api_key" : [ ] + }, { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Updates a pet in the store with form data", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "string" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/x-www-form-urlencoded", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "description" : "", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "multipart/form-data", + "x-accepts" : "application/json" + } + }, + "/store/inventory" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Returns pet inventories by status", + "description" : "Returns a map of status codes to quantities", + "operationId" : "getInventory", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : false, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid Order" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order/{orderId}" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Find purchase order by ID", + "description" : "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "store" ], + "summary" : "Delete purchase order by ID", + "description" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Create user", + "description" : "This can only be done by the logged in user.", + "operationId" : "createUser", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : false, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : false, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : false, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : false, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : false, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "string" + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing. ", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/User" + } + }, + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "user" ], + "summary" : "Updated user", + "description" : "This can only be done by the logged in user.", + "operationId" : "updateUser", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : false, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid user supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "user" ], + "summary" : "Delete user", + "description" : "This can only be done by the logged in user.", + "operationId" : "deleteUser", + "produces" : [ "application/json", "application/xml" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + } + }, + "securityDefinitions" : { + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + }, + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + } + }, + "definitions" : { + "User" : { + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "username" : { + "type" : "string" + }, + "firstName" : { + "type" : "string" + }, + "lastName" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "password" : { + "type" : "string" + }, + "phone" : { + "type" : "string" + }, + "userStatus" : { + "type" : "integer", + "format" : "int32", + "description" : "User Status" + } + }, + "xml" : { + "name" : "User" + } + }, + "Category" : { + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "xml" : { + "name" : "Category" + } + }, + "Pet" : { + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/Category" + }, + "name" : { + "type" : "string", + "example" : "doggie" + }, + "photoUrls" : { + "type" : "array", + "xml" : { + "name" : "photoUrl", + "wrapped" : true + }, + "items" : { + "type" : "string" + } + }, + "tags" : { + "type" : "array", + "xml" : { + "name" : "tag", + "wrapped" : true + }, + "items" : { + "$ref" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "xml" : { + "name" : "Pet" + } + }, + "Tag" : { + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "xml" : { + "name" : "Tag" + } + }, + "Order" : { + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "petId" : { + "type" : "integer", + "format" : "int64" + }, + "quantity" : { + "type" : "integer", + "format" : "int32" + }, + "shipDate" : { + "type" : "string", + "format" : "date-time" + }, + "status" : { + "type" : "string", + "description" : "Order Status", + "enum" : [ "placed", "approved", "delivered" ] + }, + "complete" : { + "type" : "boolean" + } + }, + "xml" : { + "name" : "Order" + } + } + } +} \ No newline at end of file