gpt4 book ai didi

java - 为什么 Swagger Parser 的 getPaths 方法没有返回所有路径?

转载 作者:行者123 更新时间:2023-12-05 06:19:11 24 4
gpt4 key购买 nike

我有一个 Swagger 1.2 doc.json 和以下使用 Swagger Parser 从该文档中提取所有路径的 Java 代码。问题是解析器没有获取所有路径(从 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",

重复路径 are not allowed通过 Swagger 1.2 规范:

In the apis array, there MUST be only one API Object per path.

解析器会简单地忽略重复项。

关于java - 为什么 Swagger Parser 的 getPaths 方法没有返回所有路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60903944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com