values = uriInfo.getQueryParameters().get(a.value());
+
+ if (values == null || values.isEmpty())
+ return null;
+ if (values.size() > 1) {
+ throw new WebApplicationException(Response.status(Status.BAD_REQUEST).
+ entity(a.value() + " cannot contain multiple values").build());
+ }
+
+ return LocalDateTime.parse(values.get(0));
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/NotFoundException.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/NotFoundException.mustache
new file mode 100644
index 00000000000..40c25c5ea5c
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/NotFoundException.mustache
@@ -0,0 +1,10 @@
+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/JavaJaxRS/jersey2/README.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/README.mustache
new file mode 100644
index 00000000000..808f690a496
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/README.mustache
@@ -0,0 +1,23 @@
+# Swagger Jersey 2 generated server
+
+## Overview
+This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
+[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
+is an example of building a swagger-enabled JAX-RS server.
+
+This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.
+
+To run the server, please execute the following:
+
+```
+mvn clean package jetty:run
+```
+
+You can then view the swagger listing here:
+
+```
+http://localhost:{{serverPort}}{{contextPath}}/swagger.json
+```
+
+Note that if you have configured the `host` to be something other than localhost, the calls through
+swagger-ui will be directed to that host and not localhost!
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/StringUtil.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/StringUtil.mustache
new file mode 100644
index 00000000000..073966b0c21
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/StringUtil.mustache
@@ -0,0 +1,42 @@
+package {{invokerPackage}};
+
+{{>generatedAnnotation}}
+public class StringUtil {
+ /**
+ * Check if the given array contains the given value (with case-insensitive comparison).
+ *
+ * @param array The array
+ * @param value The value to search
+ * @return true if the array contains the value
+ */
+ public static boolean containsIgnoreCase(String[] array, String value) {
+ for (String str : array) {
+ if (value == null && str == null) return true;
+ if (value != null && value.equalsIgnoreCase(str)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Join an array of strings with the given separator.
+ *
+ * Note: This might be replaced by utility method from commons-lang or guava someday
+ * if one of those libraries is added as dependency.
+ *
+ *
+ * @param array The array of strings
+ * @param separator The separator
+ * @return the resulting string
+ */
+ public static String join(String[] array, String separator) {
+ int len = array.length;
+ if (len == 0) return "";
+
+ StringBuilder out = new StringBuilder();
+ out.append(array[0]);
+ for (int i = 1; i < len; i++) {
+ out.append(separator).append(array[i]);
+ }
+ return out.toString();
+ }
+}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/allowableValues.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/allowableValues.mustache
new file mode 100644
index 00000000000..a48256d027a
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/allowableValues.mustache
@@ -0,0 +1 @@
+{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/api.mustache
new file mode 100644
index 00000000000..4200f4aca6e
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/api.mustache
@@ -0,0 +1,55 @@
+package {{package}};
+
+import {{modelPackage}}.*;
+import {{package}}.{{classname}}Service;
+import {{package}}.factories.{{classname}}ServiceFactory;
+
+import io.swagger.annotations.ApiParam;
+
+{{#imports}}import {{import}};
+{{/imports}}
+
+import java.util.List;
+import {{package}}.NotFoundException;
+
+import java.io.InputStream;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.*;
+
+@Path("/{{baseName}}")
+{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
+{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
+@io.swagger.annotations.Api(description = "the {{baseName}} API")
+{{>generatedAnnotation}}
+{{#operations}}
+public class {{classname}} {
+ private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}();
+
+{{#operation}}
+ @{{httpMethod}}
+ {{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
+ {{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
+ {{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
+ @io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
+ {{#authMethods}}@io.swagger.annotations.Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
+ {{#scopes}}@io.swagger.annotations.AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
+ {{/hasMore}}{{/scopes}}
+ }{{/isOAuth}}){{#hasMore}},
+ {{/hasMore}}{{/authMethods}}
+ }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
+ @io.swagger.annotations.ApiResponses(value = { {{#responses}}
+ @io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}){{#hasMore}},
+ {{/hasMore}}{{/responses}} })
+ public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},{{/allParams}}@Context SecurityContext securityContext)
+ throws NotFoundException {
+ return delegate.{{nickname}}({{#allParams}}{{#isFile}}inputStream, fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}},{{/allParams}}securityContext);
+ }
+{{/operation}}
+}
+{{/operations}}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiService.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiService.mustache
new file mode 100644
index 00000000000..50e00e24497
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiService.mustache
@@ -0,0 +1,26 @@
+package {{package}};
+
+import {{package}}.*;
+import {{modelPackage}}.*;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+
+{{#imports}}import {{import}};
+{{/imports}}
+
+import java.util.List;
+import {{package}}.NotFoundException;
+
+import java.io.InputStream;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+
+{{>generatedAnnotation}}
+{{#operations}}
+public abstract class {{classname}}Service {
+ {{#operation}}
+ public abstract Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}},{{/allParams}}SecurityContext securityContext) throws NotFoundException;
+ {{/operation}}
+}
+{{/operations}}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceFactory.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceFactory.mustache
new file mode 100644
index 00000000000..0f321034999
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceFactory.mustache
@@ -0,0 +1,13 @@
+package {{package}}.factories;
+
+import {{package}}.{{classname}}Service;
+import {{package}}.impl.{{classname}}ServiceImpl;
+
+{{>generatedAnnotation}}
+public class {{classname}}ServiceFactory {
+ private final static {{classname}}Service service = new {{classname}}ServiceImpl();
+
+ public static {{classname}}Service get{{classname}}() {
+ return service;
+ }
+}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceImpl.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceImpl.mustache
new file mode 100644
index 00000000000..3d3f4c6cbf7
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/apiServiceImpl.mustache
@@ -0,0 +1,30 @@
+package {{package}}.impl;
+
+import {{package}}.*;
+import {{modelPackage}}.*;
+
+{{#imports}}import {{import}};
+{{/imports}}
+
+import java.util.List;
+import {{package}}.NotFoundException;
+
+import java.io.InputStream;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+
+{{>generatedAnnotation}}
+{{#operations}}
+public class {{classname}}ServiceImpl extends {{classname}}Service {
+ {{#operation}}
+ @Override
+ public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}, {{/allParams}}SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+ {{/operation}}
+}
+{{/operations}}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bodyParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bodyParams.mustache
new file mode 100644
index 00000000000..2b28441d3d0
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bodyParams.mustache
@@ -0,0 +1 @@
+{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bootstrap.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bootstrap.mustache
new file mode 100644
index 00000000000..f7e8efff419
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/bootstrap.mustache
@@ -0,0 +1,31 @@
+package {{apiPackage}};
+
+import io.swagger.jaxrs.config.SwaggerContextService;
+import io.swagger.models.*;
+
+import io.swagger.models.auth.*;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+public class Bootstrap extends HttpServlet {
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ Info info = new Info()
+ .title("{{title}}")
+ .description("{{{appDescription}}}")
+ .termsOfService("{{termsOfService}}")
+ .contact(new Contact()
+ .email("{{infoEmail}}"))
+ .license(new License()
+ .name("{{licenseInfo}}")
+ .url("{{licenseUrl}}"));
+
+ ServletContext context = config.getServletContext();
+ Swagger swagger = new Swagger().info(info);
+
+ new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
+ }
+}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumClass.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumClass.mustache
new file mode 100644
index 00000000000..6010e26704f
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumClass.mustache
@@ -0,0 +1,17 @@
+
+ public enum {{{datatypeWithEnum}}} {
+ {{#allowableValues}}{{#enumVars}}{{{name}}}("{{{value}}}"){{^-last}},
+ {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
+
+ private String value;
+
+ {{{datatypeWithEnum}}}(String value) {
+ this.value = value;
+ }
+
+ @Override
+ @JsonValue
+ public String toString() {
+ return value;
+ }
+ }
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumOuterClass.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumOuterClass.mustache
new file mode 100644
index 00000000000..7aea7b92f22
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/enumOuterClass.mustache
@@ -0,0 +1,3 @@
+public enum {{classname}} {
+ {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}}
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/formParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/formParams.mustache
new file mode 100644
index 00000000000..993d47bb562
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/formParams.mustache
@@ -0,0 +1,3 @@
+{{#isFormParam}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#vendorExtensions.x-multipart}}@FormDataParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{^vendorExtensions.x-multipart}}@FormParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/vendorExtensions.x-multipart}}{{/notFile}}{{#isFile}}
+ @FormDataParam("file") InputStream inputStream,
+ @FormDataParam("file") FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/generatedAnnotation.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/generatedAnnotation.mustache
new file mode 100644
index 00000000000..a47b6faa85b
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/generatedAnnotation.mustache
@@ -0,0 +1 @@
+{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/headerParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/headerParams.mustache
new file mode 100644
index 00000000000..1360d796826
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/headerParams.mustache
@@ -0,0 +1 @@
+{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/jacksonJsonProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/jacksonJsonProvider.mustache
new file mode 100644
index 00000000000..5efcb449bb5
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/jacksonJsonProvider.mustache
@@ -0,0 +1,19 @@
+package {{apiPackage}};
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
+import io.swagger.util.Json;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Produces({MediaType.APPLICATION_JSON})
+public class JacksonJsonProvider extends JacksonJaxbJsonProvider {
+ private static ObjectMapper commonMapper = Json.mapper();
+
+ public JacksonJsonProvider() {
+ super.setMapper(commonMapper);
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/model.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/model.mustache
new file mode 100644
index 00000000000..b9512d2b83c
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/model.mustache
@@ -0,0 +1,16 @@
+package {{package}};
+
+import java.util.Objects;
+{{#imports}}import {{import}};
+{{/imports}}
+
+{{#serializableModel}}import java.io.Serializable;{{/serializableModel}}
+{{#models}}
+{{#model}}{{#description}}
+/**
+ * {{description}}
+ **/{{/description}}
+{{#isEnum}}{{>enumOuterClass}}{{/isEnum}}
+{{^isEnum}}{{>pojo}}{{/isEnum}}
+{{/model}}
+{{/models}}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pathParams.mustache
new file mode 100644
index 00000000000..8d80210b4b4
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pathParams.mustache
@@ -0,0 +1 @@
+{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pojo.mustache
new file mode 100644
index 00000000000..58bfed16381
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pojo.mustache
@@ -0,0 +1,73 @@
+{{#description}}@ApiModel(description = "{{{description}}}"){{/description}}
+{{>generatedAnnotation}}
+public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
+ {{#vars}}{{#isEnum}}
+
+{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
+
+{{>enumClass}}{{/items}}{{/items.isEnum}}
+ private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
+
+ {{#vars}}
+ /**{{#description}}
+ * {{{description}}}{{/description}}{{#minimum}}
+ * minimum: {{minimum}}{{/minimum}}{{#maximum}}
+ * maximum: {{maximum}}{{/maximum}}
+ **/
+ public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
+ this.{{name}} = {{name}};
+ return this;
+ }
+
+ {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
+ @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
+ @JsonProperty("{{baseName}}")
+ public {{{datatypeWithEnum}}} {{getter}}() {
+ return {{name}};
+ }
+ public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
+ this.{{name}} = {{name}};
+ }
+
+ {{/vars}}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ {{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}}
+ return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
+ {{/hasMore}}{{^hasMore}};{{/hasMore}}{{/vars}}{{/hasVars}}{{^hasVars}}
+ return true;{{/hasVars}}
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}});
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("class {{classname}} {\n");
+ {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}}
+ {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n");
+ {{/vars}}sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces
+ * (except the first line).
+ */
+ private String toIndentedString(Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pom.mustache
new file mode 100644
index 00000000000..a2f59b53fe7
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/pom.mustache
@@ -0,0 +1,145 @@
+
+ 4.0.0
+ {{groupId}}
+ {{artifactId}}
+ jar
+ {{artifactId}}
+ {{artifactVersion}}
+
+ src/main/java
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 2.1.1
+
+
+ maven-failsafe-plugin
+ 2.6
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+ org.eclipse.jetty
+ jetty-maven-plugin
+ ${jetty-version}
+
+
+ /
+
+ target/${project.artifactId}-${project.version}
+ 8079
+ stopit
+
+ {{serverPort}}
+ 60000
+
+
+
+
+ start-jetty
+ pre-integration-test
+
+ start
+
+
+ 0
+ true
+
+
+
+ stop-jetty
+ post-integration-test
+
+ stop
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 1.9.1
+
+
+ add-source
+ generate-sources
+
+ add-source
+
+
+
+ src/gen/java
+
+
+
+
+
+
+
+
+
+ io.swagger
+ swagger-jersey2-jaxrs
+ compile
+ ${swagger-core-version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback-version}
+ compile
+
+
+ ch.qos.logback
+ logback-core
+ ${logback-version}
+ compile
+
+
+ junit
+ junit
+ ${junit-version}
+ test
+
+
+ javax.servlet
+ servlet-api
+ ${servlet-api-version}
+
+
+ org.glassfish.jersey.containers
+ jersey-container-servlet-core
+ ${jersey2-version}
+
+
+ org.glassfish.jersey.media
+ jersey-media-multipart
+ ${jersey2-version}
+
+
+
+
+ sonatype-snapshots
+ https://oss.sonatype.org/content/repositories/snapshots
+
+ true
+
+
+
+
+ 1.5.8
+ 9.2.9.v20150224
+ 2.6
+ 1.6.3
+ 4.8.1
+ 1.0.1
+ 2.5
+
+
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/build.properties b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/build.properties
new file mode 100644
index 00000000000..a8c2f849be3
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/build.properties
@@ -0,0 +1 @@
+sbt.version=0.12.0
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/plugins.sbt b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/plugins.sbt
new file mode 100644
index 00000000000..713b7f3e993
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/project/plugins.sbt
@@ -0,0 +1,9 @@
+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/JavaJaxRS/jersey2/queryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/queryParams.mustache
new file mode 100644
index 00000000000..9055e6f16dc
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/queryParams.mustache
@@ -0,0 +1 @@
+{{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/returnTypes.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/returnTypes.mustache
new file mode 100644
index 00000000000..c8f7a56938a
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/returnTypes.mustache
@@ -0,0 +1 @@
+{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceBodyParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceBodyParams.mustache
new file mode 100644
index 00000000000..c7d1abfe527
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceBodyParams.mustache
@@ -0,0 +1 @@
+{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceFormParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceFormParams.mustache
new file mode 100644
index 00000000000..759335ba9ce
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceFormParams.mustache
@@ -0,0 +1 @@
+{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}InputStream inputStream, FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceHeaderParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceHeaderParams.mustache
new file mode 100644
index 00000000000..bd03573d196
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceHeaderParams.mustache
@@ -0,0 +1 @@
+{{#isHeaderParam}}{{{dataType}}} {{paramName}}{{/isHeaderParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/servicePathParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/servicePathParams.mustache
new file mode 100644
index 00000000000..6829cf8c7a6
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/servicePathParams.mustache
@@ -0,0 +1 @@
+{{#isPathParam}}{{{dataType}}} {{paramName}}{{/isPathParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceQueryParams.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceQueryParams.mustache
new file mode 100644
index 00000000000..ff79730471d
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/serviceQueryParams.mustache
@@ -0,0 +1 @@
+{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/web.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/web.mustache
new file mode 100644
index 00000000000..520456fb128
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey2/web.mustache
@@ -0,0 +1,63 @@
+
+
+
+
+ jersey
+ org.glassfish.jersey.servlet.ServletContainer
+
+ jersey.config.server.provider.packages
+
+ io.swagger.jaxrs.listing,
+ io.swagger.sample.resource,
+ {{apiPackage}}
+
+
+
+ jersey.config.server.provider.classnames
+ org.glassfish.jersey.media.multipart.MultiPartFeature
+
+
+ jersey.config.server.wadl.disableWadl
+ true
+
+ 1
+
+
+
+ Jersey2Config
+ io.swagger.jersey.config.JerseyJaxrsConfig
+
+ api.version
+ 1.0.0
+
+
+ swagger.api.title
+ {{{title}}}
+
+
+ swagger.api.basepath
+ {{basePath}}
+
+
+ 2
+
+
+ Bootstrap
+ {{apiPackage}}.Bootstrap
+ 2
+
+
+ jersey
+ {{contextPath}}/*
+
+
+ ApiOriginFilter
+ {{apiPackage}}.ApiOriginFilter
+
+
+ ApiOriginFilter
+ /*
+
+
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/LocalDateTimeProvider.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/LocalDateTimeProvider.mustache
index 591b410b275..5ee7f06bf8e 100644
--- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/LocalDateTimeProvider.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/LocalDateTimeProvider.mustache
@@ -14,7 +14,7 @@ public class LocalDateTimeProvider implements ParamConverterProvider {
@Override
public LocalDateTime fromString(String string) {
- LocalDate localDateTime = LocalDateTime.parse(string);
+ LocalDateTime localDateTime = LocalDateTime.parse(string);
return localDateTime;
}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/model.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/model.mustache
index b9512d2b83c..85d815a79c6 100644
--- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/model.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/model.mustache
@@ -1,6 +1,7 @@
package {{package}};
import java.util.Objects;
+import java.util.ArrayList;
{{#imports}}import {{import}};
{{/imports}}
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pom.mustache
index ad4c4e7655f..3373c53b2ce 100644
--- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pom.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/resteasy/pom.mustache
@@ -145,7 +145,7 @@
- 1.5.7
+ 1.5.8
9.2.9.v20150224
3.0.11.Final
1.6.3
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom-j8-async.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom-j8-async.mustache
index dc18ee3b7fd..257a4611db5 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom-j8-async.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom-j8-async.mustache
@@ -159,7 +159,7 @@
- 1.5.7
+ 1.5.8
9.2.9.v20150224
1.13
1.6.3
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
index 4d5bceecc68..8cb969102e1 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
@@ -118,7 +118,7 @@
- 1.5.7
+ 1.5.8
9.2.9.v20150224
1.13
1.6.3
diff --git a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache
index b8311bd9709..25f5474523f 100644
--- a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache
@@ -15,46 +15,74 @@
}(this, function(superagent) {
'use strict';
- var ApiClient = function ApiClient() {
- /**
- * The base path to put in front of every API call's (relative) path.
+{{#emitJSDoc}} /**
+ * @module ApiClient
+ * @version {{projectVersion}}
+ */
+
+ /**
+ * Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
+ * application to use this class directly - the *Api and model classes provide the public API for the service. The
+ * contents of this file should be regarded as internal but are documented for completeness.
+ * @alias module:ApiClient
+ * @class
+ */
+{{/emitJSDoc}} var exports = function() {
+{{#emitJSDoc}} /**
+ * The base URL against which to resolve every API call's (relative) path.
+ * @type {String}
+ * @default {{basePath}}
*/
- this.basePath = '{{basePath}}'.replace(/\/+$/, '');
-{{=< >=}}
- this.authentications = {<#authMethods><#isBasic>
+{{/emitJSDoc}} this.basePath = '{{basePath}}'.replace(/\/+$/, '');
+
+{{#emitJSDoc}} /**
+ * The authentication methods to be included for all API calls.
+ * @type {Array.}
+ */
+{{/emitJSDoc}}{{=< >=}} this.authentications = {<#authMethods><#isBasic>
'': {type: 'basic'}<#isApiKey>
- '': {type: 'apiKey', in: <#isKeyInHeader>'header'<^isKeyInHeader>'query', name: ''}<#isOAuth>
+ '': {type: 'apiKey', 'in': <#isKeyInHeader>'header'<^isKeyInHeader>'query', name: ''}<#isOAuth>
'': {type: 'oauth2'}<#hasMore>,
};
<={{ }}=>
- /**
+{{#emitJSDoc}} /**
* The default HTTP headers to be included for all API calls.
+ * @type {Array.}
+ * @default {}
*/
- this.defaultHeaders = {};
+{{/emitJSDoc}} this.defaultHeaders = {};
/**
* The default HTTP timeout for all API calls.
+ * @type {Number}
+ * @default 60000
*/
this.timeout = 60000;
};
- ApiClient.prototype.paramToString = function paramToString(param) {
- if (param == null) {
- // return empty string for null and undefined
+{{#emitJSDoc}} /**
+ * Returns a string representation for an actual parameter.
+ * @param param The actual parameter.
+ * @returns {String} The string representation of param
.
+ */
+{{/emitJSDoc}} exports.prototype.paramToString = function(param) {
+ if (param == undefined || param == null) {
return '';
- } else if (param instanceof Date) {
- return param.toJSON();
- } else {
- return param.toString();
}
+ if (param instanceof Date) {
+ return param.toJSON();
+ }
+ return param.toString();
};
- /**
- * Build full URL by appending the given path to base path and replacing
- * path parameter placeholders with parameter values.
+{{#emitJSDoc}} /**
+ * Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values.
* NOTE: query parameters are not handled here.
+ * @param {String} path The path to append to the base URL.
+ * @param {Object} pathParams The parameter values to append.
+ * @returns {String} The encoded path with parameter values substituted.
*/
- ApiClient.prototype.buildUrl = function buildUrl(path, pathParams) {
+{{/emitJSDoc}} exports.prototype.buildUrl = function(path, pathParams) {
if (!path.match(/^\//)) {
path = '/' + path;
}
@@ -72,35 +100,41 @@
return url;
};
- /**
- * Check if the given MIME is a JSON MIME.
- * JSON MIME examples:
- * application/json
- * application/json; charset=UTF8
- * APPLICATION/JSON
+{{#emitJSDoc}} /**
+ * Checks whether the given content type represents JSON.
+ * JSON content type examples:
+ *
+ * - application/json
+ * - application/json; charset=UTF8
+ * - APPLICATION/JSON
+ *
+ * @param {String} contentType The MIME content type to check.
+ * @returns {Boolean} true
if contentType
represents JSON, otherwise false
.
*/
- ApiClient.prototype.isJsonMime = function isJsonMime(mime) {
- return Boolean(mime != null && mime.match(/^application\/json(;.*)?$/i));
+{{/emitJSDoc}} exports.prototype.isJsonMime = function(contentType) {
+ return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
};
- /**
- * Choose a MIME from the given MIMEs with JSON preferred,
- * i.e. return JSON if included, otherwise return the first one.
+{{#emitJSDoc}} /**
+ * Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.
+ * @param {Array.} contentTypes
+ * @returns {String} The chosen content type, preferring JSON.
*/
- ApiClient.prototype.jsonPreferredMime = function jsonPreferredMime(mimes) {
- var len = mimes.length;
- for (var i = 0; i < len; i++) {
- if (this.isJsonMime(mimes[i])) {
- return mimes[i];
+{{/emitJSDoc}} exports.prototype.jsonPreferredMime = function(contentTypes) {
+ for (var i = 0; i < contentTypes.length; i++) {
+ if (this.isJsonMime(contentTypes[i])) {
+ return contentTypes[i];
}
}
- return mimes[0];
+ return contentTypes[0];
};
- /**
- * Check if the given parameter value is like file content.
+{{#emitJSDoc}} /**
+ * Checks whether the given parameter value represents file-like content.
+ * @param param The parameter to check.
+ * @returns {Boolean} true
if param
represents a file.
*/
- ApiClient.prototype.isFileParam = function isFileParam(param) {
+{{/emitJSDoc}} exports.prototype.isFileParam = function(param) {
// fs.ReadStream in Node.js (but not in runtime like browserify)
if (typeof window === 'undefined' &&
typeof require === 'function' &&
@@ -123,16 +157,20 @@
return false;
};
- /**
- * Normalize parameters values:
- * remove nils,
- * keep files and arrays,
- * format to string with `paramToString` for other cases.
+{{#emitJSDoc}} /**
+ * Normalizes parameter values:
+ *
+ * - remove nils
+ * - keep files and arrays
+ * - format to string with `paramToString` for other cases
+ *
+ * @param {Object.} params The parameters as object properties.
+ * @returns {Object.} normalized parameters.
*/
- ApiClient.prototype.normalizeParams = function normalizeParams(params) {
+{{/emitJSDoc}} exports.prototype.normalizeParams = function(params) {
var newParams = {};
for (var key in params) {
- if (params.hasOwnProperty(key) && params[key] != null) {
+ if (params.hasOwnProperty(key) && params[key] != undefined && params[key] != null) {
var value = params[key];
if (this.isFileParam(value) || Array.isArray(value)) {
newParams[key] = value;
@@ -144,11 +182,47 @@
return newParams;
};
- /**
- * Build parameter value according to the given collection format.
- * @param {String} collectionFormat one of 'csv', 'ssv', 'tsv', 'pipes' and 'multi'
+{{#emitJSDoc}} /**
+ * Enumeration of collection format separator strategies.
+ * @enum {String}
+ * @readonly
*/
- ApiClient.prototype.buildCollectionParam = function buildCollectionParam(param, collectionFormat) {
+ exports.CollectionFormatEnum = {
+ /**
+ * Comma-separated values. Value: csv
+ * @const
+ */
+ CSV: ',',
+ /**
+ * Space-separated values. Value: ssv
+ * @const
+ */
+ SSV: ' ',
+ /**
+ * Tab-separated values. Value: tsv
+ * @const
+ */
+ TSV: '\t',
+ /**
+ * Pipe(|)-separated values. Value: pipes
+ * @const
+ */
+ PIPES: '|',
+ /**
+ * Native array. Value: multi
+ * @const
+ */
+ MULTI: 'multi'
+ };
+
+ /**
+ * Builds a string representation of an array-type actual parameter, according to the given collection format.
+ * @param {Array} param An array parameter.
+ * @param {module:ApiClient.CollectionFormatEnum} collectionFormat The array element separator strategy.
+ * @returns {String|Array} A string representation of the supplied collection, using the specified delimiter. Returns
+ * param
as is if collectionFormat
is multi
.
+ */
+{{/emitJSDoc}} exports.prototype.buildCollectionParam = function buildCollectionParam(param, collectionFormat) {
if (param == null) {
return null;
}
@@ -162,14 +236,19 @@
case 'pipes':
return param.map(this.paramToString).join('|');
case 'multi':
- // return the array directly as Superagent will handle it as expected
+ // return the array directly as SuperAgent will handle it as expected
return param.map(this.paramToString);
default:
throw new Error('Unknown collection format: ' + collectionFormat);
}
};
- ApiClient.prototype.applyAuthToRequest = function applyAuthToRequest(request, authNames) {
+{{#emitJSDoc}} /**
+ * Applies authentication headers to the request.
+ * @param {Object} request The request object created by a superagent()
call.
+ * @param {Array.} authNames An array of authentication method names.
+ */
+{{/emitJSDoc}} exports.prototype.applyAuthToRequest = function(request, authNames) {
var _this = this;
authNames.forEach(function(authName) {
var auth = _this.authentications[authName];
@@ -187,7 +266,7 @@
} else {
data[auth.name] = auth.apiKey;
}
- if (auth.in === 'header') {
+ if (auth['in'] === 'header') {
request.set(data);
} else {
request.query(data);
@@ -205,24 +284,58 @@
});
};
- ApiClient.prototype.deserialize = function deserialize(response, returnType) {
+{{#emitJSDoc}} /**
+ * Deserializes an HTTP response body into a value of the specified type.
+ * @param {Object} response A SuperAgent response object.
+ * @param {(String|Array.|Object.|Function)} returnType The type to return. Pass a string for simple types
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
+ * all properties on data will be converted to this type.
+ * @returns A value of the specified type.
+ */
+{{/emitJSDoc}} exports.prototype.deserialize = function deserialize(response, returnType) {
if (response == null || returnType == null) {
return null;
}
- // Rely on Superagent for parsing response body.
+ // Rely on SuperAgent for parsing response body.
// See http://visionmedia.github.io/superagent/#parsing-response-bodies
var data = response.body;
if (data == null) {
- // Superagent does not always produce a body; use the unparsed response
- // as a fallback
+ // SuperAgent does not always produce a body; use the unparsed response as a fallback
data = response.text;
}
- return ApiClient.convertToType(data, returnType);
+ return exports.convertToType(data, returnType);
};
- ApiClient.prototype.callApi = function callApi(path, httpMethod, pathParams,
- queryParams, headerParams, formParams, bodyParam, authNames, contentTypes,
- accepts, returnType{{^usePromises}}, callback{{/usePromises}}) {
+{{#emitJSDoc}}{{^usePromises}} /**
+ * Callback function to receive the result of the operation.
+ * @callback module:ApiClient~callApiCallback
+ * @param {String} error Error message, if any.
+ * @param data The data returned by the service call.
+ * @param {String} response The complete HTTP response.
+ */
+
+{{/usePromises}} /**
+ * Invokes the REST service using the supplied settings and parameters.
+ * @param {String} path The base URL to invoke.
+ * @param {String} httpMethod The HTTP method to use.
+ * @param {Object.} pathParams A map of path parameters and their values.
+ * @param {Object.} queryParams A map of query parameters and their values.
+ * @param {Object.} headerParams A map of header parameters and their values.
+ * @param {Object.} formParams A map of form parameters and their values.
+ * @param {Object} bodyParam The value to pass as the request body.
+ * @param {Array.} authNames An array of authentication type names.
+ * @param {Array.} contentTypes An array of request MIME types.
+ * @param {Array.} accepts An array of acceptable response MIME types.
+ * @param {(String|Array|ObjectFunction)} returnType The required type to return; can be a string for simple types or the
+ * constructor for a complex type.{{^usePromises}}
+ * @param {module:ApiClient~callApiCallback} callback The callback function.
+{{/usePromises}} * @returns {{#usePromises}}{Promise} A Promise object{{/usePromises}}{{^usePromises}}{Object} The SuperAgent request object{{/usePromises}}.
+ */
+{{/emitJSDoc}} exports.prototype.callApi = function callApi(path, httpMethod, pathParams,
+ queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts,
+ returnType{{^usePromises}}, callback{{/usePromises}}) {
+
var _this = this;
var url = this.buildUrl(path, pathParams);
var request = superagent(httpMethod, url);
@@ -236,7 +349,7 @@
// set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));
- //set request timeout
+ // set request timeout
request.timeout(this.timeout);
var contentType = this.jsonPreferredMime(contentTypes);
@@ -269,21 +382,17 @@
request.accept(accept);
}
- {{#usePromises}}
- return new Promise( function(resolve,reject) {
+{{#usePromises}} return new Promise(function(resolve, reject) {
request.end(function(error, response) {
if (error) {
reject(error);
- }
- else {
+ } else {
var data = _this.deserialize(response, returnType);
resolve(data);
}
});
- });
- {{/usePromises}}
- {{^usePromises}}
- request.end(function(error, response) {
+ });{{/usePromises}}
+{{^usePromises}} request.end(function(error, response) {
if (callback) {
var data = null;
if (!error) {
@@ -294,15 +403,27 @@
});
return request;
- {{/usePromises}}
+{{/usePromises}} };
+
+{{#emitJSDoc}} /**
+ * Parses an ISO-8601 string representation of a date value.
+ * @param {String} str The date value as a string.
+ * @returns {Date} The parsed date object.
+ */
+{{/emitJSDoc}} exports.parseDate = function(str) {
+ return new Date(str.replace(/T/i, ' '));
};
- ApiClient.parseDate = function parseDate(str) {
- str = str.replace(/T/i, ' ');
- return new Date(str);
- };
-
- ApiClient.convertToType = function convertToType(data, type) {
+{{#emitJSDoc}} /**
+ * Converts a value to the specified type.
+ * @param {(String|Object)} data The data to convert, as a string or object.
+ * @param {(String|Array.|Object.|Function)} type The type to return. Pass a string for simple types
+ * or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
+ * return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
+ * all properties on data will be converted to this type.
+ * @returns An instance of the specified type.
+ */
+{{/emitJSDoc}} exports.convertToType = function(data, type) {
switch (type) {
case 'Boolean':
return Boolean(data);
@@ -320,13 +441,12 @@
return data;
} else if (typeof type === 'function') {
// for model type like: User
- var model = type.constructFromObject(data);
- return model;
+ return type.constructFromObject(data);
} else if (Array.isArray(type)) {
// for array type like: ['String']
var itemType = type[0];
return data.map(function(item) {
- return ApiClient.convertToType(item, itemType);
+ return exports.convertToType(item, itemType);
});
} else if (typeof type === 'object') {
// for plain object type like: {'String': 'Integer'}
@@ -341,8 +461,8 @@
var result = {};
for (var k in data) {
if (data.hasOwnProperty(k)) {
- var key = ApiClient.convertToType(k, keyType);
- var value = ApiClient.convertToType(data[k], valueType);
+ var key = exports.convertToType(k, keyType);
+ var value = exports.convertToType(data[k], valueType);
result[key] = value;
}
}
@@ -354,7 +474,11 @@
}
};
- ApiClient.default = new ApiClient();
+{{#emitJSDoc}} /**
+ * The default API client implementation.
+ * @type {module:ApiClient}
+ */
+{{/emitJSDoc}} exports.instance = new exports();
- return ApiClient;
+ return exports;
}));
diff --git a/modules/swagger-codegen/src/main/resources/Javascript/README.mustache b/modules/swagger-codegen/src/main/resources/Javascript/README.mustache
new file mode 100644
index 00000000000..633f2f0aebb
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/Javascript/README.mustache
@@ -0,0 +1,138 @@
+# {{projectName}}
+
+{{moduleName}} - JavaScript client for {{projectName}}
+{{#appDescription}}
+{{{appDescription}}}
+{{/appDescription}}
+This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
+
+- API version: {{appVersion}}
+- Package version: {{projectVersion}}
+- Build date: {{generatedDate}}
+- Build package: {{generatorClass}}
+{{#infoUrl}}
+For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
+{{/infoUrl}}
+
+## Installation
+
+### For [Node.js](https://nodejs.org/)
+
+#### npm
+
+To publish the library as a [npm](https://www.npmjs.com/),
+please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages).
+
+Then install it via:
+
+```shell
+npm install {{{projectName}}} --save
+```
+
+#### git
+#
+If the library is hosted at a git repository, e.g.
+https://github.com/{{#gitUserName}}{{.}}{{/gitUserName}}{{^gitUserName}}YOUR_USERNAME{{/gitUserName}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}{{projectName}}{{/gitRepoId}}
+then install it via:
+
+```shell
+npm install {{#gitUserName}}{{.}}{{/gitUserName}}{{^gitUserName}}YOUR_USERNAME{{/gitUserName}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}{{projectName}}{{/gitRepoId}} --save
+```
+
+### For browser
+
+The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following
+the above steps with Node.js and installing browserify with `npm install -g browserify`,
+perform the following (assuming *main.js* is your entry file):
+
+```shell
+browserify main.js > bundle.js
+```
+
+Then include *bundle.js* in the HTML pages.
+
+## Getting Started
+
+Please follow the [installation](#installation) instruction and execute the following JS code:
+
+```javascript
+var {{{moduleName}}} = require('{{{projectName}}}');
+{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
+var defaultClient = {{{moduleName}}}.ApiClient.default;
+{{#authMethods}}{{#isBasic}}
+// Configure HTTP basic authorization: {{{name}}}
+var {{{name}}} = defaultClient.authentications['{{{name}}}'];
+{{{name}}}.username = 'YOUR USERNAME'
+{{{name}}}.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
+// Configure API key authorization: {{{name}}}
+var {{{name}}} = defaultClient.authentications['{{{name}}}'];
+{{{name}}}.apiKey = "YOUR API KEY"
+// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
+//{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token"{{/isApiKey}}{{#isOAuth}}
+// Configure OAuth2 access token for authorization: {{{name}}}
+var {{{name}}} = defaultClient.authentications['{{{name}}}'];
+{{{name}}}.accessToken = "YOUR ACCESS TOKEN"{{/isOAuth}}
+{{/authMethods}}
+{{/hasAuthMethods}}
+
+var api = new {{{moduleName}}}.{{{classname}}}(){{#hasParams}}
+{{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}}
+var {{{paramName}}} = {{{example}}}; // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}
+{{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}}
+var opts = { {{#allParams}}{{^required}}
+ '{{{paramName}}}': {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}{{/required}}{{/allParams}}
+};{{/hasOptionalParams}}{{/hasParams}}
+{{#usePromises}}
+api.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}).then(function({{#returnType}}data{{/returnType}}) {
+ {{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
+}, function(error) {
+ console.error(error);
+});
+
+{{/usePromises}}{{^usePromises}}
+var callback = function(error, data, response) {
+ if (error) {
+ console.error(error);
+ } else {
+ {{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
+ }
+};
+api.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}{{#hasParams}}, {{/hasParams}}callback);
+{{/usePromises}}{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
+```
+
+## Documentation for API Endpoints
+
+All URIs are relative to *{{basePath}}*
+
+Class | Method | HTTP request | Description
+------------ | ------------- | ------------- | -------------
+{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{moduleName}}.{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}}
+{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
+
+## Documentation for Models
+
+{{#models}}{{#model}} - [{{moduleName}}.{{classname}}]({{modelDocPath}}{{classname}}.md)
+{{/model}}{{/models}}
+
+## Documentation for Authorization
+
+{{^authMethods}} All endpoints do not require authorization.
+{{/authMethods}}{{#authMethods}}{{#last}} Authentication schemes defined for the API:{{/last}}{{/authMethods}}
+{{#authMethods}}### {{name}}
+
+{{#isApiKey}}- **Type**: API key
+- **API key parameter name**: {{keyParamName}}
+- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}}
+{{/isApiKey}}
+{{#isBasic}}- **Type**: HTTP basic authentication
+{{/isBasic}}
+{{#isOAuth}}- **Type**: OAuth
+- **Flow**: {{flow}}
+- **Authorizatoin URL**: {{authorizationUrl}}
+- **Scopes**: {{^scopes}}N/A{{/scopes}}
+{{#scopes}} - {{scope}}: {{description}}
+{{/scopes}}
+{{/isOAuth}}
+
+{{/authMethods}}
diff --git a/modules/swagger-codegen/src/main/resources/Javascript/api.mustache b/modules/swagger-codegen/src/main/resources/Javascript/api.mustache
index 79a5fd2a674..8cc6cee18b9 100644
--- a/modules/swagger-codegen/src/main/resources/Javascript/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/Javascript/api.mustache
@@ -1,10 +1,10 @@
{{=< >=}}(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
- define(['../ApiClient'<#imports>, '../model/'], factory);
+ define(['../ApiClient'<#imports>, '../<#modelPackage>/'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
- module.exports = factory(require('../ApiClient')<#imports>, require('../model/'));
+ module.exports = factory(require('../ApiClient')<#imports>, require('../<#modelPackage>/'));
} else {
// Browser globals (root is window)
if (!root.) {
@@ -15,28 +15,50 @@
}(this, function(ApiClient<#imports>, ) {
'use strict';
- var = function (apiClient) {
- this.apiClient = apiClient || ApiClient.default;
+<#emitJSDoc> /**
+ *