diff --git a/bin/all-petstore.sh b/bin/all-petstore.sh index 7564d9cfdb..8b8fd96226 100755 --- a/bin/all-petstore.sh +++ b/bin/all-petstore.sh @@ -22,6 +22,7 @@ cd $APP_DIR ./bin/android-java-wordnik-api.sh ./bin/dynamic-html.sh ./bin/html.sh +./bin/jaxrs-petstore-server.sh ./bin/java-petstore-filemap.sh ./bin/java-petstore.sh ./bin/java-wordnik-api.sh diff --git a/bin/jaxrs-petstore-server.sh b/bin/jaxrs-petstore-server.sh new file mode 100755 index 0000000000..066651aaca --- /dev/null +++ b/bin/jaxrs-petstore-server.sh @@ -0,0 +1,36 @@ +#!/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 + +root=./modules/swagger-codegen-distribution/pom.xml + +# gets version of swagger-codegen +version=$(sed '//,/<\/project>/d;//!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*\([^<]*\).*,\1,g') + +executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.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="$@ -i http://petstore.swagger.wordnik.com/v2/swagger.json -l jaxrs -o samples/server/petstore/jaxrs -t modules/swagger-codegen/src/main/resources/JavaJaxRS" + +java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/pom.xml b/modules/swagger-codegen/pom.xml index 8f0de9f7dd..9ca956c85a 100644 --- a/modules/swagger-codegen/pom.xml +++ b/modules/swagger-codegen/pom.xml @@ -9,7 +9,7 @@ com.wordnik swagger-codegen jar - swagger-codegen + swagger-codegen (core library) 2.1.0-SNAPSHOT src/main/java diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index e89b0f0b26..92ff8129ef 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -7,9 +7,14 @@ import com.wordnik.swagger.util.Json; import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.*; public class DefaultCodegen { + Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class); + protected String outputFolder = ""; protected Set defaultIncludes = new HashSet(); protected Map typeMapping = new HashMap(); @@ -375,7 +380,7 @@ public class DefaultCodegen { Property prop = impl.getProperties().get(key); if(prop == null) { - System.out.println("null property for " + key); + LOGGER.warn("null property for " + key); } else { CodegenProperty cp = fromProperty(key, prop); @@ -422,7 +427,7 @@ public class DefaultCodegen { public CodegenProperty fromProperty(String name, Property p) { if(p == null) { - System.out.println("unexpected missing property for name " + null); + LOGGER.error("unexpected missing property for name " + null); return null; } CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY); @@ -481,8 +486,7 @@ public class DefaultCodegen { ArrayProperty ap = (ArrayProperty) p; CodegenProperty cp = fromProperty("inner", ap.getItems()); if(cp == null) { - System.out.println("skipping invalid property:"); - Json.prettyPrint(p); + LOGGER.warn("skipping invalid property " + Json.pretty(p)); } else { property.baseType = getSwaggerType(p); @@ -540,7 +544,7 @@ public class DefaultCodegen { } } operationId = builder.toString(); - System.out.println("generated operationId " + operationId); + LOGGER.warn("generated operationId " + operationId); } op.path = path; op.operationId = operationId; @@ -741,7 +745,7 @@ public class DefaultCodegen { if("array".equals(qp.getType())) { Property inner = qp.getItems(); if(inner == null) { - System.out.println("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String"); + LOGGER.warn("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String"); inner = new StringProperty().description("//TODO automatically added by swagger-codegen"); } property = new ArrayProperty(inner); @@ -753,7 +757,7 @@ public class DefaultCodegen { else property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null); if(property == null) { - System.out.println("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String"); + LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String"); property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + qp.getType() + " but not supported"); } CodegenProperty model = fromProperty(qp.getName(), property); diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java index 6c805e993c..3e6702a847 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JaxRSServerCodegen.java @@ -10,8 +10,8 @@ import java.util.*; import java.io.File; public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig { - protected String invokerPackage = "com.wordnik.api"; - protected String groupId = "com.wordnik"; + protected String invokerPackage = "io.swagger.api"; + protected String groupId = "io.swagger"; protected String artifactId = "swagger-server"; protected String artifactVersion = "1.0.0"; protected String sourceFolder = "src/main/java"; @@ -31,8 +31,8 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf modelTemplateFiles.put("model.mustache", ".java"); apiTemplateFiles.put("api.mustache", ".java"); templateDir = "JavaJaxRS"; - apiPackage = "com.wordnik.api"; - modelPackage = "com.wordnik.model"; + apiPackage = "io.swagger.api"; + modelPackage = "io.swagger.model"; additionalProperties.put("invokerPackage", invokerPackage); additionalProperties.put("groupId", groupId); @@ -66,6 +66,22 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf ); } + @Override + public String getTypeDeclaration(Property p) { + if(p instanceof ArrayProperty) { + ArrayProperty ap = (ArrayProperty) p; + Property inner = ap.getItems(); + return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">"; + } + else if (p instanceof MapProperty) { + MapProperty mp = (MapProperty) p; + Property inner = mp.getAdditionalProperties(); + + return getTypeDeclaration(inner); + } + return super.getTypeDeclaration(p); + } + @Override public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { String basePath = resourcePath; diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache index fe287c9ddf..ce99acb1f3 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache @@ -23,6 +23,7 @@ public class {{classname}} { {{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}} {{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} {{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} + // {{returnType}} @ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}) @ApiResponses(value = { {{#responses}} @ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}}, diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache index e0782610ef..a33f899e02 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/pom.mustache @@ -123,14 +123,8 @@ ${servlet-api-version} - - - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - 1.5.0-SNAPSHOT + 1.5.0-M1 8.1.11.v20130520 1.13 1.6.3 diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache index b9cd00b71c..f6181046dd 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/web.mustache @@ -45,7 +45,7 @@ ApiOriginFilter - com.wordnik.api.ApiOriginFilter + {{apiPackage}}.ApiOriginFilter ApiOriginFilter diff --git a/pom.xml b/pom.xml index 2666991140..40db216c56 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.wordnik swagger-codegen-project pom - swagger-codegen + swagger-codegen-project 2.1.0-SNAPSHOT https://github.com/swagger-api/swagger-codegen diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java new file mode 100644 index 0000000000..31bc8a0978 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java @@ -0,0 +1,29 @@ +package io.swagger.client; + +public class ApiException extends Exception { + int code = 0; + String message = null; + + public ApiException() {} + + public ApiException(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} \ No newline at end of file diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java new file mode 100644 index 0000000000..30f7e83c97 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java @@ -0,0 +1,187 @@ +package io.swagger.client; + +import com.fasterxml.jackson.core.JsonGenerator.Feature; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; +import com.sun.jersey.api.client.WebResource.Builder; +import com.sun.jersey.multipart.FormDataMultiPart; + +import javax.ws.rs.core.Response.Status.Family; +import javax.ws.rs.core.MediaType; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.io.IOException; +import java.net.URLEncoder; +import java.io.UnsupportedEncodingException; + +public class ApiInvoker { + private static ApiInvoker INSTANCE = new ApiInvoker(); + private Map hostMap = new HashMap(); + private Map defaultHeaderMap = new HashMap(); + private boolean isDebug = false; + + public void enableDebug() { + isDebug = true; + } + + public static ApiInvoker getInstance() { + return INSTANCE; + } + + public void addDefaultHeader(String key, String value) { + defaultHeaderMap.put(key, value); + } + + public String escapeString(String str) { + try{ + return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20"); + } + catch(UnsupportedEncodingException e) { + return str; + } + } + + public static Object deserialize(String json, String containerType, Class cls) throws ApiException { + try{ + if("List".equals(containerType)) { + JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls); + List response = (List) JsonUtil.getJsonMapper().readValue(json, typeInfo); + return response; + } + else if(String.class.equals(cls)) { + if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) + return json.substring(1, json.length() - 2); + else + return json; + } + else { + return JsonUtil.getJsonMapper().readValue(json, cls); + } + } + catch (IOException e) { + throw new ApiException(500, e.getMessage()); + } + } + + public static String serialize(Object obj) throws ApiException { + try { + if (obj != null) + return JsonUtil.getJsonMapper().writeValueAsString(obj); + else + return null; + } + catch (Exception e) { + throw new ApiException(500, e.getMessage()); + } + } + + public String invokeAPI(String host, String path, String method, Map queryParams, Object body, Map headerParams, Map formParams, String contentType) throws ApiException { + Client client = getClient(host); + + StringBuilder b = new StringBuilder(); + + for(String key : queryParams.keySet()) { + String value = queryParams.get(key); + if (value != null){ + if(b.toString().length() == 0) + b.append("?"); + else + b.append("&"); + b.append(escapeString(key)).append("=").append(escapeString(value)); + } + } + String querystring = b.toString(); + + Builder builder = client.resource(host + path + querystring).accept("application/json"); + for(String key : headerParams.keySet()) { + builder.header(key, headerParams.get(key)); + } + + for(String key : defaultHeaderMap.keySet()) { + if(!headerParams.containsKey(key)) { + builder.header(key, defaultHeaderMap.get(key)); + } + } + ClientResponse response = null; + + if("GET".equals(method)) { + response = (ClientResponse) builder.get(ClientResponse.class); + } + else if ("POST".equals(method)) { + if(body == null) + response = builder.post(ClientResponse.class, null); + else if(body instanceof FormDataMultiPart) { + response = builder.type(contentType).post(ClientResponse.class, body); + } + else + response = builder.type(contentType).post(ClientResponse.class, serialize(body)); + } + else if ("PUT".equals(method)) { + if(body == null) + response = builder.put(ClientResponse.class, serialize(body)); + else { + if("application/x-www-form-urlencoded".equals(contentType)) { + StringBuilder formParamBuilder = new StringBuilder(); + + // encode the form params + for(String key : formParams.keySet()) { + String value = formParams.get(key); + if(value != null && !"".equals(value.trim())) { + if(formParamBuilder.length() > 0) { + formParamBuilder.append("&"); + } + try { + formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8")); + } + catch (Exception e) { + // move on to next + } + } + } + response = builder.type(contentType).put(ClientResponse.class, formParamBuilder.toString()); + } + else + response = builder.type(contentType).put(ClientResponse.class, serialize(body)); + } + } + else if ("DELETE".equals(method)) { + if(body == null) + response = builder.delete(ClientResponse.class, serialize(body)); + else + response = builder.type(contentType).delete(ClientResponse.class, serialize(body)); + } + else { + throw new ApiException(500, "unknown method type " + method); + } + if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { + return null; + } + else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { + return (String) response.getEntity(String.class); + } + else { + throw new ApiException( + response.getClientResponseStatus().getStatusCode(), + response.getEntity(String.class)); + } + } + + private Client getClient(String host) { + if(!hostMap.containsKey(host)) { + Client client = Client.create(); + if(isDebug) + client.addFilter(new LoggingFilter()); + hostMap.put(host, client); + } + return hostMap.get(host); + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/JsonUtil.java b/samples/client/petstore/java/src/main/java/io/swagger/client/JsonUtil.java new file mode 100644 index 0000000000..8e7e686dd0 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/JsonUtil.java @@ -0,0 +1,23 @@ +package io.swagger.client; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.core.JsonGenerator.Feature; + +import com.fasterxml.jackson.datatype.joda.*; + +public class JsonUtil { + public static ObjectMapper mapper; + + static { + mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.registerModule(new JodaModule()); + } + + public static ObjectMapper getJsonMapper() { + return mapper; + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java new file mode 100644 index 0000000000..21306184f1 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/PetApi.java @@ -0,0 +1,403 @@ +package io.swagger.client.api; + +import io.swagger.client.ApiException; +import io.swagger.client.ApiInvoker; + +import io.swagger.client.model.*; + +import java.util.*; + +import io.swagger.client.model.Pet; + +import com.sun.jersey.multipart.FormDataMultiPart; + +import javax.ws.rs.core.MediaType; + +import java.io.File; +import java.util.Map; +import java.util.HashMap; + +public class PetApi { + String basePath = "http://petstore.swagger.wordnik.com/v2"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + + + public void updatePet (Pet body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/pet".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + "application/json","application/xml" + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public void addPet (Pet body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/pet".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + "application/json","application/xml" + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public List findPetsByStatus (List status) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + if(!"null".equals(String.valueOf(status))) + queryParams.put("status", String.valueOf(status)); + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "Pet", Pet.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public List findPetsByTags (List tags) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + if(!"null".equals(String.valueOf(tags))) + queryParams.put("tags", String.valueOf(tags)); + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "Pet", Pet.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public Pet getPetById (Long petId) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/pet/{petId}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (Pet) ApiInvoker.deserialize(response, "", Pet.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public void updatePetWithForm (String petId, String name, String status) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/pet/{petId}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + "application/x-www-form-urlencoded" + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + hasFields = true; + mp.field("name", name, MediaType.MULTIPART_FORM_DATA_TYPE); + + hasFields = true; + mp.field("status", status, MediaType.MULTIPART_FORM_DATA_TYPE); + + if(hasFields) + postBody = mp; + } + else { + formParams.put("name", name); + formParams.put("status", status); + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public void deletePet (String api_key, Long petId) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/pet/{petId}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + headerParams.put("api_key", api_key); + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java new file mode 100644 index 0000000000..63309b2ae3 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/StoreApi.java @@ -0,0 +1,240 @@ +package io.swagger.client.api; + +import io.swagger.client.ApiException; +import io.swagger.client.ApiInvoker; + +import io.swagger.client.model.*; + +import java.util.*; + +import java.util.Map; +import io.swagger.client.model.Order; + +import com.sun.jersey.multipart.FormDataMultiPart; + +import javax.ws.rs.core.MediaType; + +import java.io.File; +import java.util.Map; +import java.util.HashMap; + +public class StoreApi { + String basePath = "http://petstore.swagger.wordnik.com/v2"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + + + public Map getInventory () throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/store/inventory".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (Map) ApiInvoker.deserialize(response, "", Map.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public Order placeOrder (Order body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/store/order".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (Order) ApiInvoker.deserialize(response, "", Order.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public Order getOrderById (String orderId) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (Order) ApiInvoker.deserialize(response, "", Order.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public void deleteOrder (String orderId) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java new file mode 100644 index 0000000000..307fd2b399 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/api/UserApi.java @@ -0,0 +1,445 @@ +package io.swagger.client.api; + +import io.swagger.client.ApiException; +import io.swagger.client.ApiInvoker; + +import io.swagger.client.model.*; + +import java.util.*; + +import io.swagger.client.model.User; +import java.util.*; + +import com.sun.jersey.multipart.FormDataMultiPart; + +import javax.ws.rs.core.MediaType; + +import java.io.File; +import java.util.Map; +import java.util.HashMap; + +public class UserApi { + String basePath = "http://petstore.swagger.wordnik.com/v2"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + + + public void createUser (User body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/user".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public void createUsersWithArrayInput (List body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public void createUsersWithListInput (List body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/user/createWithList".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public String loginUser (String username, String password) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/user/login".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + if(!"null".equals(String.valueOf(username))) + queryParams.put("username", String.valueOf(username)); + if(!"null".equals(String.valueOf(password))) + queryParams.put("password", String.valueOf(password)); + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (String) ApiInvoker.deserialize(response, "", String.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public void logoutUser () throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/user/logout".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public User getUserByName (String username) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/user/{username}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return (User) ApiInvoker.deserialize(response, "", User.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + + + public void updateUser (String username, User body) throws ApiException { + Object postBody = body; + + + // create path and map variables + String path = "/user/{username}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + + + public void deleteUser (String username) throws ApiException { + Object postBody = null; + + + // create path and map variables + String path = "/user/{username}".replaceAll("\\{format\\}","json") + .replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + Map formParams = new HashMap(); + + + + String[] contentTypes = { + + }; + + String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json"; + + if(contentType.startsWith("multipart/form-data")) { + boolean hasFields = false; + FormDataMultiPart mp = new FormDataMultiPart(); + + if(hasFields) + postBody = mp; + } + else { + + } + + try { + String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, postBody, headerParams, formParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Category.java new file mode 100644 index 0000000000..32427482d2 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Category.java @@ -0,0 +1,52 @@ +package io.swagger.client.model; + + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class Category { + private Long id = null; + + //public enum idEnum { }; + + private String name = null; + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Order.java new file mode 100644 index 0000000000..1b1c94c391 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Order.java @@ -0,0 +1,116 @@ +package io.swagger.client.model; + +import java.util.Date; + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class Order { + private Long id = null; + + //public enum idEnum { }; + + private Long petId = null; + + //public enum petIdEnum { }; + + private Integer quantity = null; + + //public enum quantityEnum { }; + + private Date shipDate = null; + private String status = null; + private Boolean complete = null; + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("petId") + public Long getPetId() { + return petId; + } + public void setPetId(Long petId) { + this.petId = petId; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("quantity") + public Integer getQuantity() { + return quantity; + } + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("shipDate") + public Date getShipDate() { + return shipDate; + } + public void setShipDate(Date shipDate) { + this.shipDate = shipDate; + } + + + /** + * Order Status + **/ + @ApiModelProperty(required = false, value = "Order Status") + @JsonProperty("status") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("complete") + public Boolean getComplete() { + return complete; + } + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" petId: ").append(petId).append("\n"); + sb.append(" quantity: ").append(quantity).append("\n"); + sb.append(" shipDate: ").append(shipDate).append("\n"); + sb.append(" status: ").append(status).append("\n"); + sb.append(" complete: ").append(complete).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Pet.java new file mode 100644 index 0000000000..fe374748c0 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Pet.java @@ -0,0 +1,112 @@ +package io.swagger.client.model; + +import io.swagger.client.model.Category; +import io.swagger.client.model.Tag; +import java.util.*; + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class Pet { + private Long id = null; + + //public enum idEnum { }; + + private Category category = null; + private String name = null; + private List photoUrls = new ArrayList() ; + private List tags = new ArrayList() ; + private String status = null; + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("category") + public Category getCategory() { + return category; + } + public void setCategory(Category category) { + this.category = category; + } + + + /** + **/ + @ApiModelProperty(required = true, value = "") + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + /** + **/ + @ApiModelProperty(required = true, value = "") + @JsonProperty("photoUrls") + public List getPhotoUrls() { + return photoUrls; + } + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("tags") + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + + /** + * pet status in the store + **/ + @ApiModelProperty(required = false, value = "pet status in the store") + @JsonProperty("status") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" category: ").append(category).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append(" photoUrls: ").append(photoUrls).append("\n"); + sb.append(" tags: ").append(tags).append("\n"); + sb.append(" status: ").append(status).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Tag.java new file mode 100644 index 0000000000..862a736d60 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/Tag.java @@ -0,0 +1,52 @@ +package io.swagger.client.model; + + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class Tag { + private Long id = null; + + //public enum idEnum { }; + + private String name = null; + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/User.java new file mode 100644 index 0000000000..024515e6b8 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/User.java @@ -0,0 +1,140 @@ +package io.swagger.client.model; + + +import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class User { + private Long id = null; + + //public enum idEnum { }; + + private String username = null; + private String firstName = null; + private String lastName = null; + private String email = null; + private String password = null; + private String phone = null; + private Integer userStatus = null; + + //public enum userStatusEnum { }; + + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("username") + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("firstName") + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("lastName") + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("email") + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("password") + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + + /** + **/ + @ApiModelProperty(required = false, value = "") + @JsonProperty("phone") + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + + /** + * User Status + **/ + @ApiModelProperty(required = false, value = "User Status") + @JsonProperty("userStatus") + public Integer getUserStatus() { + return userStatus; + } + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" username: ").append(username).append("\n"); + sb.append(" firstName: ").append(firstName).append("\n"); + sb.append(" lastName: ").append(lastName).append("\n"); + sb.append(" email: ").append(email).append("\n"); + sb.append(" password: ").append(password).append("\n"); + sb.append(" phone: ").append(phone).append("\n"); + sb.append(" userStatus: ").append(userStatus).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/README.md b/samples/server/petstore/jaxrs/README.md new file mode 100644 index 0000000000..f8a560b776 --- /dev/null +++ b/samples/server/petstore/jaxrs/README.md @@ -0,0 +1,10 @@ +# Swagger generated server + +## Overview +This server was generated by the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. By using the +[swagger-spec](https://github.com/wordnik/swagger-core/wiki) from a remote server, you can easily generate a server stub. This +is an example of building a swagger-enabled scalatra server. + +This example uses the [scalatra](http://scalatra.org/) framework. To see how to make this your own, look here: + +[README](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/scalatra) \ No newline at end of file diff --git a/samples/server/petstore/jaxrs/pom.xml b/samples/server/petstore/jaxrs/pom.xml new file mode 100644 index 0000000000..a8bb02cb55 --- /dev/null +++ b/samples/server/petstore/jaxrs/pom.xml @@ -0,0 +1,135 @@ + + 4.0.0 + io.swagger + swagger-server + jar + swagger-server + 1.0.0 + + src/main/java + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.mortbay.jetty + jetty-maven-plugin + ${jetty-version} + + + /v2 + + target/${project.artifactId}-${project.version} + ${project.basedir}/conf/jetty/webdefault.xml + 8079 + stopit + + + 8002 + 60000 + 8443 + + + + + + start-jetty + pre-integration-test + + run + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + com.wordnik + swagger-jersey-jaxrs + ${swagger-core-version} + + + org.slf4j + slf4j-log4j12 + ${slf4j-version} + + + com.sun.jersey + jersey-core + ${jersey-version} + + + com.sun.jersey + jersey-json + ${jersey-version} + + + com.sun.jersey + jersey-servlet + ${jersey-version} + + + com.sun.jersey.contribs + jersey-multipart + ${jersey-version} + + + com.sun.jersey + jersey-server + ${jersey-version} + + + + org.scalatest + scalatest_2.9.1 + ${scala-test-version} + test + + + junit + junit + ${junit-version} + test + + + javax.servlet + servlet-api + ${servlet-api-version} + + + + 1.5.0-M1 + 8.1.11.v20130520 + 1.13 + 1.6.3 + 1.6.1 + 4.8.1 + 2.5 + + \ No newline at end of file diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiException.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiException.java new file mode 100644 index 0000000000..cae767c039 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiException.java @@ -0,0 +1,9 @@ +package io.swagger.api; + +public class ApiException extends Exception{ + private int code; + public ApiException (int code, String msg) { + super(msg); + this.code = code; + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiOriginFilter.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiOriginFilter.java new file mode 100644 index 0000000000..c2eeacf13d --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiOriginFilter.java @@ -0,0 +1,26 @@ +package io.swagger.api; + +import java.io.IOException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; + +public class ApiOriginFilter implements javax.servlet.Filter { + @Override + 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); + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } +} \ No newline at end of file diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiResponseMessage.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiResponseMessage.java new file mode 100644 index 0000000000..9e5b0ee44e --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/ApiResponseMessage.java @@ -0,0 +1,68 @@ +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; + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/NotFoundException.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/NotFoundException.java new file mode 100644 index 0000000000..9c8410e47a --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/NotFoundException.java @@ -0,0 +1,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; + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/PetApi.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/PetApi.java new file mode 100644 index 0000000000..9aef181a3f --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/PetApi.java @@ -0,0 +1,141 @@ +package io.swagger.api; + +import io.swagger.model.*; + +import com.wordnik.swagger.annotations.*; +import com.sun.jersey.multipart.FormDataParam; + +import io.swagger.model.Pet; + +import java.util.List; +import io.swagger.api.NotFoundException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.*; + +@Path("/pet") +@Api(value = "/pet", description = "the pet API") +public class PetApi { + + @PUT + + @Consumes({ "application/json", "application/xml" }) + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Update an existing pet", notes = "", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 405, message = "Validation exception"), + + @ApiResponse(code = 404, message = "Pet not found"), + + @ApiResponse(code = 400, message = "Invalid ID supplied") }) + + public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ) Pet body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @POST + + @Consumes({ "application/json", "application/xml" }) + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 405, message = "Invalid input") }) + + public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ) Pet body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/findByStatus") + + @Produces({ "application/json", "application/xml" }) + // Pet + @ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma seperated strings", response = Pet.class, responseContainer = "List") + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid status value") }) + + public Response findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter") @QueryParam("status") List status) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/findByTags") + + @Produces({ "application/json", "application/xml" }) + // Pet + @ApiOperation(value = "Finds Pets by tags", notes = "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List") + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid tag value") }) + + public Response findPetsByTags(@ApiParam(value = "Tags to filter by") @QueryParam("tags") List tags) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/{petId}") + + @Produces({ "application/json", "application/xml" }) + // Pet + @ApiOperation(value = "Find pet by ID", notes = "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions", response = Pet.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "Pet not found"), + + @ApiResponse(code = 400, message = "Invalid ID supplied") }) + + public Response getPetById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathParam("petId") Long petId) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @POST + @Path("/{petId}") + @Consumes({ "application/x-www-form-urlencoded" }) + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 405, message = "Invalid input") }) + + public Response updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathParam("petId") String petId, + @ApiParam(value = "Updated name of the pet" )@FormParam("name") String name, + @ApiParam(value = "Updated status of the pet" )@FormParam("status") String status) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @DELETE + @Path("/{petId}") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Deletes a pet", notes = "", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid pet value") }) + + public Response deletePet(@ApiParam(value = "" )@HeaderParam("api_key") String api_key, + @ApiParam(value = "Pet id to delete",required=true ) @PathParam("petId") Long petId) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/StoreApi.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/StoreApi.java new file mode 100644 index 0000000000..1706d63325 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/StoreApi.java @@ -0,0 +1,88 @@ +package io.swagger.api; + +import io.swagger.model.*; + +import com.wordnik.swagger.annotations.*; +import com.sun.jersey.multipart.FormDataParam; + +import java.util.Map; +import io.swagger.model.Order; + +import java.util.List; +import io.swagger.api.NotFoundException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.*; + +@Path("/store") +@Api(value = "/store", description = "the store API") +public class StoreApi { + + @GET + @Path("/inventory") + + @Produces({ "application/json", "application/xml" }) + // Integer + @ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class) + @ApiResponses(value = { }) + + public Response getInventory() + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @POST + @Path("/order") + + @Produces({ "application/json", "application/xml" }) + // Order + @ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class) + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid Order") }) + + public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ) Order body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/order/{orderId}") + + @Produces({ "application/json", "application/xml" }) + // Order + @ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "Order not found"), + + @ApiResponse(code = 400, message = "Invalid ID supplied") }) + + public Response getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathParam("orderId") String orderId) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @DELETE + @Path("/order/{orderId}") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Delete purchase order by ID", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "Order not found"), + + @ApiResponse(code = 400, message = "Invalid ID supplied") }) + + public Response deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathParam("orderId") String orderId) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/UserApi.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/UserApi.java new file mode 100644 index 0000000000..b98f79880b --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/api/UserApi.java @@ -0,0 +1,153 @@ +package io.swagger.api; + +import io.swagger.model.*; + +import com.wordnik.swagger.annotations.*; +import com.sun.jersey.multipart.FormDataParam; + +import io.swagger.model.User; +import java.util.*; + +import java.util.List; +import io.swagger.api.NotFoundException; + +import javax.ws.rs.core.Response; +import javax.ws.rs.*; + +@Path("/user") +@Api(value = "/user", description = "the user API") +public class UserApi { + + @POST + + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { }) + + public Response createUser(@ApiParam(value = "Created user object" ) User body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @POST + @Path("/createWithArray") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class) + @ApiResponses(value = { }) + + public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ) List body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @POST + @Path("/createWithList") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class) + @ApiResponses(value = { }) + + public Response createUsersWithListInput(@ApiParam(value = "List of user object" ) List body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/login") + + @Produces({ "application/json", "application/xml" }) + // String + @ApiOperation(value = "Logs user into the system", notes = "", response = String.class) + @ApiResponses(value = { + @ApiResponse(code = 400, message = "Invalid username/password supplied") }) + + public Response loginUser(@ApiParam(value = "The user name for login") @QueryParam("username") String username, + @ApiParam(value = "The password for login in clear text") @QueryParam("password") String password) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/logout") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class) + @ApiResponses(value = { }) + + public Response logoutUser() + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @GET + @Path("/{username}") + + @Produces({ "application/json", "application/xml" }) + // User + @ApiOperation(value = "Get user by user name", notes = "", response = User.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "User not found"), + + @ApiResponse(code = 400, message = "Invalid username supplied") }) + + public Response getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathParam("username") String username) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @PUT + @Path("/{username}") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "User not found"), + + @ApiResponse(code = 400, message = "Invalid user supplied") }) + + public Response updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathParam("username") String username, + @ApiParam(value = "Updated user object" ) User body) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + + @DELETE + @Path("/{username}") + + @Produces({ "application/json", "application/xml" }) + // Void + @ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 404, message = "User not found"), + + @ApiResponse(code = 400, message = "Invalid username supplied") }) + + public Response deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathParam("username") String username) + throws NotFoundException { + // do some magic! + return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build(); + } + + +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Category.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Category.java new file mode 100644 index 0000000000..e6a7f9e1c7 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Category.java @@ -0,0 +1,46 @@ +package io.swagger.model; + + +import com.wordnik.swagger.annotations.*; + + +@ApiModel(description = "") +public class Category { + /** + **/ + private Long id = null; + /** + **/ + private String name = null; + + + @ApiModelProperty(required = false, value = "") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @ApiModelProperty(required = false, value = "") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Order.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Order.java new file mode 100644 index 0000000000..edbc5250df --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Order.java @@ -0,0 +1,100 @@ +package io.swagger.model; + +import java.util.Date; + +import com.wordnik.swagger.annotations.*; + + +@ApiModel(description = "") +public class Order { + /** + **/ + private Long id = null; + /** + **/ + private Long petId = null; + /** + **/ + private Integer quantity = null; + /** + **/ + private Date shipDate = null; + /** + * Order Status + **/ + private String status = null; + /** + **/ + private Boolean complete = null; + + + @ApiModelProperty(required = false, value = "") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @ApiModelProperty(required = false, value = "") + public Long getPetId() { + return petId; + } + public void setPetId(Long petId) { + this.petId = petId; + } + + + @ApiModelProperty(required = false, value = "") + public Integer getQuantity() { + return quantity; + } + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + + @ApiModelProperty(required = false, value = "") + public Date getShipDate() { + return shipDate; + } + public void setShipDate(Date shipDate) { + this.shipDate = shipDate; + } + + + @ApiModelProperty(required = false, value = "Order Status") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + + @ApiModelProperty(required = false, value = "") + public Boolean getComplete() { + return complete; + } + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" petId: ").append(petId).append("\n"); + sb.append(" quantity: ").append(quantity).append("\n"); + sb.append(" shipDate: ").append(shipDate).append("\n"); + sb.append(" status: ").append(status).append("\n"); + sb.append(" complete: ").append(complete).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Pet.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Pet.java new file mode 100644 index 0000000000..b8de517cb7 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Pet.java @@ -0,0 +1,102 @@ +package io.swagger.model; + +import io.swagger.model.Category; +import io.swagger.model.Tag; +import java.util.*; + +import com.wordnik.swagger.annotations.*; + + +@ApiModel(description = "") +public class Pet { + /** + **/ + private Long id = null; + /** + **/ + private Category category = null; + /** + **/ + private String name = null; + /** + **/ + private List photoUrls = new ArrayList() ; + /** + **/ + private List tags = new ArrayList() ; + /** + * pet status in the store + **/ + private String status = null; + + + @ApiModelProperty(required = false, value = "") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @ApiModelProperty(required = false, value = "") + public Category getCategory() { + return category; + } + public void setCategory(Category category) { + this.category = category; + } + + + @ApiModelProperty(required = true, value = "") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @ApiModelProperty(required = true, value = "") + public List getPhotoUrls() { + return photoUrls; + } + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + @ApiModelProperty(required = false, value = "") + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + + @ApiModelProperty(required = false, value = "pet status in the store") + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" category: ").append(category).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append(" photoUrls: ").append(photoUrls).append("\n"); + sb.append(" tags: ").append(tags).append("\n"); + sb.append(" status: ").append(status).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Tag.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Tag.java new file mode 100644 index 0000000000..ee3ad3baeb --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/Tag.java @@ -0,0 +1,46 @@ +package io.swagger.model; + + +import com.wordnik.swagger.annotations.*; + + +@ApiModel(description = "") +public class Tag { + /** + **/ + private Long id = null; + /** + **/ + private String name = null; + + + @ApiModelProperty(required = false, value = "") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @ApiModelProperty(required = false, value = "") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" name: ").append(name).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/User.java b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/User.java new file mode 100644 index 0000000000..0cf49ba968 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/java/io/swagger/model/User.java @@ -0,0 +1,125 @@ +package io.swagger.model; + + +import com.wordnik.swagger.annotations.*; + + +@ApiModel(description = "") +public class User { + /** + **/ + private Long id = null; + /** + **/ + private String username = null; + /** + **/ + private String firstName = null; + /** + **/ + private String lastName = null; + /** + **/ + private String email = null; + /** + **/ + private String password = null; + /** + **/ + private String phone = null; + /** + * User Status + **/ + private Integer userStatus = null; + + + @ApiModelProperty(required = false, value = "") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @ApiModelProperty(required = false, value = "") + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + + @ApiModelProperty(required = false, value = "") + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + + @ApiModelProperty(required = false, value = "") + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + + + @ApiModelProperty(required = false, value = "") + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + + @ApiModelProperty(required = false, value = "") + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + + @ApiModelProperty(required = false, value = "") + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + + @ApiModelProperty(required = false, value = "User Status") + public Integer getUserStatus() { + return userStatus; + } + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" id: ").append(id).append("\n"); + sb.append(" username: ").append(username).append("\n"); + sb.append(" firstName: ").append(firstName).append("\n"); + sb.append(" lastName: ").append(lastName).append("\n"); + sb.append(" email: ").append(email).append("\n"); + sb.append(" password: ").append(password).append("\n"); + sb.append(" phone: ").append(phone).append("\n"); + sb.append(" userStatus: ").append(userStatus).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/server/petstore/jaxrs/src/main/webapp/WEB-INF/web.xml b/samples/server/petstore/jaxrs/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..2708ad5dd4 --- /dev/null +++ b/samples/server/petstore/jaxrs/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,54 @@ + + + + + jersey + com.sun.jersey.spi.container.servlet.ServletContainer + + com.sun.jersey.config.property.packages + com.wordnik.swagger.jaxrs.json;com.wordnik.swagger.jaxrs.listing;io.swagger.api + + + com.sun.jersey.spi.container.ContainerRequestFilters + com.sun.jersey.api.container.filter.PostReplaceFilter + + + com.sun.jersey.api.json.POJOMappingFeature + true + + 1 + + + + DefaultJaxrsConfig + com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig + + api.version + 1.0.0 + + + swagger.api.title + Swagger Server + + + swagger.api.basepath + http://localhost:8002 + + 2 + + + + jersey + /* + + + ApiOriginFilter + io.swagger.api.ApiOriginFilter + + + ApiOriginFilter + /* + + diff --git a/samples/swagger-dynamic-html/docs/index.html b/samples/swagger-dynamic-html/docs/index.html index 3fc5889337..e6c5488d45 100644 --- a/samples/swagger-dynamic-html/docs/index.html +++ b/samples/swagger-dynamic-html/docs/index.html @@ -90,6 +90,8 @@
    +
  • getInventory
  • +
  • placeOrder
  • getOrderById
  • diff --git a/samples/swagger-dynamic-html/docs/operations/StoreApi.html b/samples/swagger-dynamic-html/docs/operations/StoreApi.html index 75bd19e01a..ecfa5fef65 100644 --- a/samples/swagger-dynamic-html/docs/operations/StoreApi.html +++ b/samples/swagger-dynamic-html/docs/operations/StoreApi.html @@ -4,6 +4,21 @@ +

    getInventory

    +
    +

    +

    Returns a map of status codes to quantities

    +

    URL

    + http://petstore.swagger.wordnik.com/v2/store/inventory +

    HTTP Method

    + GET +

    Response Type

    + +

    Parameters

    +
      + +
    +

    placeOrder


    diff --git a/samples/swagger-html/index.html b/samples/swagger-html/index.html index 077295b4a9..2fc19ee462 100644 --- a/samples/swagger-html/index.html +++ b/samples/swagger-html/index.html @@ -292,8 +292,12 @@
    petId (required)
    Path Parameter — ID of pet that needs to be updated
    - - +
    name (optional)
    + +
    Form Parameter — Updated name of the pet
    +
    status (optional)
    + +
    Form Parameter — Updated status of the pet

    Return type

    @@ -311,7 +315,7 @@

    Parameters

    -
    api_key (required)
    +
    api_key (optional)
    Header Parameter
    petId (required)
    @@ -329,6 +333,23 @@ +
    +
    get: /store/inventory
    +
    getInventory Returns pet inventories by status
    +
    Returns a map of status codes to quantities
    + +

    Parameters

    +
    + +
    +

    Return type

    + + + + +
    +
    +
    post: /store/order
    placeOrder Place an order for a pet