mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-06 15:40:54 +00:00
updated examples
This commit is contained in:
parent
e2ae99acac
commit
36aad8bc0a
@ -21,6 +21,7 @@ public class CodegenOperation {
|
||||
public List<CodegenResponse> responses = new ArrayList<CodegenResponse>();
|
||||
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
public List<Map<String, String>> examples;
|
||||
|
||||
// legacy support
|
||||
public String nickname;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenResponse {
|
||||
public String code, message;
|
||||
public Boolean hasMore;
|
||||
public List<Map<String, String>> examples;
|
||||
Object schema;
|
||||
}
|
@ -115,6 +115,9 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public String toVarName(String name) {
|
||||
if(reservedWords.contains(name))
|
||||
return escapeReservedWord(name);
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -314,6 +317,9 @@ public class DefaultCodegen {
|
||||
|
||||
public CodegenModel fromModel(String name, Model model) {
|
||||
CodegenModel m = new CodegenModel();
|
||||
if(reservedWords.contains(name))
|
||||
m.name = escapeReservedWord(name);
|
||||
else
|
||||
m.name = name;
|
||||
m.description = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
@ -498,12 +504,13 @@ public class DefaultCodegen {
|
||||
|
||||
String operationId = operation.getOperationId();
|
||||
if(operationId == null) {
|
||||
path = path.replaceAll("\\{", "");
|
||||
path = path.replaceAll("\\}", "");
|
||||
String[] parts = (path + "/" + httpMethod).split("/");
|
||||
String tmpPath = path;
|
||||
tmpPath = tmpPath.replaceAll("\\{", "");
|
||||
tmpPath = tmpPath.replaceAll("\\}", "");
|
||||
String[] parts = (tmpPath + "/" + httpMethod).split("/");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if("/".equals(path)) {
|
||||
// must be root path
|
||||
if("/".equals(tmpPath)) {
|
||||
// must be root tmpPath
|
||||
builder.append("root");
|
||||
}
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
@ -575,6 +582,7 @@ public class DefaultCodegen {
|
||||
r.code = responseCode;
|
||||
r.message = response.getDescription();
|
||||
r.schema = response.getSchema();
|
||||
r.examples = toExamples(response.getExamples());
|
||||
op.responses.add(r);
|
||||
}
|
||||
for(int i = 0; i < op.responses.size() - 1; i++) {
|
||||
@ -600,7 +608,7 @@ public class DefaultCodegen {
|
||||
else
|
||||
op.returnBaseType = cm.baseType;
|
||||
}
|
||||
|
||||
op.examples = toExamples(methodResponse.getExamples());
|
||||
op.defaultResponse = toDefaultValue(responseProperty);
|
||||
op.returnType = cm.datatype;
|
||||
if(cm.isContainer != null) {
|
||||
@ -750,6 +758,22 @@ public class DefaultCodegen {
|
||||
return op;
|
||||
}
|
||||
|
||||
protected List<Map<String, String>> toExamples(Map<String, String> examples) {
|
||||
if(examples == null)
|
||||
return null;
|
||||
|
||||
List<Map<String, String>> output = new ArrayList<Map<String, String>>();
|
||||
for(String key: examples.keySet()) {
|
||||
String value = examples.get(key);
|
||||
|
||||
Map<String, String> kv = new HashMap<String, String>();
|
||||
kv.put("contentType", key);
|
||||
kv.put("example", value);
|
||||
output.add(kv);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private List<CodegenParameter> addHasMore(List<CodegenParameter> objs) {
|
||||
if(objs != null) {
|
||||
for(int i = 0; i < objs.size(); i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user