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

Route schema validation #171

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Pietrohl
Copy link

Checklist

  • I have ensured my pull request is not behind the main or master branch of the original repository.
  • I have rebased all commits where necessary so that reviewing this pull request can be done without having to merge it first.
  • I have written a commit message that passes commitlint linting.
  • I have ensured that my code changes pass linting tests.
  • I have ensured that my code changes pass unit tests.
  • I have described my pull request and the reasons for code changes along with context if necessary.

Validation Schema to routes verb methods

This PR is to resolve the issue 170 for a possible new feature, to add a function overload to route[verb] function so it can accept a schema validation as second parameter.

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

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@koa/bodyparser 5.0.0 None +7 473 kB fengmk2

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.

None yet

1 participant