如何从swagger中的Body Parameter获取有效载荷选项
我想在swagger中检索post请求的有效负载,我可以在其中获取Body参数对象
我的代码是
JSONArray array = new JSONArray();
try {
SwaggerParser node = new SwaggerParser();
v2.io.swagger.models.Swagger swagger = node.read(url);
String path = swagger.getHost()+ swagger.getBasePath();
Map<String, Path> map = swagger.getPaths();
Iterator<Entry<String, Path>> iterator = map.entrySet().iterator();
while(iterator.hasNext())
{
Entry<String, Path> entry = iterator.next();
JSONObject jsonObject = new JSONObject();
String temp = entry.getKey();
jsonObject.put("path", path+temp);
jsonObject.put("name", temp);
Map<HttpMethod, Operation> mapOp = entry.getValue().getOperationMap();
Iterator<Entry<HttpMethod, Operation>> iterator2 = mapOp.entrySet().iterator();
while(iterator2.hasNext())
{
Entry<HttpMethod, Operation> entry2 = iterator2.next();
HttpMethod httpMethod = entry2.getKey();
String temp1 = httpMethod.name();
for (int i = 0; i < entry2.getValue().getParameters().size(); i++) {
// operation.getRequestBody()
// entry2.getValue().getParameters().get(i).get
System.out.println("entry2.getValue().getParameters().get(i)" + entry2.getValue().getParameters().get(i));
if (entry2.getValue().getParameters().get(i) instanceof BodyParameter) {
BodyParameter bp = (BodyParameter) entry2.getValue().getParameters().get(i);
Model schema = bp.getSchema();
// here i want my payload but i am not able to retrive
}
// System.out.println(entry2.getValue().parameter(entry2.getValue().getParameters().get(i)).getConsumes());
System.out.println(temp +" ====> "+ entry2.getValue().getResponses());
}
if(temp1.equalsIgnoreCase("GET"))
jsonObject.put("operation", "GET");
}
array.add(jsonObject);
}
System.out.println(array);
}
catch (Exception e) {
e.printStackTrace();
}
return array ;