Enable Tag details to be used in templates (#5455)

* Enable Tag details to be used in templates

Adds the ability to reference the tag name, description, external
docs, and vendor extensions in Mustache templates during codegen

* Properly resolve tags when not defined in Swagger tags definition
This commit is contained in:
nbruno
2017-04-25 11:07:59 -04:00
committed by wing328
parent 2dd051fd4e
commit aef25ffdc3
4 changed files with 268 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package io.swagger.codegen;
import io.swagger.models.ExternalDocs;
import io.swagger.models.Tag;
import java.util.ArrayList;
import java.util.HashSet;
@@ -28,7 +29,7 @@ public class CodegenOperation {
public List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
public List<CodegenSecurity> authMethods;
public List<String> tags;
public List<Tag> tags;
public List<CodegenResponse> responses = new ArrayList<CodegenResponse>();
public Set<String> imports = new HashSet<String>();
public List<Map<String, String>> examples;

View File

@@ -1965,7 +1965,6 @@ public class DefaultCodegen {
op.summary = escapeText(operation.getSummary());
op.unescapedNotes = operation.getDescription();
op.notes = escapeText(operation.getDescription());
op.tags = operation.getTags();
op.hasConsumes = false;
op.hasProduces = false;

View File

@@ -751,11 +751,37 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
if (System.getProperty("debugOperations") != null) {
LOGGER.info("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation + "\n");
}
List<String> tags = operation.getTags();
if (tags == null) {
tags = new ArrayList<String>();
tags.add("default");
List<Tag> tags = new ArrayList<Tag>();
List<String> tagNames = operation.getTags();
List<Tag> swaggerTags = swagger.getTags();
if (tagNames != null) {
if (swaggerTags == null) {
for (String tagName : tagNames) {
tags.add(new Tag().name(tagName));
}
} else {
for (String tagName : tagNames) {
boolean foundTag = false;
for (Tag tag : swaggerTags) {
if (tag.getName().equals(tagName)) {
tags.add(tag);
foundTag = true;
break;
}
}
if (!foundTag) {
tags.add(new Tag().name(tagName));
}
}
}
}
if (tags.isEmpty()) {
tags.add(new Tag().name("default"));
}
/*
build up a set of parameter "ids" defined at the operation level
per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location"
@@ -778,12 +804,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
}
}
for (String tag : tags) {
for (Tag tag : tags) {
try {
CodegenOperation codegenOperation = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger);
codegenOperation.tags = new ArrayList<String>();
codegenOperation.tags.add(config.sanitizeTag(tag));
config.addOperationToGroup(config.sanitizeTag(tag), resourcePath, operation, codegenOperation, operations);
codegenOperation.tags = new ArrayList<Tag>(tags);
config.addOperationToGroup(config.sanitizeTag(tag.getName()), resourcePath, operation, codegenOperation, operations);
List<Map<String, List<String>>> securities = operation.getSecurity();
if (securities == null && swagger.getSecurity() != null) {