Make response headers available to the code generator

This commit is contained in:
Martin Ehrnhoefer 2014-10-08 08:57:01 +02:00
parent f2c64a0fbb
commit 3f0b71b3e0
2 changed files with 13 additions and 2 deletions

View File

@ -19,7 +19,7 @@ public class CodegenOperation {
public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>(); public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
public List<String> tags; public List<String> tags;
public List<CodegenResponse> responses = new ArrayList<CodegenResponse>(); public List<CodegenResponse> responses = new ArrayList<CodegenResponse>();
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
public Set<String> imports = new HashSet<String>(); public Set<String> imports = new HashSet<String>();
public List<Map<String, String>> examples; public List<Map<String, String>> examples;
public ExternalDocs externalDocs; public ExternalDocs externalDocs;

View File

@ -606,7 +606,8 @@ public class DefaultCodegen {
} }
} }
if(methodResponse != null && methodResponse.getSchema() != null) { if(methodResponse != null) {
if (methodResponse.getSchema() != null) {
CodegenProperty cm = fromProperty("response", methodResponse.getSchema()); CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
Property responseProperty = methodResponse.getSchema(); Property responseProperty = methodResponse.getSchema();
@ -633,6 +634,8 @@ public class DefaultCodegen {
if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null) if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null)
op.returnTypeIsPrimitive = true; op.returnTypeIsPrimitive = true;
} }
addHeaders(methodResponse, op.responseHeaders);
}
if(op.returnBaseType == null) { if(op.returnBaseType == null) {
op.returnTypeIsPrimitive = true; op.returnTypeIsPrimitive = true;
@ -808,6 +811,14 @@ public class DefaultCodegen {
return output; return output;
} }
private void addHeaders(Response response, List<CodegenProperty> target) {
if (response.getHeaders() != null) {
for (Map.Entry<String, Property> headers : response.getHeaders().entrySet()) {
target.add(fromProperty(headers.getKey(), headers.getValue()));
}
}
}
private List<CodegenParameter> addHasMore(List<CodegenParameter> objs) { private List<CodegenParameter> addHasMore(List<CodegenParameter> objs) {
if(objs != null) { if(objs != null) {
for(int i = 0; i < objs.size(); i++) { for(int i = 0; i < objs.size(); i++) {