Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with native Swagger Tag content. #670

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.thoughtworks.qdox.JavaProjectBuilder;

import java.util.*;
import java.util.stream.Collectors;

import static com.ly.doc.constants.DocGlobalConstants.*;

Expand Down Expand Up @@ -116,7 +117,11 @@ public Map<String, Object> buildPaths(ApiConfig apiConfig, List<ApiDoc> apiDocLi
}
for (Map.Entry<String, TagDoc> docEntry : DocMapping.TAG_DOC.entrySet()) {
String tag = docEntry.getKey();
tags.add(OpenApiTag.of(tag, tag));
tags.addAll(docEntry.getValue().getClazzDocs()
.stream()
//optimize tag content for copatible to swagger
.map(doc -> OpenApiTag.of(doc.getName(), doc.getDesc()))
.collect(Collectors.toSet()));
}
return pathMap;
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/ly/doc/builder/openapi/SwaggerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ public Map<String, Object> buildPathUrlsRequest(ApiConfig apiConfig, ApiMethodDo
Map<String, Object> request = new HashMap<>(20);
request.put("summary", apiMethodDoc.getDesc());
request.put("description", apiMethodDoc.getDetail());
String tag = StringUtil.isEmpty(apiDoc.getDesc()) ? DocGlobalConstants.OPENAPI_TAG : apiDoc.getDesc();
if (StringUtil.isNotEmpty(apiMethodDoc.getGroup())) {
request.put("tags", new String[]{tag});
} else {
request.put("tags", new String[]{tag});
}
request.put("tags", Arrays.asList(apiDoc.getName(),apiDoc.getDesc(), apiMethodDoc.getGroup())
.stream().filter(StringUtil::isNotEmpty).toArray(n->new String[n]));
List<Map<String, Object>> parameters = buildParameters(apiMethodDoc);
//requestBody
if (CollectionUtil.isNotEmpty(apiMethodDoc.getRequestParams())) {
Expand All @@ -160,7 +156,8 @@ public Map<String, Object> buildPathUrlsRequest(ApiConfig apiConfig, ApiMethodDo
request.put("responses", buildResponses(apiConfig, apiMethodDoc));
request.put("deprecated", apiMethodDoc.isDeprecated());
String operationId = apiMethodDoc.getUrl().replace(apiMethodDoc.getServerUrl(), "");
request.put("operationId", String.join("", OpenApiSchemaUtil.getPatternResult("[A-Za-z0-9{}]*", operationId)));
//make sure operationId is unique and can be used as a method name
request.put("operationId",apiMethodDoc.getName()+"_"+apiMethodDoc.getMethodId()+"UsingOn"+apiMethodDoc.getType());

return request;
}
Expand Down