|
74 | 74 | import io.swagger.v3.oas.annotations.enums.ParameterStyle;
|
75 | 75 | import io.swagger.v3.oas.annotations.extensions.Extension;
|
76 | 76 | import io.swagger.v3.oas.annotations.media.ExampleObject;
|
77 |
| -import io.swagger.v3.oas.annotations.tags.Tags; |
78 | 77 | import io.swagger.v3.oas.models.Components;
|
79 | 78 | import io.swagger.v3.oas.models.ExternalDocumentation;
|
80 | 79 | import io.swagger.v3.oas.models.OpenAPI;
|
|
103 | 102 | import java.util.ArrayList;
|
104 | 103 | import java.util.Collection;
|
105 | 104 | import java.util.Collections;
|
106 |
| -import java.util.Comparator; |
107 | 105 | import java.util.HashMap;
|
108 | 106 | import java.util.HashSet;
|
109 | 107 | import java.util.LinkedHashMap;
|
|
190 | 188 | import static io.micronaut.openapi.visitor.StringUtil.DOLLAR;
|
191 | 189 | import static io.micronaut.openapi.visitor.StringUtil.OPEN_BRACE;
|
192 | 190 | import static io.micronaut.openapi.visitor.StringUtil.THREE_DOTS;
|
| 191 | +import static io.micronaut.openapi.visitor.TagUtils.generationTags; |
| 192 | +import static io.micronaut.openapi.visitor.TagUtils.readTags; |
193 | 193 | import static io.micronaut.openapi.visitor.Utils.DEFAULT_MEDIA_TYPES;
|
194 | 194 | import static io.micronaut.openapi.visitor.Utils.getMediaType;
|
195 | 195 | import static io.micronaut.openapi.visitor.Utils.resolveWebhooks;
|
@@ -283,6 +283,9 @@ private void processTags(ClassElement element, VisitorContext context) {
|
283 | 283 | }
|
284 | 284 | }
|
285 | 285 | }
|
| 286 | + if (CollectionUtils.isEmpty(classTags)) { |
| 287 | + classTags = generationTags(element, context); |
| 288 | + } |
286 | 289 | }
|
287 | 290 |
|
288 | 291 | private void processExternalDocs(ClassElement element, VisitorContext context) {
|
@@ -1982,13 +1985,6 @@ private Map<String, Callback> initCallbacks(Operation swaggerOperation) {
|
1982 | 1985 | return callbacks;
|
1983 | 1986 | }
|
1984 | 1987 |
|
1985 |
| - private void addTagIfNotPresent(String tag, Operation swaggerOperation) { |
1986 |
| - List<String> tags = swaggerOperation.getTags(); |
1987 |
| - if (tags == null || !tags.contains(tag)) { |
1988 |
| - swaggerOperation.addTagsItem(tag); |
1989 |
| - } |
1990 |
| - } |
1991 |
| - |
1992 | 1988 | private void processMicronautVersionAndGroup(Operation swaggerOperation, String url,
|
1993 | 1989 | HttpMethod httpMethod,
|
1994 | 1990 | List<MediaType> consumesMediaTypes,
|
@@ -2141,70 +2137,6 @@ private void addVersionParameters(Operation swaggerOperation, List<String> names
|
2141 | 2137 | }
|
2142 | 2138 | }
|
2143 | 2139 |
|
2144 |
| - private void readTags(MethodElement element, VisitorContext context, Operation swaggerOperation, List<Tag> classTags, OpenAPI openAPI) { |
2145 |
| - element.getAnnotationValuesByType(io.swagger.v3.oas.annotations.tags.Tag.class) |
2146 |
| - .forEach(av -> av.stringValue(PROP_NAME) |
2147 |
| - .ifPresent(swaggerOperation::addTagsItem)); |
2148 |
| - |
2149 |
| - var copyTags = openAPI.getTags() != null ? new ArrayList<>(openAPI.getTags()) : null; |
2150 |
| - var operationTags = processOpenApiAnnotation(element, context, io.swagger.v3.oas.annotations.tags.Tag.class, Tag.class, copyTags); |
2151 |
| - // find not simple tags (tags with description or other information), such fields need to be described at the openAPI level. |
2152 |
| - List<Tag> complexTags = null; |
2153 |
| - if (CollectionUtils.isNotEmpty(operationTags)) { |
2154 |
| - complexTags = new ArrayList<>(); |
2155 |
| - for (Tag operationTag : operationTags) { |
2156 |
| - if (StringUtils.hasText(operationTag.getDescription()) |
2157 |
| - || CollectionUtils.isNotEmpty(operationTag.getExtensions()) |
2158 |
| - || operationTag.getExternalDocs() != null) { |
2159 |
| - complexTags.add(operationTag); |
2160 |
| - } |
2161 |
| - } |
2162 |
| - } |
2163 |
| - if (CollectionUtils.isNotEmpty(complexTags)) { |
2164 |
| - if (CollectionUtils.isEmpty(openAPI.getTags())) { |
2165 |
| - openAPI.setTags(complexTags); |
2166 |
| - } else { |
2167 |
| - for (Tag complexTag : complexTags) { |
2168 |
| - // skip all existed tags |
2169 |
| - boolean alreadyExists = false; |
2170 |
| - for (Tag apiTag : openAPI.getTags()) { |
2171 |
| - if (apiTag.getName().equals(complexTag.getName())) { |
2172 |
| - alreadyExists = true; |
2173 |
| - break; |
2174 |
| - } |
2175 |
| - } |
2176 |
| - if (!alreadyExists) { |
2177 |
| - openAPI.getTags().add(complexTag); |
2178 |
| - } |
2179 |
| - } |
2180 |
| - } |
2181 |
| - } |
2182 |
| - |
2183 |
| - // only way to get inherited tags |
2184 |
| - element.getValues(Tags.class, AnnotationValue.class) |
2185 |
| - .forEach((k, v) -> v.stringValue(PROP_NAME).ifPresent(name -> addTagIfNotPresent((String) name, swaggerOperation))); |
2186 |
| - |
2187 |
| - classTags.forEach(tag -> addTagIfNotPresent(tag.getName(), swaggerOperation)); |
2188 |
| - if (CollectionUtils.isNotEmpty(swaggerOperation.getTags())) { |
2189 |
| - swaggerOperation.getTags().sort(Comparator.naturalOrder()); |
2190 |
| - } |
2191 |
| - } |
2192 |
| - |
2193 |
| - private List<Tag> readTags(ClassElement element, VisitorContext context) { |
2194 |
| - return readTags(element.getAnnotationValuesByType(io.swagger.v3.oas.annotations.tags.Tag.class), context); |
2195 |
| - } |
2196 |
| - |
2197 |
| - final List<Tag> readTags(List<AnnotationValue<io.swagger.v3.oas.annotations.tags.Tag>> tagAnns, VisitorContext context) { |
2198 |
| - var tags = new ArrayList<Tag>(); |
2199 |
| - for (var tagAnn : tagAnns) { |
2200 |
| - var tag = toValue(tagAnn.getAnnotationName(), tagAnn.getValues(), context, Tag.class, null); |
2201 |
| - if (tag != null) { |
2202 |
| - tags.add(tag); |
2203 |
| - } |
2204 |
| - } |
2205 |
| - return tags; |
2206 |
| - } |
2207 |
| - |
2208 | 2140 | private Content buildContent(Element definingElement, ClassElement type, List<MediaType> mediaTypes, OpenAPI openAPI, VisitorContext context, @Nullable ClassElement jsonViewClass) {
|
2209 | 2141 | var content = new Content();
|
2210 | 2142 | for (var mediaType : mediaTypes) {
|
|
0 commit comments