"in: body" in parameters causes an error
hrs-allbsd opened this issue · comments
I am unsure if this is just my misunderstanding or an actual bug, but I got an error when I tried to use POST method and "in: body".
The details are as follows. I tried an example found at https://github.com/jonasbn/perl-mojolicious-plugin-openapi-tutorial-parameters/. I changed getUserByParameter to use POST by using the following spec. Only the method and the parameters were changed:
"/user": {
"post": {
"operationId": "getUserByParameter",
"x-mojo-name": "get_user_by_parameter",
"x-mojo-to": "user#get_by_parameter",
"summary": "User response",
"parameters": [
{"in": "body", "name": "id", "schema": { "type": "string"} }
],
After that, I tried ./script/parameters openapi /api
and the following error occurred:
% perl ./script/parameters openapi /api
[2022-07-18 05:39:37.11343] [63029] [trace] [Fde4Rj-OsFGO] GET "/api"
[2022-07-18 05:39:37.11371] [63029] [trace] [Fde4Rj-OsFGO] Routing to a callback
[2022-07-18 05:39:37.11994] [63029] [trace] [Fde4Rj-OsFGO] 200 OK (0.00651s, 153.610/s)
Invalid schema: http://127.0.0.1:23781/api has the following errors:
/paths/~00000001user/post/parameters/0: /oneOf/1 Properties not allowed: accepts, in, name, schema, type.
/paths/~00001user/post/parameters/0: /oneOf/0/oneOf/1/oneOf/3 Properties not allowed: accepts, schema.
/paths/~0001user/post/parameters/0: /oneOf/0/oneOf/1/oneOf/2 Properties not allowed: accepts, schema.
/paths/~001user/post/parameters/0: /oneOf/0/oneOf/1/oneOf/1 Properties not allowed: accepts, schema.
/paths/~01user/post/parameters/0: /oneOf/0/oneOf/1/oneOf/0 Properties not allowed: accepts, schema.
/paths/~1user/post/parameters/0: /oneOf/0/oneOf/0 Properties not allowed: accepts, type. at /usr/local/lib/perl5/site_perl/OpenAPI/Client.pm line 66.
When I tried ./script/parameters openapi ./openapi.json
to directly read the spec, no error occurred:
% perl ./script/parameters openapi ./openapi.json
--- Operations for http://localhost/api
getUserByParameter
getUsers
getUserByUrl
I have no idea why openapi /api
caused the error. After some more investigation, I noticed the following:
- "in: query" works fine in both cases.
- When using Mojolicious::Lite, like an example in https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/main/README.md, the app works fine with "in: body". A full app like this tutorial does not.
Is this an expected behavior? This error seems not specific to this example. I confirmed that it was reproducible by creating a smaller app with "in: body" in the parameters.
The version numbers are as follows:
- Mojolicious: 9.26
- Mojolicious::Plugin::OpenAPI: 5.05
- OpenAPI::Client: 1.04
No, this is not expected behavior. There's no difference between a lite app and full app, except maybe how it locate files in your directory structure.
I also use "in:body" many places and that case also has a bunch of tests, so I doubt there's a bug there...
https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/main/t/v2-body.t#L33
Here are some more resources which might help:
I'm going to close this issue now. Please join #perl-openapi on https://libera.chat/ or drop me an email i you want me to look into this further.