fix group error;fix #138 at github

This commit is contained in:
Forget 2021-09-09 15:17:12 +08:00
parent 835e25c613
commit e2608debe4
2 changed files with 26 additions and 11 deletions

View File

@ -38,6 +38,8 @@ import com.thoughtworks.qdox.model.JavaMethod;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.power.doc.constants.DocTags.DEPRECATED;
import static com.power.doc.constants.DocTags.IGNORE;
@ -119,14 +121,8 @@ public class SpringMVCRequestMappingHandler {
for (Map.Entry<String, String> entry : constantsMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (url.contains(key)) {
url = url.replace(key, value);
url = url.replace("+", "");
}
if (shortUrl.contains(key)) {
shortUrl = shortUrl.replace(key, value);
shortUrl = shortUrl.replace("+", "");
}
url = delConstantsUrl(url,key,value);
shortUrl = delConstantsUrl(shortUrl,key, value);
}
String urlSuffix = projectBuilder.getApiConfig().getUrlSuffix();
if (StringUtil.isNotEmpty(urlSuffix)) {
@ -141,4 +137,20 @@ public class SpringMVCRequestMappingHandler {
}
return null;
}
public static String delConstantsUrl(String url,String replaceKey,String replaceValue){
if (url.endsWith(replaceKey)) {
url = url.replace(replaceKey, replaceValue);
url = url.replace("+", "");
}
else{
String regex = "("+replaceKey+")[/|\\\\].*?";
Pattern pattern =Pattern.compile(regex);
Matcher m = pattern.matcher(url);
if(m.matches()) {
url = m.replaceAll(Matcher.quoteReplacement(replaceValue));
}
}
return url;
}
}

View File

@ -125,20 +125,23 @@ public interface IDocBuildTemplate<T> {
defaultGroup.getChildrenApiDocs().addAll(apiDocList);
return finalApiDocs;
}
Map<String,String> hasInsert = new HashMap<>();
groups.forEach(group -> {
ApiDoc groupApiDoc = ApiDoc.buildGroupApiDoc(group.getName());
groupApiDoc.setOrder(order.getAndIncrement());
finalApiDocs.add(groupApiDoc);
apiDocList.forEach(doc -> {
if(hasInsert.containsKey(doc.getAlias())){
return;
}
// not match, add default group
if (!DocUtil.isMatch(group.getApis(), doc.getPackageName())) {
defaultGroup.getChildrenApiDocs().add(doc);
doc.setOrder(defaultGroup.getChildrenApiDocs().size());
hasInsert.put(doc.getAlias(),null);
return;
}
hasInsert.put(doc.getAlias(),null);
groupApiDoc.getChildrenApiDocs().add(doc);
doc.setOrder(groupApiDoc.getChildrenApiDocs().size());
doc.setGroup(group.getName());