kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Callback validation

Open orensolo opened this issue 3 years ago • 3 comments

Hi, I need to validate a callback request and response. (i.e validate that the request/response body is valid according to the schema) I didn't find any support for this. I know that since the callback path is dynamic, you can not find it in the schema in the same way as with other requests/responses. Do you have any support for this?

Thanks, Oren

orensolo avatar Sep 22 '22 11:09 orensolo

I believe you're looking for request/response validation code. This should help: https://pkg.go.dev/github.com/getkin/[email protected]/openapi3filter#example-package

Callback validation is supported. If you're not getting the thing you're expecting, please share your code.

fenollp avatar Sep 22 '22 18:09 fenollp

Thanks for the quick reply.

The problem is with this line :

route, pathParams, err := router.FindRoute(r)

The route is not found because the callback URL is not constant.

For example,

/subscribe:
    post:
      summary: Subscribe to a webhook
      requestBody:
        …
      callbacks:   # Callback definition
        myEvent:   # Event name
          '{$request.body#/callbackUrl}'	<===**This is not constant**
         post:
              requestBody:   # Contents of the callback message
                required: true
                content:
                  application/json:
                    schema:
                      type: object

The callback URL is the callbackUrl property value in the subscribe request body. So, its value depends on the subscribe request body.

kin open API does not find the callback path (so it also does not find its schema).

And this is the problem...

orensolo1 avatar Sep 22 '22 20:09 orensolo1

Ah so you're using routers, probably the one that's not called "legacy". Have a look into https://github.com/getkin/kin-openapi/blob/fa5d9a9b251edabf09f20bebd8aebba923c4da44/routers/gorillamux/router.go There's no mention of callbacks. Meaning the issue here is not that callbacks are not constant. It's just that FindRoute is not implemented to handle callbacks, yet. Feel free to take a stab at it :)

fenollp avatar Sep 23 '22 08:09 fenollp