forked from loafle/openapi-generator-original
merged
This commit is contained in:
commit
0c1bdc0fd6
@ -6,11 +6,9 @@
|
|||||||
<relativePath>../..</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.wordnik</groupId>
|
|
||||||
<artifactId>swagger-codegen</artifactId>
|
<artifactId>swagger-codegen</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>swagger-codegen (core library)</name>
|
<name>swagger-codegen (core library)</name>
|
||||||
<version>2.1.1-M2-SNAPSHOT</version>
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.wordnik.swagger.codegen;
|
package com.wordnik.swagger.codegen;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class CodegenResponse {
|
public class CodegenResponse {
|
||||||
public String code, message;
|
public String code, message;
|
||||||
public Boolean hasMore;
|
public Boolean hasMore;
|
||||||
public List<Map<String, String>> examples;
|
public List<Map<String, Object>> examples;
|
||||||
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
|
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
|
||||||
public String dataType, baseType, containerType;
|
public String dataType, baseType, containerType;
|
||||||
public Boolean isDefault;
|
public Boolean isDefault;
|
||||||
@ -16,4 +18,4 @@ public class CodegenResponse {
|
|||||||
public Object schema;
|
public Object schema;
|
||||||
public String jsonSchema;
|
public String jsonSchema;
|
||||||
public boolean isWildcard() { return "0".equals(code) || "default".equals(code); }
|
public boolean isWildcard() { return "0".equals(code) || "default".equals(code); }
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,58 @@
|
|||||||
package com.wordnik.swagger.codegen;
|
package com.wordnik.swagger.codegen;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.wordnik.swagger.codegen.examples.ExampleGenerator;
|
import com.wordnik.swagger.codegen.examples.ExampleGenerator;
|
||||||
import com.wordnik.swagger.models.*;
|
import com.wordnik.swagger.models.ArrayModel;
|
||||||
|
import com.wordnik.swagger.models.Model;
|
||||||
|
import com.wordnik.swagger.models.ModelImpl;
|
||||||
|
import com.wordnik.swagger.models.Operation;
|
||||||
|
import com.wordnik.swagger.models.RefModel;
|
||||||
|
import com.wordnik.swagger.models.Response;
|
||||||
|
import com.wordnik.swagger.models.Swagger;
|
||||||
import com.wordnik.swagger.models.auth.ApiKeyAuthDefinition;
|
import com.wordnik.swagger.models.auth.ApiKeyAuthDefinition;
|
||||||
import com.wordnik.swagger.models.auth.BasicAuthDefinition;
|
import com.wordnik.swagger.models.auth.BasicAuthDefinition;
|
||||||
import com.wordnik.swagger.models.auth.In;
|
import com.wordnik.swagger.models.auth.In;
|
||||||
import com.wordnik.swagger.models.auth.SecuritySchemeDefinition;
|
import com.wordnik.swagger.models.auth.SecuritySchemeDefinition;
|
||||||
import com.wordnik.swagger.models.parameters.*;
|
import com.wordnik.swagger.models.parameters.BodyParameter;
|
||||||
import com.wordnik.swagger.models.properties.*;
|
import com.wordnik.swagger.models.parameters.CookieParameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.FormParameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.HeaderParameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.Parameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.PathParameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.QueryParameter;
|
||||||
|
import com.wordnik.swagger.models.parameters.SerializableParameter;
|
||||||
|
import com.wordnik.swagger.models.properties.AbstractNumericProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.ArrayProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.BooleanProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DateProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DateTimeProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DecimalProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DoubleProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.FloatProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.IntegerProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.LongProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.MapProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.Property;
|
||||||
|
import com.wordnik.swagger.models.properties.PropertyBuilder;
|
||||||
|
import com.wordnik.swagger.models.properties.RefProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.StringProperty;
|
||||||
import com.wordnik.swagger.util.Json;
|
import com.wordnik.swagger.util.Json;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class DefaultCodegen {
|
public class DefaultCodegen {
|
||||||
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||||
|
|
||||||
@ -1015,9 +1047,9 @@ public class DefaultCodegen {
|
|||||||
if(schemes == null)
|
if(schemes == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<CodegenSecurity> secs = new ArrayList<CodegenSecurity>();
|
List<CodegenSecurity> secs = new ArrayList<CodegenSecurity>(schemes.size());
|
||||||
for(Iterator entries = schemes.entrySet().iterator(); entries.hasNext(); ) {
|
for (Iterator<Map.Entry<String, SecuritySchemeDefinition>> it = schemes.entrySet().iterator(); it.hasNext();) {
|
||||||
Map.Entry<String, SecuritySchemeDefinition> entry = (Map.Entry<String, SecuritySchemeDefinition>) entries.next();
|
final Map.Entry<String, SecuritySchemeDefinition> entry = it.next();
|
||||||
final SecuritySchemeDefinition schemeDefinition = entry.getValue();
|
final SecuritySchemeDefinition schemeDefinition = entry.getValue();
|
||||||
|
|
||||||
CodegenSecurity sec = CodegenModelFactory.newInstance(CodegenModelType.SECURITY);
|
CodegenSecurity sec = CodegenModelFactory.newInstance(CodegenModelType.SECURITY);
|
||||||
@ -1037,23 +1069,21 @@ public class DefaultCodegen {
|
|||||||
sec.isOAuth = !sec.isBasic;
|
sec.isOAuth = !sec.isBasic;
|
||||||
}
|
}
|
||||||
|
|
||||||
sec.hasMore = entries.hasNext();
|
sec.hasMore = it.hasNext();
|
||||||
secs.add(sec);
|
secs.add(sec);
|
||||||
}
|
}
|
||||||
return secs;
|
return secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Map<String, String>> toExamples(Map<String, Object> examples) {
|
protected List<Map<String, Object>> toExamples(Map<String, Object> examples) {
|
||||||
if(examples == null)
|
if(examples == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
List<Map<String, String>> output = new ArrayList<Map<String, String>>();
|
final List<Map<String, Object>> output = new ArrayList<Map<String, Object>>(examples.size());
|
||||||
for(String key: examples.keySet()) {
|
for(Map.Entry<String, Object> entry : examples.entrySet()) {
|
||||||
String value = String.valueOf(examples.get(key));
|
final Map<String, Object> kv = new HashMap<String, Object>();
|
||||||
|
kv.put("contentType", entry.getKey());
|
||||||
Map<String, String> kv = new HashMap<String, String>();
|
kv.put("example", entry.getValue());
|
||||||
kv.put("contentType", key);
|
|
||||||
kv.put("example", value);
|
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
package com.wordnik.swagger.codegen.examples;
|
package com.wordnik.swagger.codegen.examples;
|
||||||
|
|
||||||
import com.wordnik.swagger.models.*;
|
|
||||||
import com.wordnik.swagger.models.properties.*;
|
|
||||||
import com.wordnik.swagger.util.Json;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Marshaller;
|
|
||||||
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.wordnik.swagger.models.Model;
|
||||||
|
import com.wordnik.swagger.models.ModelImpl;
|
||||||
|
import com.wordnik.swagger.models.properties.ArrayProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.BooleanProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DateProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DateTimeProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DecimalProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.DoubleProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.FileProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.FloatProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.IntegerProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.LongProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.MapProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.ObjectProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.Property;
|
||||||
|
import com.wordnik.swagger.models.properties.RefProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.StringProperty;
|
||||||
|
import com.wordnik.swagger.models.properties.UUIDProperty;
|
||||||
|
import com.wordnik.swagger.util.Json;
|
||||||
|
|
||||||
public class ExampleGenerator {
|
public class ExampleGenerator {
|
||||||
protected Map<String, Model> examples;
|
protected Map<String, Model> examples;
|
||||||
@ -37,7 +51,6 @@ public class ExampleGenerator {
|
|||||||
String example = Json.pretty(resolvePropertyToExample(mediaType, property, processedModels));
|
String example = Json.pretty(resolvePropertyToExample(mediaType, property, processedModels));
|
||||||
|
|
||||||
if(example != null) {
|
if(example != null) {
|
||||||
example = example.replaceAll("\n", "\\\\n");
|
|
||||||
kv.put("example", example);
|
kv.put("example", example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
@ -45,7 +58,6 @@ public class ExampleGenerator {
|
|||||||
else if(property != null && mediaType.startsWith("application/xml")) {
|
else if(property != null && mediaType.startsWith("application/xml")) {
|
||||||
String example = new XmlExampleGenerator(this.examples).toXml(property);
|
String example = new XmlExampleGenerator(this.examples).toXml(property);
|
||||||
if(example != null) {
|
if(example != null) {
|
||||||
example = example.replaceAll("\n", "\\\\n");
|
|
||||||
kv.put("example", example);
|
kv.put("example", example);
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
@ -53,12 +65,10 @@ public class ExampleGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(String key: examples.keySet()) {
|
for(Map.Entry<String, Object> entry: examples.entrySet()) {
|
||||||
String value = String.valueOf(examples.get(key));
|
final Map<String, String> kv = new HashMap<String, String>();
|
||||||
|
kv.put("contentType", entry.getKey());
|
||||||
Map<String, String> kv = new HashMap<String, String>();
|
kv.put("example", Json.pretty(entry.getValue()));
|
||||||
kv.put("contentType", key);
|
|
||||||
kv.put("example", value);
|
|
||||||
output.add(kv);
|
output.add(kv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package com.wordnik.swagger.codegen.languages;
|
package com.wordnik.swagger.codegen.languages;
|
||||||
|
|
||||||
import com.wordnik.swagger.codegen.*;
|
|
||||||
import com.wordnik.swagger.util.Json;
|
|
||||||
import com.wordnik.swagger.models.properties.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.CodegenConfig;
|
||||||
|
import com.wordnik.swagger.codegen.CodegenOperation;
|
||||||
|
import com.wordnik.swagger.codegen.CodegenParameter;
|
||||||
|
import com.wordnik.swagger.codegen.CodegenResponse;
|
||||||
|
import com.wordnik.swagger.codegen.CodegenType;
|
||||||
|
import com.wordnik.swagger.codegen.DefaultCodegen;
|
||||||
|
import com.wordnik.swagger.codegen.SupportingFile;
|
||||||
|
|
||||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String apiVersion = "1.0.0";
|
protected String apiVersion = "1.0.0";
|
||||||
@ -156,8 +164,10 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||||
Map<String, Object> objectMap = (Map<String, Object>)objs.get("operations");
|
@SuppressWarnings("unchecked")
|
||||||
List<CodegenOperation> operations = (List<CodegenOperation>)objectMap.get("operation");
|
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||||
for(CodegenOperation operation : operations) {
|
for(CodegenOperation operation : operations) {
|
||||||
operation.httpMethod = operation.httpMethod.toLowerCase();
|
operation.httpMethod = operation.httpMethod.toLowerCase();
|
||||||
List<CodegenParameter> params = operation.allParams;
|
List<CodegenParameter> params = operation.allParams;
|
||||||
@ -170,20 +180,14 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
resp.code = "default";
|
resp.code = "default";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(operation.examples != null && operation.examples.size() > 0) {
|
if(operation.examples != null && !operation.examples.isEmpty()) {
|
||||||
List<Map<String, String>> examples = operation.examples;
|
// Leave application/json* items only
|
||||||
for(int i = examples.size() - 1; i >= 0; i--) {
|
for (Iterator<Map<String, String>> it = operation.examples.iterator(); it.hasNext();) {
|
||||||
Map<String, String> example = examples.get(i);
|
final Map<String, String> example = it.next();
|
||||||
String contentType = example.get("contentType");
|
final String contentType = example.get("contentType");
|
||||||
if(contentType != null && contentType.indexOf("application/json") == 0) {
|
if (contentType == null || !contentType.startsWith("application/json")) {
|
||||||
String jsonExample = example.get("example");
|
it.remove();
|
||||||
if(jsonExample != null) {
|
|
||||||
jsonExample = jsonExample.replaceAll("\\\\n", "\n");
|
|
||||||
example.put("example", jsonExample);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
examples.remove(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
{{#examples}}
|
{{#examples}}
|
||||||
<h3 class="field-label">Example data</h3>
|
<h3 class="field-label">Example data</h3>
|
||||||
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
|
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
|
||||||
<pre class="example"><code>{{{example}}}</code></pre>
|
<pre class="example"><code>{{example}}</code></pre>
|
||||||
{{/examples}}
|
{{/examples}}
|
||||||
</div> <!-- method -->
|
</div> <!-- method -->
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -720,6 +720,18 @@
|
|||||||
"description": "successful operation",
|
"description": "successful operation",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/User"
|
"$ref": "#/definitions/User"
|
||||||
|
},
|
||||||
|
"examples": {
|
||||||
|
"application/json": {
|
||||||
|
"id": 1,
|
||||||
|
"username": "johnp",
|
||||||
|
"firstName": "John",
|
||||||
|
"lastName": "Public",
|
||||||
|
"email": "johnp@swagger.io",
|
||||||
|
"password": "-secret-",
|
||||||
|
"phone": "0123456789",
|
||||||
|
"userStatus": 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
<version>2.1.1-M2-SNAPSHOT</version>
|
<version>2.1.1-M2-SNAPSHOT</version>
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.wordnik</groupId>
|
|
||||||
<artifactId>swagger-generator</artifactId>
|
<artifactId>swagger-generator</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>swagger-generator</name>
|
<name>swagger-generator</name>
|
||||||
<version>2.1.1-M2-SNAPSHOT</version>
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user