Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api callbacks decorator #2233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MiguelSavignano
Copy link

@MiguelSavignano MiguelSavignano commented Jan 11, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Not possible to add callbacks property using a decorator.

What is the new behavior?

With the new @ApiCallbacks decorator is possible add callbacks in a controller method.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Documentation PR nestjs/docs.nestjs.com#2621

  • Create a new decorator @ApiCallbacks
  • document and provide examples in PR
  • define @ApiCallbacks config interface

OpenApi has a special property to define and document the callbacks https://swagger.io/docs/specification/callbacks/

This decorator allows to add in the generated OpenApi Specification of this callbacks property.

Usage

  @ApiCallbacks({
    name: 'mySecondEvent',
    callbackUrl: '{$request.body#/callbackUrl}',
    method: 'post',
    requestBody: {
      type: Cat
    },
    expectedResponse: {
      status: 200
    }
  })

Produces an OpenApi object:

{
  "callbacks": {
    "myEvent": {
      "{$request.body#/callbackUrl}": {
        "post": {
          "requestBody": {
            "required": true,
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cat"
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "Your server returns this code if it accepts the callback"
            }
          }
        }
      }
    }
  }
}

@destyk
Copy link
Contributor

destyk commented Aug 2, 2023

@kamilmysliwiec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants