koa-swagger-decorator icon indicating copy to clipboard operation
koa-swagger-decorator copied to clipboard

Add support for header validation

Open regis-underdog opened this issue 6 months ago • 1 comments

Swagger supports header parameters as described here https://swagger.io/docs/specification/describing-parameters/#header-parameters

The example I would like to see is add a @header() parameter like this example for a GitHub webhook:

export default class GitHubWebHookRouter {
  @request('post', '/webhook/github')
  @summary('Receive webhooks from GitHub.')
  @body(WebhookEvent)
  @header({'x-github-delivery': { type: string, required: true, default: '', description: 'GitHub ID' }})
  @header({'x-github-event': { type: string, required: true, default: '', description: 'GitHub Event' }})
  @header({'x-hub-signature-256': { type: string, required: true, default: '', description: 'GitHub 256 Signature' }})
  @header({'x-github-hook-installation-target-id': { type: string, required: true, default: '', description: 'GitHub Target ID' }})
  static async receiveGitHubWebHookController(ctx) {
    const payload = ctx.request.body;
    const id = ctx.request.headers['x-github-delivery'];
    const type = ctx.request.headers['x-github-event'];
    const targetId = parseInt(ctx.request.headers['x-github-hook-installation-target-id']);
    const verified = verify(
      GITHUB_WEBHOOK_SECRET,
      JSON.stringify(payload),
      ctx.request.headers['x-hub-signature-256']
    );
...
  }
}

regis-underdog avatar Aug 23 '24 20:08 regis-underdog