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

[feat] Add request validation guard with jsonSchema #170

Open
2 tasks done
Pietrohl opened this issue Sep 11, 2023 · 0 comments
Open
2 tasks done

[feat] Add request validation guard with jsonSchema #170

Pietrohl opened this issue Sep 11, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Pietrohl
Copy link

Pietrohl commented Sep 11, 2023

Describe the feature

I'm trying to add new overload for the router[method] function, to add a validation middleware easily by passing a jsonSchema as the function second parameter. Right now I only did a quick update to the lib for my use case, but if the maintainers think that this could be good to include to the router I can expend some more time working on it.

example usage:

    const app = new Koa();
    const router = new Router();

    const schema = {
      type: 'object',
      properties: {
        x: { type: 'integer' }
      },
      required: ['x'],
      additionalProperties: false
    };

    router.post('/user', { body: schema }, function (ctx, next) {
      ctx.status = 201;
      ctx.body = { message: 'User added!' };
      }
    );

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
@Pietrohl Pietrohl added the enhancement New feature or request label Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant