|
@@ -100,6 +100,8 @@ public class SwaggerExtentionSupport implements ApplicationListener<ContextRefre
|
|
|
Multimap<String, ApiListing> apiListings = documentation.getApiListings();
|
|
Multimap<String, ApiListing> apiListings = documentation.getApiListings();
|
|
|
//Swagger swagger = mapper.mapDocumentation(documentation);
|
|
//Swagger swagger = mapper.mapDocumentation(documentation);
|
|
|
String[] beanDefinitionNames = context.getBeanDefinitionNames();
|
|
String[] beanDefinitionNames = context.getBeanDefinitionNames();
|
|
|
|
|
+
|
|
|
|
|
+ //String[] beanDefinitionNames = new String[]{"test.do", "param.do", "rule.do"};
|
|
|
for (String name : beanDefinitionNames) {
|
|
for (String name : beanDefinitionNames) {
|
|
|
if(name.endsWith(".do")) {
|
|
if(name.endsWith(".do")) {
|
|
|
Class<?> aClass = context.getBean(name).getClass();
|
|
Class<?> aClass = context.getBean(name).getClass();
|
|
@@ -134,10 +136,11 @@ public class SwaggerExtentionSupport implements ApplicationListener<ContextRefre
|
|
|
String methodName) {
|
|
String methodName) {
|
|
|
// 获取去除了 .do 的 名称
|
|
// 获取去除了 .do 的 名称
|
|
|
String optGroup = getName(beanName);
|
|
String optGroup = getName(beanName);
|
|
|
- String optId = optGroup + "_" + methodName;
|
|
|
|
|
|
|
+ String apiId = optGroup + "_" + methodName;
|
|
|
|
|
+ String optId = methodName;
|
|
|
|
|
|
|
|
// 生成唯一ID
|
|
// 生成唯一ID
|
|
|
- Collection<ApiListing> apis = apiListings.get(optId);
|
|
|
|
|
|
|
+ Collection<ApiListing> apis = apiListings.get(apiId);
|
|
|
if(apis == null) {
|
|
if(apis == null) {
|
|
|
// 后面只是用 apis 的 size 获取长度
|
|
// 后面只是用 apis 的 size 获取长度
|
|
|
apis = new HashSet<>();
|
|
apis = new HashSet<>();
|
|
@@ -147,12 +150,18 @@ public class SwaggerExtentionSupport implements ApplicationListener<ContextRefre
|
|
|
|
|
|
|
|
ArrayList<Operation> operations = new ArrayList<>();
|
|
ArrayList<Operation> operations = new ArrayList<>();
|
|
|
|
|
|
|
|
- ResponseMessageBuilder v1 = new ResponseMessageBuilder();
|
|
|
|
|
- v1.code(200).message("OK");
|
|
|
|
|
|
|
+ ResponseMessage v200 = new ResponseMessageBuilder().code(200).message("OK").build();
|
|
|
|
|
+ ResponseMessage v401 = new ResponseMessageBuilder().code(401).message("Unauthorized").build();
|
|
|
|
|
+ ResponseMessage v403 = new ResponseMessageBuilder().code(403).message("Forbidden").build();
|
|
|
|
|
+ ResponseMessage v404 = new ResponseMessageBuilder().code(404).message("Not Found").build();
|
|
|
|
|
|
|
|
// tag
|
|
// tag
|
|
|
HashSet<Tag> tags = new HashSet<>();
|
|
HashSet<Tag> tags = new HashSet<>();
|
|
|
- tags.add(new Tag(optGroup, beanName+"." + methodName));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // description 是生成 API JS 的文件名
|
|
|
|
|
+ // optGroup 是生成的函数名
|
|
|
|
|
+ Tag tag = new Tag(optGroup, optGroup + "Controller");
|
|
|
|
|
+ tags.add(tag);
|
|
|
|
|
|
|
|
// 注意 position,必须是不重复的值
|
|
// 注意 position,必须是不重复的值
|
|
|
Operation operaGet = new Operation(
|
|
Operation operaGet = new Operation(
|
|
@@ -162,39 +171,42 @@ public class SwaggerExtentionSupport implements ApplicationListener<ContextRefre
|
|
|
new ModelRef("ResponseCode"),
|
|
new ModelRef("ResponseCode"),
|
|
|
optId+"UsingGET",
|
|
optId+"UsingGET",
|
|
|
0,
|
|
0,
|
|
|
- Sets.newHashSet(optGroup),
|
|
|
|
|
|
|
+ Sets.newHashSet(tag.getName()),
|
|
|
Sets.newHashSet(MediaType.ANY_TYPE.toString()),
|
|
Sets.newHashSet(MediaType.ANY_TYPE.toString()),
|
|
|
Sets.newHashSet(MediaType.create("application", "json").toString()),
|
|
Sets.newHashSet(MediaType.create("application", "json").toString()),
|
|
|
new HashSet<>(),
|
|
new HashSet<>(),
|
|
|
new ArrayList<>(),
|
|
new ArrayList<>(),
|
|
|
new ArrayList<>(),
|
|
new ArrayList<>(),
|
|
|
- Sets.newHashSet(v1.build()),
|
|
|
|
|
|
|
+ Sets.newHashSet(v200, v401, v403, v404),
|
|
|
"",
|
|
"",
|
|
|
false,
|
|
false,
|
|
|
new ArrayList<>()
|
|
new ArrayList<>()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ // Operation 只需要 tag name,他决定了该 api 在 Swagger 上挂载的tag
|
|
|
|
|
+ /*
|
|
|
Operation operaPost = new Operation(
|
|
Operation operaPost = new Operation(
|
|
|
HttpMethod.POST,
|
|
HttpMethod.POST,
|
|
|
"do exec " + optGroup + "." + methodName,
|
|
"do exec " + optGroup + "." + methodName,
|
|
|
"",
|
|
"",
|
|
|
new ModelRef("ResponseCode"),
|
|
new ModelRef("ResponseCode"),
|
|
|
optId+"UsingPOST",
|
|
optId+"UsingPOST",
|
|
|
- 1,
|
|
|
|
|
- Sets.newHashSet(optGroup),
|
|
|
|
|
|
|
+ 0,
|
|
|
|
|
+ Sets.newHashSet(tag.getName()),
|
|
|
Sets.newHashSet(MediaType.ANY_TYPE.toString()),
|
|
Sets.newHashSet(MediaType.ANY_TYPE.toString()),
|
|
|
Sets.newHashSet(MediaType.create("application", "json").toString()),
|
|
Sets.newHashSet(MediaType.create("application", "json").toString()),
|
|
|
new HashSet<>(),
|
|
new HashSet<>(),
|
|
|
new ArrayList<>(),
|
|
new ArrayList<>(),
|
|
|
new ArrayList<>(),
|
|
new ArrayList<>(),
|
|
|
- Sets.newHashSet(v1.build()),
|
|
|
|
|
|
|
+ Sets.newHashSet(v200, v401, v403, v404),
|
|
|
"",
|
|
"",
|
|
|
false,
|
|
false,
|
|
|
new ArrayList<>()
|
|
new ArrayList<>()
|
|
|
);
|
|
);
|
|
|
|
|
+ */
|
|
|
|
|
|
|
|
operations.add(operaGet);
|
|
operations.add(operaGet);
|
|
|
- operations.add(operaPost);
|
|
|
|
|
|
|
+ //operations.add(operaPost);
|
|
|
|
|
|
|
|
String url = "/" + beanName + "?invoke=" + methodName;
|
|
String url = "/" + beanName + "?invoke=" + methodName;
|
|
|
apis1.add(new ApiDescription(groupName,
|
|
apis1.add(new ApiDescription(groupName,
|
|
@@ -212,7 +224,9 @@ public class SwaggerExtentionSupport implements ApplicationListener<ContextRefre
|
|
|
new HashMap<>(), beanName+"." + methodName, apis.size(), tags);
|
|
new HashMap<>(), beanName+"." + methodName, apis.size(), tags);
|
|
|
|
|
|
|
|
// 放到api列表中
|
|
// 放到api列表中
|
|
|
- apiListings.put(optId, apiListing);
|
|
|
|
|
|
|
+ apiListings.put(apiId, apiListing);
|
|
|
|
|
+
|
|
|
|
|
+ // 返回 tag,tag 会显示到 Swagger Content
|
|
|
return tags;
|
|
return tags;
|
|
|
}
|
|
}
|
|
|
|
|
|