use of io.swagger.v3.oas.annotations.tags.Tag in project cxf by apache.
the class OpenApiCustomizer method customize.
public void customize(final OpenAPI oas) {
if (replaceTags || javadocProvider != null) {
Map<String, ClassResourceInfo> operations = new HashMap<>();
Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>();
cris.forEach(cri -> {
cri.getMethodDispatcher().getOperationResourceInfos().forEach(ori -> {
String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue());
operations.put(normalizedPath, cri);
methods.put(Pair.of(ori.getHttpMethod(), normalizedPath), ori);
});
});
List<Tag> tags = new ArrayList<>();
oas.getPaths().forEach((pathKey, pathItem) -> {
Tag tag = null;
if (replaceTags && operations.containsKey(pathKey)) {
ClassResourceInfo cri = operations.get(pathKey);
tag = new Tag();
tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_"));
if (javadocProvider != null) {
tag.setDescription(javadocProvider.getClassDoc(cri));
}
if (!tags.contains(tag)) {
tags.add(tag);
}
}
for (Map.Entry<HttpMethod, Operation> subentry : pathItem.readOperationsMap().entrySet()) {
if (replaceTags && tag != null) {
subentry.getValue().setTags(Collections.singletonList(tag.getName()));
}
Pair<String, String> key = Pair.of(subentry.getKey().name(), pathKey);
if (methods.containsKey(key) && javadocProvider != null) {
OperationResourceInfo ori = methods.get(key);
if (StringUtils.isBlank(subentry.getValue().getSummary())) {
subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
}
if (subentry.getValue().getParameters() == null) {
List<Parameter> parameters = new ArrayList<>();
addParameters(parameters);
subentry.getValue().setParameters(parameters);
} else {
for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
if (StringUtils.isBlank(subentry.getValue().getParameters().get(i).getDescription())) {
subentry.getValue().getParameters().get(i).setDescription(javadocProvider.getMethodParameterDoc(ori, i));
}
}
addParameters(subentry.getValue().getParameters());
}
if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) {
ApiResponse response = subentry.getValue().getResponses().entrySet().iterator().next().getValue();
if (StringUtils.isBlank(response.getDescription())) {
response.setDescription(javadocProvider.getMethodResponseDoc(ori));
}
}
}
}
});
if (replaceTags && oas.getTags() != null) {
oas.setTags(tags);
}
}
}
Aggregations