add test case for global consumes and produces

This commit is contained in:
wing328
2015-10-10 22:47:24 +08:00
parent 9311dcaccb
commit 5144c54895
2 changed files with 66 additions and 8 deletions

View File

@@ -902,15 +902,21 @@ public class DefaultCodegen {
op.summary = escapeText(operation.getSummary());
op.notes = escapeText(operation.getDescription());
op.tags = operation.getTags();
op.hasConsumes = false;
op.hasProduces = false;
List<String> consumes = new ArrayList<String>();
if (operation.getConsumes() != null && operation.getConsumes().size() > 0) {
// use consumes defined in the operation
consumes = operation.getConsumes();
if (operation.getConsumes() != null) {
if (operation.getConsumes().size() > 0) {
// use consumes defined in the operation
consumes = operation.getConsumes();
} else {
// empty list, do nothing to override global setting
}
} else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) {
// use consumes defined globally
consumes = swagger.getConsumes();
LOGGER.debug("Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId);
LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId);
}
// if "consumes" is defined (per operation or using global definition)
@@ -933,13 +939,17 @@ public class DefaultCodegen {
}
List<String> produces = new ArrayList<String>();
if (operation.getProduces() != null && operation.getProduces().size() > 0) {
// use produces defined in the operation
produces = operation.getProduces();
if (operation.getProduces() != null) {
if (operation.getProduces().size() > 0) {
// use produces defined in the operation
produces = operation.getProduces();
} else {
// empty list, do nothing to override global setting
}
} else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) {
// use produces defined globally
produces = swagger.getProduces();
LOGGER.debug("Using global produces (" + swagger.getProduces() + ") for " + op.operationId);
LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId);
}
// if "produces" is defined (per operation or using global definition)