forked from loafle/openapi-generator-original
swagger codegen should honor global mime types
This commit is contained in:
parent
129086eea7
commit
2edfb96c36
@ -692,11 +692,13 @@ public class DefaultCodegen {
|
|||||||
for(String key: operation.getConsumes()) {
|
for(String key: operation.getConsumes()) {
|
||||||
Map<String, String> mediaType = new HashMap<String, String>();
|
Map<String, String> mediaType = new HashMap<String, String>();
|
||||||
mediaType.put("mediaType", key);
|
mediaType.put("mediaType", key);
|
||||||
if (count < operation.getConsumes().size())
|
|
||||||
mediaType.put("hasMore", "true");
|
|
||||||
else
|
|
||||||
mediaType.put("hasMore", null);
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
if (count < operation.getConsumes().size()) {
|
||||||
|
mediaType.put("hasMore", "true");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mediaType.put("hasMore", null);
|
||||||
|
}
|
||||||
c.add(mediaType);
|
c.add(mediaType);
|
||||||
}
|
}
|
||||||
op.consumes = c;
|
op.consumes = c;
|
||||||
|
@ -165,6 +165,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
operation.putAll(config.additionalProperties());
|
operation.putAll(config.additionalProperties());
|
||||||
operation.put("classname", config.toApiName(tag));
|
operation.put("classname", config.toApiName(tag));
|
||||||
operation.put("classVarName", config.toApiVarName(tag));
|
operation.put("classVarName", config.toApiVarName(tag));
|
||||||
|
processMimeTypes(swagger.getConsumes(), operation, "consumes");
|
||||||
|
processMimeTypes(swagger.getProduces(), operation, "produces");
|
||||||
|
|
||||||
|
|
||||||
allOperations.add(new HashMap<String, Object>(operation));
|
allOperations.add(new HashMap<String, Object>(operation));
|
||||||
for (int i = 0; i < allOperations.size(); i++) {
|
for (int i = 0; i < allOperations.size(); i++) {
|
||||||
@ -291,6 +294,28 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
return files;
|
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) {
|
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
||||||
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ import javax.ws.rs.core.Response;
|
|||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
|
|
||||||
@Path("/{{baseName}}")
|
@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")
|
@com.wordnik.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
public class {{classname}} {
|
public class {{classname}} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user