swagger codegen should honor global mime types

This commit is contained in:
russellb337 2015-05-07 12:02:25 -07:00
parent 129086eea7
commit 2edfb96c36
3 changed files with 33 additions and 4 deletions

View File

@ -692,11 +692,13 @@ public class DefaultCodegen {
for(String key: operation.getConsumes()) {
Map<String, String> mediaType = new HashMap<String, String>();
mediaType.put("mediaType", key);
if (count < operation.getConsumes().size())
mediaType.put("hasMore", "true");
else
mediaType.put("hasMore", null);
count += 1;
if (count < operation.getConsumes().size()) {
mediaType.put("hasMore", "true");
}
else {
mediaType.put("hasMore", null);
}
c.add(mediaType);
}
op.consumes = c;

View File

@ -165,6 +165,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
operation.putAll(config.additionalProperties());
operation.put("classname", config.toApiName(tag));
operation.put("classVarName", config.toApiVarName(tag));
processMimeTypes(swagger.getConsumes(), operation, "consumes");
processMimeTypes(swagger.getProduces(), operation, "produces");
allOperations.add(new HashMap<String, Object>(operation));
for (int i = 0; i < allOperations.size(); i++) {
@ -291,6 +294,28 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
return files;
}
private void processMimeTypes(List<String> mimeTypeList, Map<String, Object> operation, String source) {
if(mimeTypeList != null && mimeTypeList.size() > 0) {
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
int count = 0;
for(String key: mimeTypeList) {
Map<String, String> mediaType = new HashMap<String, String>();
mediaType.put("mediaType", key);
count += 1;
if (count < mimeTypeList.size()) {
mediaType.put("hasMore", "true");
}
else {
mediaType.put("hasMore", null);
}
c.add(mediaType);
}
operation.put(source, c);
String flagFieldName = "has" + source.substring(0, 1).toUpperCase() + source.substring(1);
operation.put(flagFieldName, true);
}
}
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();

View File

@ -21,6 +21,8 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.*;
@Path("/{{baseName}}")
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
@com.wordnik.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API")
{{#operations}}
public class {{classname}} {