Why does the getPaths method of Swagger Parser not return all paths?

人走茶凉 提交于 2020-05-07 07:16:46

问题


I have a Swagger 1.2 doc.json and the following Java code which uses Swagger Parser to extract all the paths from this document. The problem is that the parser does not get all the paths (from 50 it shows me only 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);
    }
}

Does anyone know what causes this problem?


回答1:


There are duplicate paths in your API definition, for example:

"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",

Duplicate paths are not allowed by the Swagger 1.2 Specification:

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

The parser simply ignores the duplicates.



来源:https://stackoverflow.com/questions/60903944/why-does-the-getpaths-method-of-swagger-parser-not-return-all-paths

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!