How to get the body payload?
See original GitHub issueI am hoping this is a defect against documentation.
I am unable to retrieve the body payload for a POST operation.
Using the Swagger-Petstore sample, the POST to /pet has a body parameter defined as:
{
"in": "body",
"name": "body",
"description": "Pet object that needs to be added to the store",
"required": true,
"schema": {
"$ref": "#\/definitions\/Pet"
}
}
Here is my sample code:
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.parser.SwaggerParser;
public class PetPostBody {
public static void main(String[] args) {
Swagger swagger = new SwaggerParser().read("http://petstore.swagger.io/v2/swagger.json");
Path pet = swagger.getPath("/pet");
Operation post = pet.getPost();
Parameter body = null;
for (Parameter param : post.getParameters()) {
if (param.getIn().equals("body"))
body = param;
}
body.get???
}
}
How do I retrieve the payload?
The only things that I can see (in debugger) for body is schema but that is access protected(?), and under that is genericRef (access private) that points to the definitions.
What am I missing?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
HTTP GET with request body - Stack Overflow
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing...
Read more >GET - HTTP - MDN Web Docs
It is better to just avoid sending payloads in GET requests. Request has body, No. Successful response has body, Yes. Safe, Yes. Idempotent,...
Read more >Request bodies in GET requests - Evert Pot
A payload within a GET request message has no defined semantics. That sentence could easily suggest that there's no specific behavior ...
Read more >REST API - HTTP GET with Request Body - Roy Tutorials
Generally payload in the body is sent for POST, PUT, etc. http methods where you need to create a new resource or update...
Read more >Add a Request Body to a POST Request | API Connector
As part of a POST , PUT , or PATCH request, a data payload can be sent to the server in the body...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Forgive me if I misunderstand your question but in case this helps . . . In swagger-parser 1, I use io.swagger.models.parameters.BodyParameter.getSchema()
In swagger-parser 2, I use io.swagger.oas.models.media.MediaType.getSchema()
Looks like
schema.get$ref()andschema.getReference()get you the same thing … at least in my case. So the approach I posted above is the correct way forward?Our development has decided to use an API framework that only generates OAI2, and only partially at that. I do not have any say in that.