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

checkNoUnknown() #927

Closed
CarlosRodar opened this issue Sep 17, 2020 · 5 comments · Fixed by #1204
Closed

checkNoUnknown() #927

CarlosRodar opened this issue Sep 17, 2020 · 5 comments · Fixed by #1204

Comments

@CarlosRodar
Copy link

So I would like to add this to the v4+ APIs, not to the legacy APIs as they are difficult to implement, modularise and type.

My API suggestion for now is:

app.get('/some/path', [
  check('something').not().isEmpty(),
  checkNoUnknown()
], (req, res, next) => {});

Any better names? 🤔

Originally posted by @gustavohenke in #266 (comment)

Did you added this feature for the library?

@geritol
Copy link

geritol commented Oct 15, 2020

Would love to see something like this if there is a possibility for it!

@gustavohenke
Copy link
Member

Duplicate of #266 and #578

@alexandernanberg
Copy link

I'm using a schema but this seems to work quite well

const schema: Schema = {
  avatar: {
    in: ['body'],
    isURL: true,
    optional: { options: { nullable: true } },
  },
};

const schemaKeys = Object.keys(schema);

await checkSchema({
  ...schema,
  '*': {
    in: ['body'],
    custom: {
      options: (field, { path }) => {
        if (!schemaKeys.includes(path)) {
          throw new Error(`Unknown field: ${path}`);
        }
        return true;
      },
    },
  },
}).run(req);

@gustavohenke gustavohenke linked a pull request Feb 18, 2023 that will close this issue
2 tasks
@gustavohenke gustavohenke added this to the v7.0.0 milestone Feb 18, 2023
@gustavohenke
Copy link
Member

This is coming to v7 🙂

@gustavohenke
Copy link
Member

Hi hi, https://github.com/express-validator/express-validator/releases/tag/v7.0.0 is out with a fix for this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants