jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
53 stars 41 forks source link

"in: body" in parameters causes an error #238

Closed hrs-allbsd closed 1 year ago

hrs-allbsd commented 1 year ago

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:

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:

jhthorsen commented 1 year ago

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

jhthorsen commented 1 year ago

Here are some more resources which might help:

jhthorsen commented 1 year ago

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.