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

Duplicate required() generates invalid schema #114

Closed
boyander opened this issue Mar 23, 2021 · 2 comments · Fixed by #117
Closed

Duplicate required() generates invalid schema #114

boyander opened this issue Mar 23, 2021 · 2 comments · Fixed by #117

Comments

@boyander
Copy link
Contributor

🐛 Bug Report

Calling required() twice on same prop duplicates key in required schema array required:[<prop>,<prop>] generating an invalid schema.

To Reproduce

Steps to reproduce the behavior:

const S = require('fluent-json-schema')

const schema = S.object()
  .prop('email', S.string()).required().required()
  
console.log(JSON.stringify(schema.valueOf(), undefined, 2))

causes invalid schema with duplicate prop in required array

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "email": {
      "type": "string"
    }
  },
  "required": [
    "email",
    "email"
  ]
}

https://replit.com/@boyander/duplicatedrequiredprop

Expected behavior

Either throw an error if using require() twice or generate the required:[] array using a Set

Your Environment

  • node version: 12
  • os: Mac

Also, congrats for this awesome package. We use it a lot at @core-school

@mcollina
Copy link
Member

We are glad you like it!

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@boyander
Copy link
Contributor Author

Sure! Will work on it this weekend ☀️

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants