Swagger Parser does not get all the paths from swagger.json

牧云@^-^@ 提交于 2020-04-18 05:42:33

问题


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. and I have a swagger.json file and I want to extract all the paths and their methods from this file. I tried to use Json Parser but I have no idea how to use it. How can I do so? Here is my code :

   import java.util.Map;
import java.util.Map.Entry;

import org.json.simple.parser.JSONParser;

import io.swagger.models.HttpMethod;
import io.swagger.models.Operation;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import java.io.FileReader;
import java.util.Iterator;

@SuppressWarnings("unused")
public class JSONReadExample {
    @SuppressWarnings({ "unchecked", "deprecation" })
    public static void main(String[] args) {
        JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(new FileReader("C:\\Users\\eya\\Desktop\\nodes.json"));
            JSONObject jsonObject = (JSONObject) obj;
            JSONArray apis = (JSONArray) jsonObject.get("apis");
            Iterator<JSONObject> iterator = apis.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());


            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

and it shows me only the whole path ! I don't know to extract the opération and the description ...

来源:https://stackoverflow.com/questions/60916753/swagger-parser-does-not-get-all-the-paths-from-swagger-json

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