jhthorsen / mojolicious-plugin-openapi

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

Response reference ignored and overridden by DefaultResponse #226

Closed polettix closed 2 years ago

polettix commented 2 years ago

In the example inside this gist it seems that the referenced responses item is ignored and overridden.

What comes out (full version here) contains both the $ref from the input definition as well as other stuff from DefaultResponse (content and description):

      "404": {
        "$ref": "#/components/responses/404",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/DefaultResponse"
            }
          }
        },
        "description": "Default response."
      },

Alas, the $ref is ignored and the stuff from DefaultResponse is used instead, against to the expectations.

The example run below is supposed to yield a "valid" 404 response (i.e. compliant to $ref), but it is overridden due to DefaultResponse and leads to a 500 response instead:

[2021-11-07 13:29:32.79225] [26342] [trace] [BiMmKMvSF87y] GET "/item/404"
[2021-11-07 13:29:32.79293] [26342] [trace] [BiMmKMvSF87y] Routing to a callback
[2021-11-07 13:29:32.79357] [26342] [trace] Your secret passphrase needs to be changed
[2021-11-07 13:29:32.79443] [26342] [warn] OpenAPI >>> GET /item/404 [{"message":"Missing property.","path":"\/body\/errors"}]
[2021-11-07 13:29:32.79478] [26342] [trace] [BiMmKMvSF87y] 500 Internal Server Error (0.002525s, 396.040/s)
{
  "errors": [
    {
      "message": "Missing property.",
      "path": "/body/errors"
    }
  ],
  "status": 500
}

(I would also contend that this 500 response is wrong with respect to the OpenAPI definition, but this is for another issue maybe).

The OpenAPI definition in the example Mojolicious::Lite program seems to be valid in the online swagger editor, so my current guess is a bug in this module.

jhthorsen commented 2 years ago

Thanks for reporting in! Forgot to reply!yesterday, since GitHub automations closed the issue for me.

Does this mean there will be a Perl Weekly update? :)

polettix commented 2 years ago

Hi :-)

I can surely blog about it... let's just hope it will end up in Perl Weekly!

Thanks,

Flavio.

Il giorno sab 20 nov 2021 alle ore 22:08 Jan Henning Thorsen < @.***> ha scritto:

Thanks for reporting in! Forgot to reply!yesterday, since GitHub automations closed the issue for me.

Does this mean there will be a Perl Weekly update? :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/226#issuecomment-974711517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA363APOG3DDO4Z2OIALTTUNAE4JANCNFSM5HQZ7LUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jhthorsen commented 2 years ago

Maybe I'm mixing up names/issues - I thought this was mentioned this weeks issue of "Perl Weekly" 😄

polettix commented 2 years ago

I was a bit too concise...

I blogged about the module (and the issue) here: https://github.polettix.it/ETOOBUSY/2021/11/08/perl-openapi/

Perl Weekly then included the post in #538: https://perlweekly.com/archive/538.html

Now... there's a new blog post here: https://github.polettix.it/ETOOBUSY/2021/11/21/perl-openapi-update/

Let's just hope it will be picked up by Perl Weekly again!

Ciao,

Flavio.

Il giorno dom 21 nov 2021 alle ore 01:44 Jan Henning Thorsen < @.***> ha scritto:

Maybe I'm mixing up names/issues - I thought this was mentioned this weeks issue of "Perl Weekly" 😄

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/226#issuecomment-974733443, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA363BTABZUZJK6OEPEPC3UNA6G5ANCNFSM5HQZ7LUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jhthorsen commented 2 years ago

Thank you! 😄