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

Add support for header validation #185

Open
regis-underdog opened this issue Aug 23, 2024 · 0 comments
Open

Add support for header validation #185

regis-underdog opened this issue Aug 23, 2024 · 0 comments

Comments

@regis-underdog
Copy link

regis-underdog commented Aug 23, 2024

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']
    );
...
  }
}
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

No branches or pull requests

1 participant