There are a lot of examples that use post/put and add parameters in body like so:
/**
* @OA\Put(
* path="/register",
* @OA\Parameter(
* name="email",
* in="body",
* description="Email address of the user ",
* required=true,
* @OA\Schema(
* type="string",
* ),
* ),
* @OA\Response(response="201", description="Account was successfully created."),
* )
*/
But this generates a php notice
PHP Notice: @OA\Parameter(name="email",in="body")->in "body" is invalid, expecting "query", "header", "path", "cookie"
I can see the RequestBody but I feel its output isn't as desired in swagger-ui.
/**
* @OA\Put(
* path="/register",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="email",
* description="Email address of the new user.",
* type="string",
* ),
* ),
* ),
* ),
* @OA\Response(response="201", description="Account was successfully created."),
* )
*/
The first example outputs this, but the second outputs this.
EDIT: According to the 3.0 spec it isn't valid, https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#fixed-fields-10 I guess thats why it doesn't work.
I could not find examples with the old in="body" notation.
(This was the way you'd write it in swagger v2)
Is there also something wrong with the second?
Lots of examples have it, but its hard to see whats v2 and whats v3. Im thinking @SWG is v2 and @OA is v3?
https://github.com/zircote/swagger-php/blob/615b5fa475b22fbf7a8881c7b6acb104da0dabc0/Examples/dynamic-reference/README.md
In this example here it lists in="body".
Now that I know its a v2 vs v3 issue I guess my problem is with swagger-ui. The second pic defines email, but to know if its required what its description is or any of the additional properties you have to click through to viewing the model.
The second one also does make more sense because the items are not parameters, they are the payload in the body.
In case someone is still looking for request body definition
In case someone is still looking for request body definition
Exactly how can we use the requestBody to annotate the controller's method? I'm quite new to this and there's not much documentation regarding this..
Question is: what do you expect that the output is?
That first example seems to be Swagger 2.0 (see https://swagger.io/docs/specification/2-0/describing-request-body/) and the second example looks like OpenAPI 3.
The second example is how I would expect an API to behave... the first example is a bit weird to me (not JSON, just a plain string). I would at least expect that first example to be formData instead of just body...
Most helpful comment
In case someone is still looking for request body definition