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

maryem neyli :

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?

Helen :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=355552&siteId=1