diff --git a/README.md b/README.md
index cf28a5c38de..d6e54e6e160 100644
--- a/README.md
+++ b/README.md
@@ -13,12 +13,12 @@ The goal of Swaggerâ„¢ is to define a standard, language-agnostic interface to R
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
-## Compatibility
-The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilities with the swagger specification:
+## Compatability
+The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification:
Swagger Codegen Version | Release Date | Swagger Spec compatability | Notes
----------------------- | ------------ | -------------------------- | -----
-2.1.2-M1 (master) | 2015-02-23 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.0-M1](https://github.com/swagger-api/swagger-codegen)
+2.1.3-M1-SNAPSHOT | 2015-02-23 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.0-M1](https://github.com/swagger-api/swagger-codegen)
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.0.17)
1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1)
@@ -46,7 +46,7 @@ You can build a client against the swagger sample [petstore](http://petstore.swa
This will run the generator with this command:
```
-java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
+java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.3-M1-SNAPSHOT.jar \
-i http://petstore.swagger.io/v2/swagger.json \
-l java \
-o samples/client/petstore/java
@@ -93,6 +93,17 @@ Don't like the default swagger client syntax? Want a different language support
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your tempalte folder. It actually is that easy.
+### Making your own codegen modules
+If you're starting a project with a new language and don't see what you need, swagger-codegen can help you create a project to generate your own libraries:
+
+```
+java -cp modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.3-M1-SNAPSHOT.jar \
+ com.wordnik.swagger.codegen.MetaGenerator \
+ -o output/myLibrary -n myClientCodegen -p com.my.company.codegen
+```
+
+This will write, in the folder `output/myLibrary`, all the files you need to get started, including a README.md. Once modified and compiled, you can load your library with the codegen and generate clients with your own, custom-rolled logic.
+
### Where is Javascript???
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require
static code generation.
@@ -189,7 +200,7 @@ You can also use the codegen to generate a server for a couple different framewo
### node.js
```
-java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
+java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.3-M1-SNAPSHOT.jar \
-i http://petstore.swagger.io/v2/swagger.json \
-l nodejs \
-o samples/server/petstore/nodejs
@@ -201,7 +212,7 @@ java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distributi
### scala scalatra
```
-java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
+java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.3-M1-SNAPSHOT.jar \
-i http://petstore.swagger.io/v2/swagger.json \
-l scalatra \
-o samples/server/petstore/scalatra
@@ -210,7 +221,7 @@ java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distributi
### java jax-rs
```
-java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
+java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.3-M1-SNAPSHOT.jar \
-i http://petstore.swagger.io/v2/swagger.json \
-l jaxrs \
-o samples/server/petstore/jaxrs
diff --git a/modules/swagger-codegen-distribution/pom.xml b/modules/swagger-codegen-distribution/pom.xml
index a91d5d0cc8e..634ad084c0c 100644
--- a/modules/swagger-codegen-distribution/pom.xml
+++ b/modules/swagger-codegen-distribution/pom.xml
@@ -2,7 +2,7 @@
com.wordnik
swagger-codegen-project
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
../..
4.0.0
@@ -10,7 +10,7 @@
swagger-codegen-distribution
jar
swagger-codegen (executable)
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
src/test/scala
target/classes
diff --git a/modules/swagger-codegen/pom.xml b/modules/swagger-codegen/pom.xml
index a11e0a719d1..1abd2689b5a 100644
--- a/modules/swagger-codegen/pom.xml
+++ b/modules/swagger-codegen/pom.xml
@@ -2,7 +2,7 @@
com.wordnik
swagger-codegen-project
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
../..
4.0.0
@@ -10,7 +10,7 @@
swagger-codegen
jar
swagger-codegen (core library)
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
src/main/java
install
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/AbstractGenerator.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/AbstractGenerator.java
new file mode 100644
index 00000000000..fa5131dbdc2
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/AbstractGenerator.java
@@ -0,0 +1,60 @@
+package com.wordnik.swagger.codegen;
+
+import com.samskivert.mustache.*;
+
+import java.util.regex.Pattern;
+import java.io.*;
+
+public abstract class AbstractGenerator {
+
+ public File writeToFile(String filename, String contents) throws IOException {
+ System.out.println("writing file " + filename);
+ File output = new File(filename);
+
+ if(output.getParent() != null && !new File(output.getParent()).exists()) {
+ File parent = new File(output.getParent());
+ parent.mkdirs();
+ }
+ Writer out = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(output), "UTF-8"));
+
+ out.write(contents);
+ out.close();
+ return output;
+ }
+
+ public String readTemplate(String name) {
+ try{
+ Reader reader = getTemplateReader(name);
+ if(reader == null)
+ throw new RuntimeException("no file found");
+ java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
+ return s.hasNext() ? s.next() : "";
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ throw new RuntimeException("can't load template " + name);
+ }
+
+ public Reader getTemplateReader(String name) {
+ try{
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
+ if(is == null)
+ is = new FileInputStream(new File(name));
+ if(is == null)
+ throw new RuntimeException("no file found");
+ return new InputStreamReader(is);
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ throw new RuntimeException("can't load template " + name);
+ }
+
+ private String getCPResourcePath(String name) {
+ if (!"/".equals(File.separator))
+ return name.replaceAll(Pattern.quote(File.separator), "/");
+ return name;
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
index 235a9b5ba6b..69db1b9d2da 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
@@ -1,6 +1,7 @@
package com.wordnik.swagger.codegen;
import com.wordnik.swagger.models.*;
+import com.wordnik.swagger.models.auth.SecuritySchemeDefinition;
import com.wordnik.swagger.models.properties.*;
import java.util.*;
@@ -35,6 +36,8 @@ public interface CodegenConfig {
CodegenModel fromModel(String name, Model model);
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation);
+ List fromSecurity(Map schemes);
+
Set defaultIncludes();
Map typeMapping();
Map instantiationTypes();
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java
index 41c877532f0..62f515b6c69 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java
@@ -6,7 +6,8 @@ public enum CodegenModelType {
OPERATION(CodegenOperation.class),
PARAMETER(CodegenParameter.class),
PROPERTY(CodegenProperty.class),
- RESPONSE(CodegenResponse.class);
+ RESPONSE(CodegenResponse.class),
+ SECURITY(CodegenSecurity.class);
private final Class> defaultImplementation;
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java
index af192e7e98a..12b405edeb4 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java
@@ -18,6 +18,7 @@ public class CodegenOperation {
public List queryParams = new ArrayList();
public List headerParams = new ArrayList();
public List formParams = new ArrayList();
+ public List authMethods;
public List tags;
public List responses = new ArrayList();
public final List responseHeaders = new ArrayList();
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenResponse.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenResponse.java
index 92b908759b1..d940e4922eb 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenResponse.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenResponse.java
@@ -6,5 +6,10 @@ public class CodegenResponse {
public String code, message;
public Boolean hasMore;
public List> examples;
+ public String dataType, baseType, containerType;
+ public Boolean simpleType;
+ public Boolean primitiveType;
+ public Boolean isMapContainer;
+ public Boolean isListContainer;
Object schema;
}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenSecurity.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenSecurity.java
new file mode 100644
index 00000000000..7323893106f
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenSecurity.java
@@ -0,0 +1,7 @@
+package com.wordnik.swagger.codegen;
+
+public class CodegenSecurity {
+ String name;
+ String type;
+ Boolean hasMore;
+}
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 014a595ae16..2abcfad31ea 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
@@ -1,17 +1,16 @@
package com.wordnik.swagger.codegen;
import com.wordnik.swagger.models.*;
+import com.wordnik.swagger.models.auth.SecuritySchemeDefinition;
import com.wordnik.swagger.models.parameters.*;
import com.wordnik.swagger.models.properties.*;
import com.wordnik.swagger.util.Json;
-
import org.apache.commons.lang.StringUtils;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
import java.io.File;
+import java.util.*;
public class DefaultCodegen {
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
@@ -142,6 +141,8 @@ public class DefaultCodegen {
return name;
}
+ public String toOperationId(String operationId) { return operationId; }
+
public String toVarName(String name) {
if(reservedWords.contains(name))
return escapeReservedWord(name);
@@ -156,6 +157,7 @@ public class DefaultCodegen {
return name;
}
+
public String escapeReservedWord(String name) {
throw new RuntimeException("reserved word " + name + " not allowed");
}
@@ -439,6 +441,19 @@ public class DefaultCodegen {
return m;
}
+ public static String getterAndSetterCapitalize(String name) {
+ if (name == null || name.length() == 0) {
+ return name;
+ }
+ if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
+ Character.isLowerCase(name.charAt(0))){
+ return name;
+ }
+ char chars[] = name.toCharArray();
+ chars[0] = Character.toUpperCase(chars[0]);
+ return new String(chars);
+ }
+
public CodegenProperty fromProperty(String name, Property p) {
if(p == null) {
LOGGER.error("unexpected missing property for name " + null);
@@ -449,8 +464,8 @@ public class DefaultCodegen {
property.name = toVarName(name);
property.baseName = name;
property.description = escapeText(p.getDescription());
- property.getter = "get" + initialCaps(name);
- property.setter = "set" + initialCaps(name);
+ property.getter = "get" + getterAndSetterCapitalize(name);
+ property.setter = "set" + getterAndSetterCapitalize(name);
property.example = p.getExample();
property.defaultValue = toDefaultValue(p);
@@ -537,6 +552,21 @@ public class DefaultCodegen {
return property;
}
+ private Response findMethodResponse(Map responses) {
+
+ String code = null;
+ for(String responseCode : responses.keySet()) {
+ if (responseCode.startsWith("2") || responseCode.equals("default")) {
+ if (code == null || code.compareTo(responseCode) > 0) {
+ code = responseCode;
+ }
+ }
+ }
+ if (code == null)
+ return null;
+ return responses.get(code);
+ }
+
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation){
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
Set imports = new HashSet();
@@ -566,13 +596,11 @@ public class DefaultCodegen {
LOGGER.warn("generated operationId " + operationId);
}
op.path = path;
- op.operationId = operationId;
+ op.operationId = toOperationId(operationId);
op.summary = escapeText(operation.getSummary());
op.notes = escapeText(operation.getDescription());
op.tags = operation.getTags();
- Response methodResponse = null;
-
if(operation.getConsumes() != null && operation.getConsumes().size() > 0) {
List> c = new ArrayList>();
int count = 0;
@@ -603,76 +631,46 @@ public class DefaultCodegen {
op.hasProduces = true;
}
- if(operation.getResponses() != null) {
- for(String responseCode: new TreeSet(operation.getResponses().keySet())) {
- Response response = operation.getResponses().get(responseCode);
- if (responseCode.startsWith("2")) {
- // use the first, i.e. the smallest 2xx response status as methodResponse
- methodResponse = response;
- break;
- }
+ if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
+
+ Response methodResponse = findMethodResponse(operation.getResponses());
+ CodegenResponse methodCodegenResponse = null;
+
+ for (Map.Entry entry : operation.getResponses().entrySet()) {
+ Response response = entry.getValue();
+ CodegenResponse r = fromResponse(entry.getKey(), response);
+ r.hasMore = true;
+ if(r.baseType != null &&
+ !defaultIncludes.contains(r.baseType) &&
+ !languageSpecificPrimitives.contains(r.baseType))
+ imports.add(r.baseType);
+
+ if (response == methodResponse)
+ methodCodegenResponse = r;
+ op.responses.add(r);
}
- if(methodResponse == null && operation.getResponses().keySet().contains("default")) {
- methodResponse = operation.getResponses().get("default");
- }
- for(String responseCode: operation.getResponses().keySet()) {
- Response response = operation.getResponses().get(responseCode);
- if(response != methodResponse) {
- CodegenResponse r = fromResponse(responseCode, response);
- op.responses.add(r);
- }
- for(int i = 0; i < op.responses.size() - 1; i++) {
- CodegenResponse r = op.responses.get(i);
- r.hasMore = new Boolean(true);
+ op.responses.get(op.responses.size() - 1).hasMore = false;
+
+ if (methodResponse != null) {
+ op.returnType = methodCodegenResponse.dataType;
+ op.returnBaseType = methodCodegenResponse.baseType;
+ op.returnSimpleType = methodCodegenResponse.simpleType;
+ op.returnTypeIsPrimitive = methodCodegenResponse.primitiveType;
+ op.returnContainer = methodCodegenResponse.containerType;
+ op.isListContainer = methodCodegenResponse.isListContainer;
+ op.isMapContainer = methodCodegenResponse.isMapContainer;
+ if (methodResponse.getSchema() != null) {
+ Property responseProperty = methodResponse.getSchema();
+ responseProperty.setRequired(true);
+ CodegenProperty cm = fromProperty("response", responseProperty);
+ op.examples = toExamples(methodResponse.getExamples());
+ op.defaultResponse = toDefaultValue(responseProperty);
+ addHeaders(methodResponse, op.responseHeaders);
}
+
}
}
- if(methodResponse != null) {
- if (methodResponse.getSchema() != null) {
- CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
-
- Property responseProperty = methodResponse.getSchema();
-
- if(responseProperty instanceof ArrayProperty) {
- ArrayProperty ap = (ArrayProperty) responseProperty;
- CodegenProperty innerProperty = fromProperty("response", ap.getItems());
- op.returnBaseType = innerProperty.baseType;
- }
- else {
- if(cm.complexType != null)
- op.returnBaseType = cm.complexType;
- else
- op.returnBaseType = cm.baseType;
- }
- op.examples = toExamples(methodResponse.getExamples());
- op.defaultResponse = toDefaultValue(responseProperty);
- op.returnType = cm.datatype;
- if(cm.isContainer != null) {
- op.returnContainer = cm.containerType;
- if("map".equals(cm.containerType))
- op.isMapContainer = Boolean.TRUE;
- else if ("list".equalsIgnoreCase(cm.containerType))
- op.isListContainer = Boolean.TRUE;
- }
- else
- op.returnSimpleType = true;
- if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null)
- op.returnTypeIsPrimitive = true;
- }
- addHeaders(methodResponse, op.responseHeaders);
- }
-
- if(op.returnBaseType == null) {
- op.returnTypeIsPrimitive = true;
- op.returnSimpleType = true;
- }
-
- if(op.returnBaseType != null &&
- !defaultIncludes.contains(op.returnBaseType) &&
- !languageSpecificPrimitives.contains(op.returnBaseType))
- imports.add(op.returnBaseType);
-
List parameters = operation.getParameters();
CodegenParameter bodyParam = null;
List allParams = new ArrayList();
@@ -752,6 +750,40 @@ public class DefaultCodegen {
r.message = response.getDescription();
r.schema = response.getSchema();
r.examples = toExamples(response.getExamples());
+
+ if (r.schema != null) {
+ Property responseProperty = response.getSchema();
+ responseProperty.setRequired(true);
+ CodegenProperty cm = fromProperty("response", responseProperty);
+
+ if(responseProperty instanceof ArrayProperty) {
+ ArrayProperty ap = (ArrayProperty) responseProperty;
+ CodegenProperty innerProperty = fromProperty("response", ap.getItems());
+ r.baseType = innerProperty.baseType;
+ }
+ else {
+ if(cm.complexType != null)
+ r.baseType = cm.complexType;
+ else
+ r.baseType = cm.baseType;
+ }
+ r.dataType = cm.datatype;
+ if(cm.isContainer != null) {
+ r.simpleType = false;
+ r.containerType = cm.containerType;
+ r.isMapContainer = "map".equals(cm.containerType);
+ r.isListContainer = "list".equals(cm.containerType);
+ }
+ else
+ r.simpleType = true;
+ r.primitiveType = (r.baseType == null ||languageSpecificPrimitives().contains(r.baseType));
+ }
+ if (r.baseType == null) {
+ r.isMapContainer = false;
+ r.isListContainer = false;
+ r.primitiveType = true;
+ r.simpleType = true;
+ }
return r;
}
@@ -849,6 +881,23 @@ public class DefaultCodegen {
return p;
}
+ public List fromSecurity(Map schemes) {
+ if(schemes == null)
+ return null;
+
+ List secs = new ArrayList();
+ for(Iterator entries = schemes.entrySet().iterator(); entries.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) entries.next();
+
+ CodegenSecurity sec = CodegenModelFactory.newInstance(CodegenModelType.SECURITY);
+ sec.name = entry.getKey();
+ sec.type = entry.getValue().getType();
+ sec.hasMore = entries.hasNext();
+ secs.add(sec);
+ }
+ return secs;
+ }
+
protected List> toExamples(Map examples) {
if(examples == null)
return null;
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java
index 65355d75b1f..be143e4ec50 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java
@@ -1,6 +1,7 @@
package com.wordnik.swagger.codegen;
import com.wordnik.swagger.models.*;
+import com.wordnik.swagger.models.auth.SecuritySchemeDefinition;
import com.wordnik.swagger.util.*;
import com.samskivert.mustache.*;
@@ -10,7 +11,7 @@ import java.util.*;
import java.util.regex.*;
import java.io.*;
-public class DefaultGenerator implements Generator {
+public class DefaultGenerator extends AbstractGenerator implements Generator {
protected CodegenConfig config;
protected ClientOptInput opts = null;
protected Swagger swagger = null;
@@ -150,7 +151,7 @@ public class DefaultGenerator implements Generator {
Map apis = new HashMap();
apis.put("apis", allOperations);
if(swagger.getBasePath() != null) {
- bundle.put("basePath", swagger.getBasePath());
+ bundle.put("basePath", basePath);
}
bundle.put("apiInfo", apis);
bundle.put("models", allModels);
@@ -227,20 +228,49 @@ public class DefaultGenerator implements Generator {
return ops;
}
+ public SecuritySchemeDefinition fromSecurity(String name) {
+ Map map = swagger.getSecurityDefinitions();
+ if(map == null)
+ return null;
+ SecuritySchemeDefinition scheme = map.get(name);
+ if(scheme == null)
+ return null;
+ return scheme;
+ }
+
+
+
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map> operations) {
if(operation != null) {
List tags = operation.getTags();
- if(tags == null) {
+ if (tags == null) {
tags = new ArrayList();
tags.add("default");
}
- for(String tag : tags) {
+ for (String tag : tags) {
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation);
co.tags = new ArrayList();
co.tags.add(sanitizeTag(tag));
-
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
+
+ List>> securities = operation.getSecurity();
+ if(securities == null)
+ continue;
+ Map authMethods = new HashMap();
+ for (Map> security : securities) {
+ if (security.size() != 1) {
+ //Not sure what to do
+ continue;
+ }
+ String securityName = security.keySet().iterator().next();
+ SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
+ if(securityDefinition != null)
+ authMethods.put(securityName, securityDefinition);
+ }
+ if(!authMethods.isEmpty()) {
+ co.authMethods = config.fromSecurity(authMethods);
+ }
}
}
}
@@ -259,58 +289,7 @@ public class DefaultGenerator implements Generator {
return buf.toString().replaceAll("[^a-zA-Z ]", "");
}
- public File writeToFile(String filename, String contents) throws IOException {
- System.out.println("writing file " + filename);
- File output = new File(filename);
-
- if(output.getParent() != null && !new File(output.getParent()).exists()) {
- File parent = new File(output.getParent());
- parent.mkdirs();
- }
- Writer out = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(output), "UTF-8"));
-
- out.write(contents);
- out.close();
- return output;
- }
-
- public String readTemplate(String name) {
- try{
- Reader reader = getTemplateReader(name);
- if(reader == null)
- throw new RuntimeException("no file found");
- java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
- return s.hasNext() ? s.next() : "";
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- throw new RuntimeException("can't load template " + name);
- }
-
- public Reader getTemplateReader(String name) {
- try{
- InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
- if(is == null)
- is = new FileInputStream(new File(name));
- if(is == null)
- throw new RuntimeException("no file found");
- return new InputStreamReader(is);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- throw new RuntimeException("can't load template " + name);
- }
-
- private String getCPResourcePath(String name) {
- if (!"/".equals(File.separator))
- return name.replaceAll(Pattern.quote(File.separator), "/");
- return name;
- }
-
-public Map processOperations(CodegenConfig config, String tag, List ops) {
+ public Map processOperations(CodegenConfig config, String tag, List ops) {
Map operations = new HashMap();
Map objs = new HashMap();
objs.put("classname", config.toApiName(tag));
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/MetaGenerator.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/MetaGenerator.java
new file mode 100644
index 00000000000..cc88f9a8000
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/MetaGenerator.java
@@ -0,0 +1,180 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.codegen.languages.*;
+import com.wordnik.swagger.models.Swagger;
+import com.wordnik.swagger.models.auth.AuthorizationValue;
+import com.wordnik.swagger.util.*;
+
+import io.swagger.parser.SwaggerParser;
+
+import com.samskivert.mustache.*;
+
+import org.apache.commons.cli.*;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.Reader;
+import java.util.*;
+
+public class MetaGenerator extends AbstractGenerator {
+ static Map configs = new HashMap();
+ static String configString;
+ static {
+ List extensions = getExtensions();
+ StringBuilder sb = new StringBuilder();
+
+ for(CodegenConfig config : extensions) {
+ if(sb.toString().length() != 0)
+ sb.append(", ");
+ sb.append(config.getName());
+ configs.put(config.getName(), config);
+ configString = sb.toString();
+ }
+ }
+
+ public static void main(String[] args) {
+ new MetaGenerator().generate(args);
+ }
+
+ protected void generate(String[] args) {
+ StringBuilder sb = new StringBuilder();
+ String targetLanguage = null;
+ String outputFolder = null;
+ String name = null;
+ String targetPackage = "com.wordnik.swagger.codegen";
+ final String templateDir = "codegen";
+
+ Options options = new Options();
+ options.addOption("h", "help", false, "shows this message");
+ options.addOption("l", "lang", false, "client language to generate.\nAvailable languages include:\n\t[" + configString + "]");
+ options.addOption("o", "output", true, "where to write the generated files");
+ options.addOption("n", "name", true, "the human-readable name of the generator");
+ options.addOption("p", "package", true, "the package to put the main class into (defaults to com.wordnik.swagger.codegen");
+
+ ClientOptInput clientOptInput = new ClientOptInput();
+ Swagger swagger = null;
+ CommandLine cmd = null;
+ try {
+ CommandLineParser parser = new BasicParser();
+
+ cmd = parser.parse(options, args);
+ if (cmd.hasOption("h")) {
+ usage(options);
+ return;
+ }
+ if (cmd.hasOption("n"))
+ name = cmd.getOptionValue("n");
+ else {
+ System.out.println("name is required");
+ usage(options);
+ return;
+ }
+ if (cmd.hasOption("l"))
+ targetLanguage = cmd.getOptionValue("l");
+ if (cmd.hasOption("p"))
+ targetPackage = cmd.getOptionValue("p");
+ if (cmd.hasOption("o"))
+ outputFolder = cmd.getOptionValue("o");
+ else {
+ System.out.println("output folder is required");
+ usage(options);
+ return;
+ }
+ }
+ catch (Exception e) {
+ usage(options);
+ return;
+ }
+ System.out.println("writing to folder " + outputFolder);
+ File outputFolderLocation = new File(outputFolder);
+ if(!outputFolderLocation.exists())
+ outputFolderLocation.mkdirs();
+ File sourceFolder = new File(outputFolder + File.separator + "src/main/java/" + targetPackage.replace('.', File.separatorChar));
+ if(!sourceFolder.exists())
+ sourceFolder.mkdirs();
+ File resourcesFolder = new File(outputFolder + File.separator + "src/main/resources/META-INF/services");
+ if(!resourcesFolder.exists())
+ resourcesFolder.mkdirs();
+
+ String mainClass = Character.toUpperCase(name.charAt(0)) + name.substring(1) + "Generator";
+
+ List supportingFiles = new ArrayList();
+ supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
+ supportingFiles.add(new SupportingFile("generatorClass.mustache",
+ "src/main/java/" + File.separator + targetPackage.replace('.', File.separatorChar),
+ mainClass + ".java"));
+ supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
+ supportingFiles.add(new SupportingFile("api.template", "src/main/resources" + File.separator + name, "api.mustache"));
+ supportingFiles.add(new SupportingFile("model.template", "src/main/resources" + File.separator + name, "model.mustache"));
+
+ supportingFiles.add(new SupportingFile("services.mustache", "src/main/resources/META-INF/services", "com.wordnik.swagger.codegen.CodegenConfig"));
+
+ List files = new ArrayList();
+
+ Map data = new HashMap();
+ data.put("generatorPackage", targetPackage);
+ data.put("generatorClass", mainClass);
+ data.put("name", name);
+ data.put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass);
+
+ for(SupportingFile support : supportingFiles) {
+ try {
+ String destinationFolder = outputFolder;
+ if(support.folder != null && !"".equals(support.folder))
+ destinationFolder += File.separator + support.folder;
+ File of = new File(destinationFolder);
+ if(!of.isDirectory())
+ of.mkdirs();
+ String outputFilename = destinationFolder + File.separator + support.destinationFilename;
+
+ if(support.templateFile.endsWith("mustache")) {
+ String template = readTemplate(templateDir + File.separator + support.templateFile);
+ Template tmpl = Mustache.compiler()
+ .withLoader(new Mustache.TemplateLoader() {
+ public Reader getTemplate (String name) {
+ return getTemplateReader(templateDir + File.separator + name + ".mustache");
+ };
+ })
+ .defaultValue("")
+ .compile(template);
+
+ writeToFile(outputFilename, tmpl.execute(data));
+ files.add(new File(outputFilename));
+ }
+ else {
+ String template = readTemplate(templateDir + File.separator + support.templateFile);
+ FileUtils.writeStringToFile(new File(outputFilename), template);
+ System.out.println("copying file to " + outputFilename);
+ files.add(new File(outputFilename));
+ }
+ }
+ catch (java.io.IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static List getExtensions() {
+ ServiceLoader loader = ServiceLoader.load(CodegenConfig.class);
+ List output = new ArrayList();
+ Iterator itr = loader.iterator();
+ while(itr.hasNext()) {
+ output.add(itr.next());
+ }
+ return output;
+ }
+
+ static void usage(Options options) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "MetaGenerator. Generator for creating a new template set " +
+ "and configuration for Codegen. The output will be based on the language you " +
+ "specify, and includes default templates to include.", options );
+ }
+
+ public static CodegenConfig getConfig(String name) {
+ if(configs.containsKey(name)) {
+ return configs.get(name);
+ }
+ return null;
+ }
+}
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java
index 915ff34c7f1..72e0985d229 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java
@@ -34,6 +34,17 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model";
+ reservedWords = new HashSet (
+ Arrays.asList(
+ "abstract", "continue", "for", "new", "switch", "assert",
+ "default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
+ "this", "break", "double", "implements", "protected", "throw", "byte", "else",
+ "import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
+ "catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
+ "void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
+ "native", "super", "while")
+ );
+
additionalProperties.put("invokerPackage", invokerPackage);
additionalProperties.put("groupId", groupId);
additionalProperties.put("artifactId", artifactId);
diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache
index 3b5001b9e12..b5ebb30f193 100644
--- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/api.mustache
@@ -2,7 +2,8 @@ package {{package}};
import {{modelPackage}}.*;
-import com.wordnik.swagger.annotations.*;
+import com.wordnik.swagger.annotations.ApiParam;
+
import com.sun.jersey.multipart.FormDataParam;
{{#imports}}import {{import}};
@@ -20,7 +21,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.*;
@Path("/{{baseName}}")
-@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
+@com.wordnik.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API")
{{#operations}}
public class {{classname}} {
{{#operation}}
@@ -28,10 +29,9 @@ 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}},
+ @com.wordnik.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
+ @com.wordnik.swagger.annotations.ApiResponses(value = { {{#responses}}
+ @com.wordnik.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
{{/hasMore}}{{/responses}} })
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
diff --git a/modules/swagger-codegen/src/main/resources/codegen/README.mustache b/modules/swagger-codegen/src/main/resources/codegen/README.mustache
new file mode 100644
index 00000000000..d40b9b35813
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/codegen/README.mustache
@@ -0,0 +1,74 @@
+# Swagger Codegen for the {{name}} library
+
+## Overview
+This is a boiler-plate project to generate your own client library with Swagger. It's goal is
+to get you started with the basic plumbing so you can put in your own logic. It won't work without
+your changes applied.
+
+## What's Swagger?
+The goal of Swaggerâ„¢ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
+
+
+Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
+
+## How do I use this?
+At this point, you've likely generated a client setup. It will include something along these lines:
+
+```
+.
+|- README.md // this file
+|- pom.xml // build script
+|-- src
+|--- main
+|---- java
+|----- {{generatorPackage}}.{{generatorClass}}.java // generator file
+|---- resources
+|----- {{name}} // template files
+|----- META-INF
+|------ services
+|------- com.wordnik.swagger.codegen.CodegenConfig
+```
+
+You _will_ need to make changes in at least the following:
+
+`{{generatorClass}}.java`
+
+Templates in this folder:
+
+`src/main/resources/{{name}}`
+
+Once modified, you can run this:
+
+```
+mvn package
+```
+
+In your generator project. A single jar file will be produced in `target`. You can now use that with codegen:
+
+```
+java -cp /path/to/swagger-codegen-distribution:/path/to/your/jar com.wordnik.swagger.codegen.Codegen -l {{name}} -o ./test
+```
+
+Now your templates are available to the client generator and you can write output values
+
+## But how do I modify this?
+The `{{generatorClass}}.java` has comments in it--lots of comments. There is no good substitute
+for reading the code more, though. See how the `{{generatorClass}}` implements `CodegenConfig`.
+That class has the signature of all values that can be overridden.
+
+For the templates themselves, you have a number of values available to you for generation.
+You can execute the `java` command from above while passing different debug flags to show
+the object you have available during client generation:
+
+```
+# The following additional debug options are available for all codegen targets:
+# -DdebugSwagger prints the swagger specification as interpreted by the codegen
+# -DdebugModels prints models passed to the template engine
+# -DdebugOperations prints operations passed to the template engine
+# -DdebugSupportingFiles prints additional data passed to the template engine
+
+java -DdebugOperations -cp /path/to/swagger-codegen-distribution:/path/to/your/jar com.wordnik.swagger.codegen.Codegen -l {{name}} -o ./test
+```
+
+Will, for example, output the debug info for operations. You can use this info
+in the `api.mustache` file.
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/codegen/api.template b/modules/swagger-codegen/src/main/resources/codegen/api.template
new file mode 100644
index 00000000000..9dbc8dd4ba1
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/codegen/api.template
@@ -0,0 +1,28 @@
+
+# This is a sample api mustache template. It is representing a ficticous
+# language and won't be usable or compile to anything without lots of changes.
+# Use it as an example. You can access the variables in the generator object
+# like such:
+
+# use the package from the `apiPackage` variable
+package: {{package}}
+
+# operations block
+{{#operations}}
+classname: {{classname}}
+
+# loop over each operation in the API:
+{{#operation}}
+
+# each operation has a `nickname`:
+nickname: {{nickname}}
+
+# and parameters:
+{{#allParams}}
+{{paramName}}: {{dataType}}
+{{/allParams}}
+
+{{/operation}}
+
+# end of operations block
+{{/operations}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/codegen/generatorClass.mustache b/modules/swagger-codegen/src/main/resources/codegen/generatorClass.mustache
new file mode 100644
index 00000000000..53b3a60ad1b
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/codegen/generatorClass.mustache
@@ -0,0 +1,191 @@
+package {{generatorPackage}};
+
+import com.wordnik.swagger.codegen.*;
+import com.wordnik.swagger.models.properties.*;
+
+import java.util.*;
+import java.io.File;
+
+public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig {
+
+ // source folder where to write the files
+ protected String sourceFolder = "src";
+ protected String apiVersion = "1.0.0";
+
+ /**
+ * Configures the type of generator.
+ *
+ * @return the CodegenType for this generator
+ * @see com.wordnik.swagger.codegen.CodegenType
+ */
+ public CodegenType getTag() {
+ return CodegenType.CLIENT;
+ }
+
+ /**
+ * Configures a friendly name for the generator. This will be used by the generator
+ * to select the library with the -l flag.
+ *
+ * @return the friendly name for the generator
+ */
+ public String getName() {
+ return "{{name}}";
+ }
+
+ /**
+ * Returns human-friendly help for the generator. Provide the consumer with help
+ * tips, parameters here
+ *
+ * @return A string value for the help message
+ */
+ public String getHelp() {
+ return "Generates a {{name}} client library.";
+ }
+
+ public {{generatorClass}}() {
+ super();
+
+ // set the output folder here
+ outputFolder = "generated-code/{{name}}";
+
+ /**
+ * Models. You can write model files using the modelTemplateFiles map.
+ * if you want to create one template for file, you can do so here.
+ * for multiple files for model, just put another entry in the `modelTemplateFiles` with
+ * a different extension
+ */
+ modelTemplateFiles.put(
+ "model.mustache", // the template to use
+ ".sample"); // the extension for each file to write
+
+ /**
+ * Api classes. You can write classes for each Api file with the apiTemplateFiles map.
+ * as with models, add multiple entries with different extensions for multiple files per
+ * class
+ */
+ apiTemplateFiles.put(
+ "api.mustache", // the template to use
+ ".sample"); // the extension for each file to write
+
+ /**
+ * Template Location. This is the location which templates will be read from. The generator
+ * will use the resource stream to attempt to read the templates.
+ */
+ templateDir = "{{name}}";
+
+ /**
+ * Api Package. Optional, if needed, this can be used in templates
+ */
+ apiPackage = "io.swagger.client.api";
+
+ /**
+ * Model Package. Optional, if needed, this can be used in templates
+ */
+ modelPackage = "io.swagger.client.model";
+
+ /**
+ * Reserved words. Override this with reserved words specific to your language
+ */
+ reservedWords = new HashSet (
+ Arrays.asList(
+ "sample1", // replace with static values
+ "sample2")
+ );
+
+ /**
+ * Additional Properties. These values can be passed to the templates and
+ * are available in models, apis, and supporting files
+ */
+ additionalProperties.put("apiVersion", apiVersion);
+
+ /**
+ * Supporting Files. You can write single files for the generator with the
+ * entire object tree available. If the input file has a suffix of `.mustache
+ * it will be processed by the template engine. Otherwise, it will be copied
+ */
+ supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
+ "", // the destination folder, relative `outputFolder`
+ "myFile.sample") // the output file
+ );
+
+ /**
+ * Language Specific Primitives. These types will not trigger imports by
+ * the client generator
+ */
+ languageSpecificPrimitives = new HashSet(
+ Arrays.asList(
+ "Type1", // replace these with your types
+ "Type2")
+ );
+ }
+
+ /**
+ * Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
+ * those terms here. This logic is only called if a variable matches the reseved words
+ *
+ * @return the escaped term
+ */
+ @Override
+ public String escapeReservedWord(String name) {
+ return "_" + name; // add an underscore to the name
+ }
+
+ /**
+ * Location to write model files. You can use the modelPackage() as defined when the class is
+ * instantiated
+ */
+ public String modelFileFolder() {
+ return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
+ }
+
+ /**
+ * Location to write api files. You can use the apiPackage() as defined when the class is
+ * instantiated
+ */
+ @Override
+ public String apiFileFolder() {
+ return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
+ }
+
+ /**
+ * Optional - type declaration. This is a String which is used by the templates to instantiate your
+ * types. There is typically special handling for different property types
+ *
+ * @return a string value used as the `dataType` field for model templates, `returnType` for api templates
+ */
+ @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 getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
+ }
+ return super.getTypeDeclaration(p);
+ }
+
+ /**
+ * Optional - swagger type conversion. This is used to map swagger types in a `Property` into
+ * either language specific types via `typeMapping` or into complex models if there is not a mapping.
+ *
+ * @return a string value of the type or complex model for this property
+ * @see com.wordnik.swagger.models.properties.Property
+ */
+ @Override
+ public String getSwaggerType(Property p) {
+ String swaggerType = super.getSwaggerType(p);
+ String type = null;
+ if(typeMapping.containsKey(swaggerType)) {
+ type = typeMapping.get(swaggerType);
+ if(languageSpecificPrimitives.contains(type))
+ return toModelName(type);
+ }
+ else
+ type = swaggerType;
+ return toModelName(type);
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/codegen/model.template b/modules/swagger-codegen/src/main/resources/codegen/model.template
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/modules/swagger-codegen/src/main/resources/codegen/pom.mustache b/modules/swagger-codegen/src/main/resources/codegen/pom.mustache
new file mode 100644
index 00000000000..f827a2f56b6
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/codegen/pom.mustache
@@ -0,0 +1,102 @@
+
+ 4.0.0
+ io.swagger
+ {{name}}-swagger-codegen
+ jar
+ {{name}}-swagger-codegen
+ 1.0.0
+
+ 2.2.0
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12
+
+
+
+ loggerPath
+ conf/log4j.properties
+
+
+ -Xms512m -Xmx1500m
+ methods
+ pertest
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.2
+
+
+
+ jar
+ test-jar
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add_sources
+ generate-sources
+
+ add-source
+
+
+
+ src/main/java
+
+
+
+
+ add_test_sources
+ generate-test-sources
+
+ add-test-source
+
+
+
+ src/test/java
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.3.2
+
+ 1.6
+ 1.6
+
+
+
+
+
+
+ com.wordnik
+ swagger-codegen
+ ${swagger-codegen-version}
+ provided
+
+
+
+ 2.1.2-M1
+ 1.0.0
+ 4.8.1
+
+
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/codegen/services.mustache b/modules/swagger-codegen/src/main/resources/codegen/services.mustache
new file mode 100644
index 00000000000..9b16ae65f14
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/codegen/services.mustache
@@ -0,0 +1 @@
+{{fullyQualifiedGeneratorClass}}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/test/resources/2_0/responseSelectionTest.json b/modules/swagger-codegen/src/test/resources/2_0/responseSelectionTest.json
new file mode 100644
index 00000000000..f698c96425a
--- /dev/null
+++ b/modules/swagger-codegen/src/test/resources/2_0/responseSelectionTest.json
@@ -0,0 +1,139 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "description": "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
+ "version": "1.0.0",
+ "title": "Swagger Petstore",
+ "termsOfService": "http://helloreverb.com/terms/",
+ "contact": {
+ "email": "apiteam@wordnik.com"
+ },
+ "license": {
+ "name": "Apache 2.0",
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
+ }
+ },
+ "host": "petstore.swagger.io",
+ "basePath": "/v2",
+ "schemes": [
+ "http"
+ ],
+ "paths": {
+ "/tests/withTwoHundredAndDefault": {
+ "get": {
+ "summary": "Operation with several unordered 2XX results and one default",
+ "description": "",
+ "operationId": "withTwoHundredAndDefault",
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "default": {
+ "description": "default response",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ "100": {
+ "description": "100 response",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ "202": {
+ "description": "201 response",
+ "schema": {
+ "type": "integer",
+ "format": "int64"
+ }
+ },
+ "203": {
+ "description": "202 response",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ "400": {
+ "description": "400 response",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ "201": {
+ "description": "200 response",
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "/tests/withoutTwoHundredButDefault": {
+ "get": {
+ "summary": "Operation with several unordered 2XX results and one default",
+ "description": "",
+ "operationId": "withoutTwoHundredButDefault",
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "default": {
+ "description": "default response",
+ "schema": {
+ "type": "string"
+ }
+ },
+ "100": {
+ "description": "100 response",
+ "schema": {
+ "type": "integer",
+ "format": "int32"
+ }
+ },
+ "301": {
+ "description": "301 response",
+ "schema": {
+ "type": "integer",
+ "format": "int64"
+ }
+ }
+ }
+ }
+ }
+ },
+ "securityDefinitions": {
+ "api_key": {
+ "type": "apiKey",
+ "name": "api_key",
+ "in": "header"
+ },
+ "petstore_auth": {
+ "type": "oauth2",
+ "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
+ "flow": "implicit",
+ "scopes": {
+ "write:pets": "modify pets in your account",
+ "read:pets": "read your pets"
+ }
+ }
+ },
+ "definitions": {
+ "CustomModel": {
+ "required": ["id"],
+ "properties": {
+ "id": {
+ "type": "integer",
+ "format": "int64"
+ },
+ "name": {
+ "type": "string",
+ "example": "doggie"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/test/scala/CodegenTest.scala b/modules/swagger-codegen/src/test/scala/CodegenTest.scala
index a9ccbd9f0f2..91f0c5dba2c 100644
--- a/modules/swagger-codegen/src/test/scala/CodegenTest.scala
+++ b/modules/swagger-codegen/src/test/scala/CodegenTest.scala
@@ -94,4 +94,31 @@ class CodegenTest extends FlatSpec with Matchers {
statusParam.required should equal (false)
statusParam.hasMore should be (null)
}
+
+ it should "select main response from a 2.0 spec using the lowest 2XX code" in {
+ val model = new SwaggerParser()
+ .read("src/test/resources/2_0/responseSelectionTest.json")
+
+ val codegen = new DefaultCodegen()
+
+ val path = "/tests/withTwoHundredAndDefault"
+ val p = model.getPaths().get(path).getGet()
+ val op = codegen.fromOperation(path, "get", p)
+ op.returnType should be("String")
+
+ }
+
+ it should "select main response from a 2.0 spec using the default keyword when no 2XX code" in {
+ val model = new SwaggerParser()
+ .read("src/test/resources/2_0/responseSelectionTest.json")
+
+ val codegen = new DefaultCodegen()
+
+ val path = "/tests/withoutTwoHundredButDefault"
+ val p = model.getPaths().get(path).getGet()
+ val op = codegen.fromOperation(path, "get", p)
+ op.returnType should be("String")
+
+ }
+
}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala b/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala
index 513786e4609..1e39a715eb6 100644
--- a/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala
+++ b/modules/swagger-codegen/src/test/scala/Java/JavaModelTest.scala
@@ -124,6 +124,37 @@ class JavaModelTest extends FlatSpec with Matchers {
vars.get(0).isContainer should equal (true)
}
+
+ ignore should "convert a model with a map with complex list property" in {
+ val model = new ModelImpl()
+ .description("a sample model")
+ .property("translations", new MapProperty()
+ .additionalProperties(
+ new ArrayProperty().items(new RefProperty("Pet")))
+ )
+ .required("id")
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.description should be ("a sample model")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("translations")
+ vars.get(0).getter should be ("getTranslations")
+ vars.get(0).setter should be ("setTranslations")
+ vars.get(0).datatype should be ("Map>")
+ vars.get(0).name should be ("translations")
+ vars.get(0).defaultValue should be ("new HashMap>() ")
+ vars.get(0).baseType should be ("Map")
+ vars.get(0).containerType should be ("map")
+ vars.get(0).required should equal (false)
+ vars.get(0).isContainer should equal (true)
+ }
+
it should "convert a model with complex properties" in {
val model = new ModelImpl()
.description("a sample model")
@@ -265,4 +296,30 @@ class JavaModelTest extends FlatSpec with Matchers {
vars.get(0).required should equal (true)
vars.get(0).isNotContainer should equal (true)
}
+
+ it should "convert a model with a 2nd char upper-case property names" in {
+ val model = new ModelImpl()
+ .description("a model with a 2nd char upper-case property names")
+ .property("pId", new StringProperty())
+ .required("pId")
+
+ val codegen = new JavaClientCodegen()
+ val cm = codegen.fromModel("sample", model)
+
+ cm.name should be ("sample")
+ cm.classname should be ("Sample")
+ cm.vars.size should be (1)
+
+ val vars = cm.vars
+ vars.get(0).baseName should be ("pId")
+ vars.get(0).getter should be ("getpId")
+ vars.get(0).setter should be ("setpId")
+ vars.get(0).datatype should be ("String")
+ vars.get(0).name should be ("pId")
+ vars.get(0).defaultValue should be ("null")
+ vars.get(0).baseType should be ("String")
+ vars.get(0).hasMore should equal (null)
+ vars.get(0).required should equal (true)
+ vars.get(0).isNotContainer should equal (true)
+ }
}
diff --git a/modules/swagger-generator/pom.xml b/modules/swagger-generator/pom.xml
index 653ea278617..c9a9eb8d56c 100644
--- a/modules/swagger-generator/pom.xml
+++ b/modules/swagger-generator/pom.xml
@@ -3,14 +3,14 @@
com.wordnik
swagger-codegen-project
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
../..
com.wordnik
swagger-generator
war
swagger-generator
- 1.0.0
+ 2.1.3-M1-SNAPSHOT
src/main/java
@@ -221,20 +221,12 @@
- 2.3.4
2.5
1.0.1
- 4.8.1
1.0.0
- 2.4
- 1.6.3
2.5
1.3.2
9.0.7.v20131107
2.4.1
- 1.5.1-M1
-
- 3.1.5
- 2.10.0
diff --git a/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/resource/SwaggerResource.java b/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/resource/SwaggerResource.java
index 2e3a480e115..b4592a4afc1 100644
--- a/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/resource/SwaggerResource.java
+++ b/modules/swagger-generator/src/main/java/com/wordnik/swagger/generator/resource/SwaggerResource.java
@@ -34,9 +34,10 @@ public class SwaggerResource {
@GET
@Path("/download/{fileId}")
- @Produces({"application/zip"})
+ @Produces({MediaType.APPLICATION_OCTET_STREAM})
@ApiOperation(value = "Downloads a pre-generated file",
- response = String.class)
+ response = String.class,
+ tags = {@Tag(value = "clients"), @Tag(value = "servers")})
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
Generated g = fileMap.get(fileId);
System.out.println("looking for fileId " + fileId);
@@ -57,9 +58,10 @@ public class SwaggerResource {
@POST
@Path("/clients/{language}")
- @Produces({"application/zip", "application/json"})
@ApiOperation(
- value = "Generates a client library based on the config")
+ value = "Generates a client library based on the config",
+ response = ResponseCode.class,
+ tags = {@Tag(value = "clients", description = "client operations")})
public Response generateClient(
@ApiParam(value = "The target language for the client library", allowableValues = "android,java,php,objc,docs", required = true) @PathParam("language") String language,
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts) throws Exception {
@@ -85,7 +87,8 @@ public class SwaggerResource {
@Path("/clients")
@ApiOperation(value = "Gets languages supported by the client generator",
response = String.class,
- responseContainer = "List")
+ responseContainer = "List",
+ tags = {@Tag(value = "clients", description = "client operations")})
public Response clientOptions() {
String[] languages = new String[clients.size()];
languages = clients.toArray(languages);
@@ -96,7 +99,8 @@ public class SwaggerResource {
@Path("/servers")
@ApiOperation(value = "Gets languages supported by the server generator",
response = String.class,
- responseContainer = "List")
+ responseContainer = "List",
+ tags = {@Tag(value = "servers", description = "server operations")})
public Response serverOptions() {
String[] languages = new String[servers.size()];
languages = servers.toArray(languages);
@@ -106,7 +110,8 @@ public class SwaggerResource {
@POST
@Path("/servers/{framework}")
@ApiOperation(value = "Generates a server library for the supplied server framework",
- notes = "The model representing this is not accurate, it needs to contain a consolidated JSON structure")
+ response = ResponseCode.class,
+ tags = {@Tag(value = "servers", description = "server operations")})
public Response generateServerForLanguage(
@ApiParam(value = "framework", allowableValues = "jaxrs,nodejs", required = true) @PathParam("framework") String framework,
@ApiParam(value = "parameters", required = true) GeneratorInput opts)
diff --git a/pom.xml b/pom.xml
index 549fb183305..3f3458c3f25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
swagger-codegen-project
pom
swagger-codegen-project
- 2.1.2-M1
+ 2.1.3-M1-SNAPSHOT
https://github.com/swagger-api/swagger-codegen
scm:git:git@github.com:swagger-api/swagger-codegen.git
@@ -347,10 +347,10 @@
- 1.0.1
+ 1.0.3-SNAPSHOT
2.11.1
2.3.4
- 1.5.2-M1
+ 1.5.3-M1-SNAPSHOT
2.1.4
2.3
1.2
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
index 77d30c736ad..bdf4ecec3d6 100644
--- 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
@@ -2,7 +2,8 @@ package io.swagger.api;
import io.swagger.model.*;
-import com.wordnik.swagger.annotations.*;
+import com.wordnik.swagger.annotations.ApiParam;
+
import com.sun.jersey.multipart.FormDataParam;
import io.swagger.model.Pet;
@@ -20,21 +21,20 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.*;
@Path("/pet")
-@Api(value = "/pet", description = "the pet API")
+@com.wordnik.swagger.annotations.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"),
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Update an existing pet", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 405, message = "Validation exception"),
- @ApiResponse(code = 404, message = "Pet not found"),
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "Pet not found"),
- @ApiResponse(code = 400, message = "Invalid ID supplied") })
+ @com.wordnik.swagger.annotations.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 {
@@ -47,10 +47,9 @@ public class PetApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Add a new pet to the store", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.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 {
@@ -63,10 +62,9 @@ public class PetApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma seperated strings", response = Pet.class, responseContainer = "List")
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.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 {
@@ -79,10 +77,9 @@ public class PetApi {
@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") })
+ @com.wordnik.swagger.annotations.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")
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Invalid tag value") })
public Response findPetsByTags(@ApiParam(value = "Tags to filter by") @QueryParam("tags") List tags)
throws NotFoundException {
@@ -95,12 +92,11 @@ public class PetApi {
@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"),
+ @com.wordnik.swagger.annotations.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)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "Pet not found"),
- @ApiResponse(code = 400, message = "Invalid ID supplied") })
+ @com.wordnik.swagger.annotations.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 {
@@ -113,10 +109,9 @@ public class PetApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.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,
@@ -131,10 +126,9 @@ public class PetApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Deletes a pet", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.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)
@@ -148,9 +142,8 @@ public class PetApi {
@Path("/{petId}/uploadImage")
@Consumes({ "multipart/form-data" })
@Produces({ "application/json", "application/xml" })
- // Void
- @ApiOperation(value = "uploads an image", notes = "", response = Void.class)
- @ApiResponses(value = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "uploads an image", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathParam("petId") Long petId,
@ApiParam(value = "Additional data to pass to server" )@FormParam("additionalMetadata") String additionalMetadata,
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
index cc49b9340c8..a61879188c1 100644
--- 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
@@ -2,7 +2,8 @@ package io.swagger.api;
import io.swagger.model.*;
-import com.wordnik.swagger.annotations.*;
+import com.wordnik.swagger.annotations.ApiParam;
+
import com.sun.jersey.multipart.FormDataParam;
import java.util.Map;
@@ -20,16 +21,15 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.*;
@Path("/store")
-@Api(value = "/store", description = "the store API")
+@com.wordnik.swagger.annotations.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, responseContainer = "map")
- @ApiResponses(value = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "map")
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response getInventory()
throws NotFoundException {
@@ -42,10 +42,9 @@ public class StoreApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Invalid Order") })
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ) Order body)
throws NotFoundException {
@@ -58,12 +57,11 @@ public class StoreApi {
@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"),
+ @com.wordnik.swagger.annotations.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)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "Order not found"),
- @ApiResponse(code = 400, message = "Invalid ID supplied") })
+ @com.wordnik.swagger.annotations.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 {
@@ -76,12 +74,11 @@ public class StoreApi {
@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"),
+ @com.wordnik.swagger.annotations.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)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "Order not found"),
- @ApiResponse(code = 400, message = "Invalid ID supplied") })
+ @com.wordnik.swagger.annotations.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 {
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
index c06d88e41f7..2bccc374bf9 100644
--- 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
@@ -2,7 +2,8 @@ package io.swagger.api;
import io.swagger.model.*;
-import com.wordnik.swagger.annotations.*;
+import com.wordnik.swagger.annotations.ApiParam;
+
import com.sun.jersey.multipart.FormDataParam;
import io.swagger.model.User;
@@ -20,16 +21,15 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.*;
@Path("/user")
-@Api(value = "/user", description = "the user API")
+@com.wordnik.swagger.annotations.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 = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response createUser(@ApiParam(value = "Created user object" ) User body)
throws NotFoundException {
@@ -42,9 +42,8 @@ public class UserApi {
@Path("/createWithArray")
@Produces({ "application/json", "application/xml" })
- // Void
- @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
- @ApiResponses(value = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ) List body)
throws NotFoundException {
@@ -57,9 +56,8 @@ public class UserApi {
@Path("/createWithList")
@Produces({ "application/json", "application/xml" })
- // Void
- @ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
- @ApiResponses(value = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ) List body)
throws NotFoundException {
@@ -72,10 +70,9 @@ public class UserApi {
@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") })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Logs user into the system", notes = "", response = String.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.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)
@@ -89,9 +86,8 @@ public class UserApi {
@Path("/logout")
@Produces({ "application/json", "application/xml" })
- // Void
- @ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class)
- @ApiResponses(value = { })
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Logs out current logged in user session", notes = "", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = { })
public Response logoutUser()
throws NotFoundException {
@@ -104,12 +100,11 @@ public class UserApi {
@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"),
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Get user by user name", notes = "", response = User.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "User not found"),
- @ApiResponse(code = 400, message = "Invalid username supplied") })
+ @com.wordnik.swagger.annotations.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 {
@@ -122,12 +117,11 @@ public class UserApi {
@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"),
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "User not found"),
- @ApiResponse(code = 400, message = "Invalid user supplied") })
+ @com.wordnik.swagger.annotations.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)
@@ -141,12 +135,11 @@ public class UserApi {
@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"),
+ @com.wordnik.swagger.annotations.ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class)
+ @com.wordnik.swagger.annotations.ApiResponses(value = {
+ @com.wordnik.swagger.annotations.ApiResponse(code = 404, message = "User not found"),
- @ApiResponse(code = 400, message = "Invalid username supplied") })
+ @com.wordnik.swagger.annotations.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 {