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

Option on validateResponseByPath to strip non wanted props #84

Open
seromenho opened this issue May 26, 2021 · 2 comments
Open

Option on validateResponseByPath to strip non wanted props #84

seromenho opened this issue May 26, 2021 · 2 comments

Comments

@seromenho
Copy link

Hey would an option to validate response to strip non wanted fields be a good idea for the package?

@supertong
Copy link
Collaborator

Hey @seromenho , can you elaborate the idea with an example and a use case?

@seromenho
Copy link
Author

seromenho commented May 26, 2021

Yes sure. Sorry should have done it in the issue description.
validateResponseByPath throws an error for example when there's extra props in the response that shouldn't be in there.
Ideally it shouldn't be needed but.... say there's no proper testing in place and there's an extra field being sent on the response instead of an error maybe we can use this validator to remove this not allowed extra props. (It wouldn't be anymore only about validating though)

eg:

const responseSchema = {
  type: 'object',
  properties: {
    id: {
      type: 'string',
      format: 'uuid',
      readOnly: true,
    },
    name: {
      type: 'string',
      minLength: 2,
      maxLength: 255,
    }
}

const response = {
  id: '18a4c52e-035a-4599-bbc6-b467b36b1d38',
  name: 'test',
  password: '$2a$10$qjEcP6MyPTWwbXJVE09qcuP2D1BBh3aMpPE3D4L3wMuolgjAaJXoe'
}

Given this example and passing this optional setting it would not thrown an error but instead fix it by removing the not allowed properties (password) from the response.

Haven't thought on required in the first place but could either be the same option or another setting for required. Or keep throwing the error :)

What do you think?

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

2 participants