Hi,
I am trying to parse swagger.json file using swagger-parser , want to create request file and response file in the from of json out of it.
How to get the values of schema from parameter object.
Bellow is the part of the swagger.json file. schema is highlighted.
Also I have a code snippet to read the values from it where "op" is operation object. I did not find any method to read schema like other parameter.
Swagger.json
"/pet": {
"post": {
"tags": ["pet"],
"summary": "Add a new pet to the store",
"description": "",
"operationId": "addPet",
"consumes": ["application/json",
"application/xml"],
"produces": ["application/xml",
"application/json"],
"parameters": [{
"in": "body",
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": true,
"schema": {
"$ref": "#/definitions/Pet"
}
}],
"responses": {
"405": {
"description": "Invalid input"
}
},
"security": [{
"petstore_auth": ["write:pets",
"read:pets"]
}]
},
"put": {
"tags": ["pet"],
"summary": "Update an existing pet",
"description": "",
"operationId": "updatePet",
"consumes": ["application/json",
"application/xml"],
"produces": ["application/xml",
"application/json"],
"parameters": [{
"in": "body",
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": true,
"schema": {
"$ref": "#/definitions/Pet"
}
}],
"responses": {
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Pet not found"
},
"405": {
"description": "Validation exception"
}
},
"security": [{
"petstore_auth": ["write:pets",
"read:pets"]
}]
}
}
Code Snippet
try{
List<Parameter> parameters=op.getParameters();
for(Parameter p:parameters)
{
System.out.println("p.getIn()"+p.getIn());
System.out.println("p.getName()"+p.getName());
System.out.println("p.getAccess()"+p.getAccess());
System.out.println("p.getDescription()"+p.getDescription());
System.out.println("p.getPattern()"+p.getPattern());
System.out.println("p.getRequired()"+p.getRequired());
}
System.out.println("\n");
}
catch(NullPointerException n)
{
System.out.println("no value found");
}