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

Support OpenAPI Webhooks #728

Closed
2 tasks done
MatanYadaev opened this issue Jun 12, 2023 · 1 comment · Fixed by #760
Closed
2 tasks done

Support OpenAPI Webhooks #728

MatanYadaev opened this issue Jun 12, 2023 · 1 comment · Fixed by #760
Labels
feature request New feature to be added good first issue Good for newcomers

Comments

@MatanYadaev
Copy link

MatanYadaev commented Jun 12, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

OpenAPI 3.1 has a concept of webhooks. It's similar to callbacks, but in webhooks, the API initiates the request. It's not an async response to the client's request.

Currently, Fastify Swagger doesn't support this feature.

Motivation

It's part of the OpenAPI 3.1 specification and it gives a lot of context for the API clients.

Example

Defining the schema:

await app.register(FastifySwagger, {
	openapi: {
		openapi: '3.1.0',
		info: {
			title: 'Fastify Project',
			description: 'Fastify Project',
			version: '0.0.0',
		},
		webhooks: {
			newPet: {
				post: {
					requestBody: {
						description: 'Pet to add to the store',
						content: {
							'application/json': {
								schema: {
									$ref: '#/components/schemas/NewPet',
								},
							},
						},
					},
					responses: {
						'200': {
							description: 'OK',
						},
					},
				},
			},
		},
	},
});

Should generate this OpenAPI specification:

openapi: 3.1.0
info:
  title: Fastify Project
  description: Fastify Project
  version: 0.0.0
components:
  schemas: {}
webhooks:
  newPet:
    post:
      description: Pet to add to the store
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'
      responses:
        '200':
          description: OK
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants