forked from loafle/openapi-generator-original
Merge pull request #3185 from cbornet/common_jersey
[Jax-rs][jersey] Mutualize jersey 1 and jersey 2 templates
This commit is contained in:
commit
691957875e
@ -26,6 +26,9 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs -o samples/server/petstore/jaxrs/jersey1 -DhideGenerationTimestamp=true --library=jersey1 --artifact-id=swagger-jaxrs-jersey1-server"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS/libraries/jersey1 -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs -o samples/server/petstore/jaxrs/jersey1 -DhideGenerationTimestamp=true --library=jersey1 --artifact-id=swagger-jaxrs-jersey1-server"
|
||||
|
||||
echo "Removing files and folders under samples/server/petstore/jaxrs/jersey1/src/main"
|
||||
rm -rf samples/server/petstore/jaxrs/jersey1/src/main
|
||||
find samples/server/petstore/jaxrs/jersey1 -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -28,4 +28,7 @@ fi
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs -o samples/server/petstore/jaxrs/jersey2 -DhideGenerationTimestamp=true"
|
||||
|
||||
echo "Removing files and folders under samples/server/petstore/jaxrs/jersey2/src/main"
|
||||
rm -rf samples/server/petstore/jaxrs/jersey2/src/main
|
||||
find samples/server/petstore/jaxrs/jersey2 -maxdepth 1 -type f ! -name "README.md" -exec rm {} +
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs -o samples/server/petstore/jersey2 --library=jersey2 -DhideGenerationTimestamp=true"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -1,4 +1,4 @@
|
||||
# Swagger generated server
|
||||
# Swagger Jersey generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
|
@ -1,10 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {}
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
{{>generatedAnnotation}}
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}}
|
||||
*/
|
||||
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}}({{{value}}}){{^-last}},
|
||||
|
||||
{{/-last}}{{#-last}};
|
||||
{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
private {{datatype}} value;
|
||||
|
||||
{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{datatype}} value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
@ -168,6 +168,9 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey-version>1.19.1</jersey-version>
|
||||
|
@ -1,44 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import org.joda.time.DateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Provider
|
||||
public class JodaDateTimeProvider extends PerRequestTypeInjectableProvider<QueryParam, DateTime> {
|
||||
private final UriInfo uriInfo;
|
||||
|
||||
public JodaDateTimeProvider(@Context UriInfo uriInfo) {
|
||||
super(DateTime.class);
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injectable<DateTime> getInjectable(final ComponentContext cc, final QueryParam a) {
|
||||
return new Injectable<DateTime>() {
|
||||
@Override
|
||||
public DateTime getValue() {
|
||||
final List<String> 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 DateTime.parse(values.get(0));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import org.joda.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Provider
|
||||
public class JodaLocalDateProvider extends PerRequestTypeInjectableProvider<QueryParam, LocalDate> {
|
||||
private final UriInfo uriInfo;
|
||||
|
||||
public JodaLocalDateProvider(@Context UriInfo uriInfo) {
|
||||
super(LocalDate.class);
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injectable<LocalDate> getInjectable(final ComponentContext cc, final QueryParam a) {
|
||||
return new Injectable<LocalDate>() {
|
||||
@Override
|
||||
public LocalDate getValue() {
|
||||
final List<String> 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 LocalDate.parse(values.get(0));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Provider
|
||||
public class LocalDateProvider extends PerRequestTypeInjectableProvider<QueryParam, LocalDate> {
|
||||
private final UriInfo uriInfo;
|
||||
|
||||
public LocalDateProvider(@Context UriInfo uriInfo) {
|
||||
super(LocalDate.class);
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injectable<LocalDate> getInjectable(final ComponentContext cc, final QueryParam a) {
|
||||
return new Injectable<LocalDate>() {
|
||||
@Override
|
||||
public LocalDate getValue() {
|
||||
final List<String> 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 LocalDate.parse(values.get(0));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Provider
|
||||
public class OffsetDateTimeProvider extends PerRequestTypeInjectableProvider<QueryParam, OffsetDateTime> {
|
||||
private final UriInfo uriInfo;
|
||||
|
||||
public OffsetDateTimeProvider(@Context UriInfo uriInfo) {
|
||||
super(OffsetDateTime.class);
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injectable<OffsetDateTime> getInjectable(final ComponentContext cc, final QueryParam a) {
|
||||
return new Injectable<OffsetDateTime>() {
|
||||
@Override
|
||||
public OffsetDateTime getValue() {
|
||||
final List<String> 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 OffsetDateTime.parse(values.get(0));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
# 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!
|
@ -1,42 +0,0 @@
|
||||
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.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
{{#allowableValues}}allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}{{^values}}range=[{{#min}}{{.}}{{/min}}{{^min}}-infinity{{/min}}, {{#max}}{{.}}{{/max}}{{^max}}infinity{{/max}}]{{/values}}"{{/allowableValues}}
|
@ -1 +0,0 @@
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -1,31 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
public enum {{classname}} {
|
||||
{{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}}
|
||||
}
|
@ -1 +0,0 @@
|
||||
{{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
|
@ -1 +0,0 @@
|
||||
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -1,19 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
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}}
|
@ -1 +0,0 @@
|
||||
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
@ -1,73 +0,0 @@
|
||||
{{#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 ");
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
sbt.version=0.12.0
|
@ -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"
|
||||
})
|
@ -1 +0,0 @@
|
||||
{{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#defaultValue}} @DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
|
@ -1 +0,0 @@
|
||||
{{#returnContainer}}{{#isMapContainer}}Map<String, {{{returnType}}}>{{/isMapContainer}}{{#isListContainer}}List<{{{returnType}}}>{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}
|
@ -1 +0,0 @@
|
||||
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -1 +0,0 @@
|
||||
{{#isFormParam}}{{#notFile}}{{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}InputStream inputStream, FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
|
@ -1 +0,0 @@
|
||||
{{#isHeaderParam}}{{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -1 +0,0 @@
|
||||
{{#isPathParam}}{{{dataType}}} {{paramName}}{{/isPathParam}}
|
@ -1 +0,0 @@
|
||||
{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
@ -134,10 +134,12 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.22.2</jersey2-version>
|
||||
<slf4j-version>1.7.21</slf4j-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<logback-version>1.1.7</logback-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AllowableValuesTest {
|
||||
|
||||
private static final String TEMPLATE_FILE = "JavaJaxRS/libraries/jersey1/allowableValues.mustache";
|
||||
private static final String TEMPLATE_FILE = "JavaJaxRS/allowableValues.mustache";
|
||||
private static final String PROVIDER_NAME = "operations";
|
||||
|
||||
private static String loadClassResource(Class<?> cls, String name) throws IOException {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# Thsi matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
|
@ -168,6 +168,9 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>1.7</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey-version>1.19.1</jersey-version>
|
||||
|
@ -2,9 +2,9 @@ package io.swagger.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,16 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {}
|
||||
public void destroy() {}
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
}
|
@ -5,65 +5,65 @@ import javax.xml.bind.annotation.XmlTransient;
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package io.swagger.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import io.swagger.annotations.ApiParam;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -6,8 +6,8 @@ import io.swagger.model.*;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -19,15 +19,12 @@ public class Order {
|
||||
private Integer quantity = null;
|
||||
private Date shipDate = null;
|
||||
|
||||
/**
|
||||
* Order Status
|
||||
*/
|
||||
|
||||
public enum StatusEnum {
|
||||
PLACED("placed"),
|
||||
APPROVED("approved"),
|
||||
DELIVERED("delivered");
|
||||
|
||||
APPROVED("approved"),
|
||||
|
||||
DELIVERED("delivered");
|
||||
private String value;
|
||||
|
||||
StatusEnum(String value) {
|
||||
@ -37,7 +34,7 @@ public class Order {
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,12 @@ public class Pet {
|
||||
private List<String> photoUrls = new ArrayList<String>();
|
||||
private List<Tag> tags = new ArrayList<Tag>();
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
|
||||
public enum StatusEnum {
|
||||
AVAILABLE("available"),
|
||||
PENDING("pending"),
|
||||
SOLD("sold");
|
||||
|
||||
PENDING("pending"),
|
||||
|
||||
SOLD("sold");
|
||||
private String value;
|
||||
|
||||
StatusEnum(String value) {
|
||||
@ -41,7 +38,7 @@ public class Pet {
|
||||
@Override
|
||||
@JsonValue
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,9 @@ import io.swagger.api.impl.PetApiServiceImpl;
|
||||
|
||||
|
||||
public class PetApiServiceFactory {
|
||||
private final static PetApiService service = new PetApiServiceImpl();
|
||||
|
||||
private final static PetApiService service = new PetApiServiceImpl();
|
||||
|
||||
public static PetApiService getPetApi()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
public static PetApiService getPetApi() {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ import io.swagger.api.impl.StoreApiServiceImpl;
|
||||
|
||||
|
||||
public class StoreApiServiceFactory {
|
||||
private final static StoreApiService service = new StoreApiServiceImpl();
|
||||
|
||||
private final static StoreApiService service = new StoreApiServiceImpl();
|
||||
|
||||
public static StoreApiService getStoreApi()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
public static StoreApiService getStoreApi() {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ import io.swagger.api.impl.UserApiServiceImpl;
|
||||
|
||||
|
||||
public class UserApiServiceFactory {
|
||||
private final static UserApiService service = new UserApiServiceImpl();
|
||||
|
||||
private final static UserApiService service = new UserApiServiceImpl();
|
||||
|
||||
public static UserApiService getUserApi()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
public static UserApiService getUserApi() {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import io.swagger.model.*;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# Thsi matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
|
@ -134,10 +134,12 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>1.7</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.22.2</jersey2-version>
|
||||
<slf4j-version>1.7.21</slf4j-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<logback-version>1.1.7</logback-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
|
@ -7,8 +7,8 @@ import io.swagger.api.factories.PetApiServiceFactory;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -6,8 +6,8 @@ import io.swagger.model.*;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -4,8 +4,8 @@ import io.swagger.api.*;
|
||||
import io.swagger.model.*;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import java.io.File;
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
@ -1,23 +0,0 @@
|
||||
# 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:8080/v2/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!
|
@ -1,145 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jaxrs-server</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-jaxrs-server</name>
|
||||
<version>1.0.0</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey2-jaxrs</artifactId>
|
||||
<scope>compile</scope>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet-core</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey2-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.8</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.6</jersey2-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<logback-version>1.0.1</logback-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
</properties>
|
||||
</project>
|
@ -1,10 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
public void destroy() {}
|
||||
|
||||
public void init(FilterConfig filterConfig) throws ServletException {}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
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("Swagger Server")
|
||||
.description("This is a sample server Petstore server. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\nFor this sample, you can use the api key `special-key` to test the authorization filters.\n")
|
||||
.termsOfService("http://swagger.io/terms/")
|
||||
.contact(new Contact()
|
||||
.email("apiteam@swagger.io"))
|
||||
.license(new License()
|
||||
.name("Apache 2.0")
|
||||
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
|
||||
|
||||
ServletContext context = config.getServletContext();
|
||||
Swagger swagger = new Swagger().info(info);
|
||||
|
||||
new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.*;
|
||||
import io.swagger.api.PetApiService;
|
||||
import io.swagger.api.factories.PetApiServiceFactory;
|
||||
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import io.swagger.model.ApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.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("/pet")
|
||||
|
||||
|
||||
@io.swagger.annotations.Api(description = "the pet API")
|
||||
|
||||
public class PetApi {
|
||||
private final PetApiService delegate = PetApiServiceFactory.getPetApi();
|
||||
|
||||
@POST
|
||||
|
||||
@Consumes({ "application/json", "application/xml" })
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Add a new pet to the store", notes = "", response = void.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = void.class) })
|
||||
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet body,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.addPet(body,securityContext);
|
||||
}
|
||||
@DELETE
|
||||
@Path("/{petId}")
|
||||
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = void.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = void.class),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = void.class) })
|
||||
public Response deletePet(@ApiParam(value = "Pet id to delete",required=true) @PathParam("petId") Long petId,@ApiParam(value = "" )@HeaderParam("api_key") String apiKey,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.deletePet(petId,apiKey,securityContext);
|
||||
}
|
||||
@GET
|
||||
@Path("/findByStatus")
|
||||
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid status value", response = Pet.class, responseContainer = "List") })
|
||||
public Response findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter",required=true) @QueryParam("status") List<String> status,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.findPetsByStatus(status,securityContext);
|
||||
}
|
||||
@GET
|
||||
@Path("/findByTags")
|
||||
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Finds Pets by tags", notes = "Muliple tags can be provided with comma separated strings. Use\ntag1, tag2, tag3 for testing.\n", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class, responseContainer = "List") })
|
||||
public Response findPetsByTags(@ApiParam(value = "Tags to filter by",required=true) @QueryParam("tags") List<String> tags,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.findPetsByTags(tags,securityContext);
|
||||
}
|
||||
@GET
|
||||
@Path("/{petId}")
|
||||
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "api_key")
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Pet.class),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Pet.class) })
|
||||
public Response getPetById(@ApiParam(value = "ID of pet to return",required=true) @PathParam("petId") Long petId,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.getPetById(petId,securityContext);
|
||||
}
|
||||
@PUT
|
||||
|
||||
@Consumes({ "application/json", "application/xml" })
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Update an existing pet", notes = "", response = void.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid ID supplied", response = void.class),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = void.class),
|
||||
|
||||
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = void.class) })
|
||||
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet body,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.updatePet(body,securityContext);
|
||||
}
|
||||
@POST
|
||||
@Path("/{petId}")
|
||||
@Consumes({ "application/x-www-form-urlencoded" })
|
||||
@Produces({ "application/xml", "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "null", response = void.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = void.class) })
|
||||
public Response updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true) @PathParam("petId") Long petId,@ApiParam(value = "Updated name of the pet")@FormParam("name") String name,@ApiParam(value = "Updated status of the pet")@FormParam("status") String status,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.updatePetWithForm(petId,name,status,securityContext);
|
||||
}
|
||||
@POST
|
||||
@Path("/{petId}/uploadImage")
|
||||
@Consumes({ "multipart/form-data" })
|
||||
@Produces({ "application/json" })
|
||||
@io.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = ApiResponse.class, authorizations = {
|
||||
@io.swagger.annotations.Authorization(value = "petstore_auth", scopes = {
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
|
||||
@io.swagger.annotations.AuthorizationScope(scope = "read:pets", description = "read your pets")
|
||||
})
|
||||
}, tags={ "pet", })
|
||||
@io.swagger.annotations.ApiResponses(value = {
|
||||
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = ApiResponse.class) })
|
||||
public Response uploadFile(@ApiParam(value = "ID of pet to update",required=true) @PathParam("petId") Long petId,@ApiParam(value = "Additional data to pass to server")@FormDataParam("additionalMetadata") String additionalMetadata,
|
||||
@FormDataParam("file") InputStream inputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileDetail,@Context SecurityContext securityContext)
|
||||
throws NotFoundException {
|
||||
return delegate.uploadFile(petId,additionalMetadata,inputStream, fileDetail,securityContext);
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.api.*;
|
||||
import io.swagger.model.*;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
|
||||
import io.swagger.model.Pet;
|
||||
import io.swagger.model.ApiResponse;
|
||||
import java.io.File;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.api.NotFoundException;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
|
||||
|
||||
public abstract class PetApiService {
|
||||
|
||||
public abstract Response addPet(Pet body,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response deletePet(Long petId,String apiKey,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response findPetsByStatus(List<String> status,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response findPetsByTags(List<String> tags,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response getPetById(Long petId,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response updatePet(Pet body,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response updatePetWithForm(Long petId,String name,String status,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
public abstract Response uploadFile(Long petId,String additionalMetadata,InputStream inputStream, FormDataContentDisposition fileDetail,SecurityContext securityContext) throws NotFoundException;
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user