为什么Swagger Parser的getPaths方法不返回所有路径?
我有一个Swagger 1.2
doc.json和下面的Java代码,这些代码使用Swagger分析器从该文档中提取所有路径。问题在于解析器无法获取所有路径(从50开始,它仅显示27条路径)。
public class Temps { public static void main (String[]args ) {
int totale=0;
Swagger swagger = new SwaggerParser().read("C:\\Users\\eya\\Desktop\\nodes.json");
Map<String, Path> paths = swagger.getPaths();
for (Map.Entry<String, Path> p : paths.entrySet()) {
Path path = p.getValue();
totale ++;
Map<HttpMethod, Operation> operations = path.getOperationMap();
for (java.util.Map.Entry<HttpMethod, Operation> o : operations.entrySet()) {
System.out.println("===");
System.out.println("PATH:" + p.getKey());
System.out.println("Http method:" + o.getKey());
System.out.println("Summary:" + o.getValue().getSummary());
System.out.println("Parameters number: " + o.getValue().getParameters().size());
for (Parameter parameter : o.getValue().getParameters()) {
System.out.println(" - " + parameter.getName());
}
System.out.println("Responses:");
for (Map.Entry<String, Response> r : o.getValue().getResponses().entrySet()) {
System.out.println(" - " + r.getKey() + ": " + r.getValue().getDescription());
}
}
}
System.out.println(totale);
}
}
有人知道导致此问题的原因吗?
回答:
您的API定义中有重复的路径,例如:
"path": "api/v2/nodes/{id}","description": "Get a node",
...
"path": "api/v2/nodes/{id}",
"description": "Get a virtual folder",
"path": "api/v2/nodes/actions",
"description": "Get actions for the selected node IDs",
...
"path": "api/v2/nodes/actions",
"description": "Get actions for the selected node IDs",
Swagger 1.2规范不允许重复路径:
在
apis
数组中,每个只能有一个API对象path
。
解析器只是忽略重复项。
以上是 为什么Swagger Parser的getPaths方法不返回所有路径? 的全部内容, 来源链接: utcz.com/qa/415832.html