Using in -body instead of requestBody

(Coolbloke1324) #1

Using Stoplight Next on MacOS, imported a swagger.yaml file, started to define a new path and then the body of the request but found the output code is defining the body as parameters with in -body instead of using “requestBody”.

In our Node.js application we’re using swagger tools and the application simply doesn’t accept the body of the request unless I manually go into the exported code and change to using requestBody.

Could be our set up but in the docs for openapi it says the 2.0 way was using parameters in -body vs the 3.0 way of requestBody.

Am I correct or doing something wrong? If correct, will there be an update to support requestBody instead of the 2.0 way?

P.S. only used this tool for about 5 mins and I already love it. Once these things are solved I will be recommending we purchase a bunch of licenses. Writing OpenAPI swagger yaml by hand is the worst part of my day.

(Einnes) #2

I had this problem when I was first modelling my APIs. I think you need to give more information about the API (if it’s possible) to figure out if you are doing this wrong or it’s another issue. Maybe this helps the mistake I made was to put body parameters in the body like you say, but what was really needed was formData.

You put in: formData not in: body. In the case of my APIs it has to do with them consuming application/x-www-form-urlencoded. I’m not sure for yours. You might try it and see if it correctly models the behavior you want. I think body sort of puts everything together and you can’t pick and choose what you send… or that’s how that tag gets interpreted.

Also this answer is for OpenAPI 2.0.