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

Add support for format validation #72

Open
46 tasks
jdesrosiers opened this issue Dec 4, 2024 · 6 comments
Open
46 tasks

Add support for format validation #72

jdesrosiers opened this issue Dec 4, 2024 · 6 comments
Assignees

Comments

@jdesrosiers
Copy link
Collaborator

jdesrosiers commented Dec 4, 2024

JSON Schema has never required that the format keyword be validated. Since 2019-09, it's been required that it's not validated by default. For these reasons, I never chose to add support for validating format. I do want to support it eventually, but it's never been a priority.

I think this would be a good task for someone looking to contribute to open source. It's relatively straightforward, but requires proficiency with regular expressions, attention to detail, and the ability to read and understand RFCs. For each format, you'll need to understand the syntax and determine the best way to validate it. Sometimes that will be a regular expression, sometimes you'll need to find an appropriate library. There might be a case or two where you need to write the code to validate the format yourself, but mostly this should be about finding and using the right resource. The rest is just configuring the implementation for the keyword/vocabulary.

Acceptance Criteria

  • Must include a test runner for and pass all format tests in the official test suite
  • All defined formats are supported (Spec)
    • date-time
    • date
    • time
    • duration
    • email
    • idn-email
    • hostname
    • idn-hostname
    • ipv4
    • ipv6
    • uri (Use @hyperjump/uri)
    • uri-reference (Use @hyperjump/uri)
    • iri (Use @hyperjump/uri)
    • iri-reference (Use @hyperjump/uri)
    • uuid
    • uri-template
    • json-pointer
    • relative-json-pointer
    • regex
  • Validation is off by default in all dialects and can be enabled by setting a config
  • In 2019-09, the format vocabulary set to true enables validation by default but can still be disabled by config
  • By default, only formats defined by the dialect the schema uses are validated. Other formats are not enabled even if they are defined for another dialect. (Example: uuid should not be validated in draft-07)
    • draft-04 - date-time, email, hostname, ipv4, ipv6, uri
    • draft-06 - date-time, email, hostname, ipv4, ipv6, uri, uri-reference, uri-template, json-pointer
    • draft-07 - date-time, date, time, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, iri, iri-reference, uri-template, json-pointer, relative-json-pointer, regex
    • 2019-09 - date-time, date, time, duration, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, iri, iri-reference, uuid, uri-template, json-pointer, relative-json-pointer, regex
    • 2020-12 - date-time, date, time, duration, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, iri, iri-reference, uuid, uri-template, json-pointer, relative-json-pointer, regex
  • In draft-04/6/7, unknown formats return true
  • In 2019-09 with the format vocabulary set to false, unknown formats return true
  • In 2019-09 with the format vocabulary set to true, unknown formats throw an error
  • In 2020-12 with the format-annotation vocabulary, unknown formats return true
  • In 2020-12 with the format-assertion vocabulary, unknown formats throw an error
  • Users can enable a defined format in a draft that didn't define it yet. (Example: enabling uuid in draft-07 schema)
  • Users can define and enable custom formats for specific dialects
  • Annotations are collected when validation is enabled
  • Works in node.js and the browser
  • When validation is off, its code must not be bundled
  • Bundle size for browsers should be kept as small as possible (Be careful about including large dependencies)
  • Update README
@techmannih
Copy link

techmannih commented Dec 8, 2024

Hey @jdesrosiers I’m available and interested in contributing to this issue.

@jdesrosiers
Copy link
Collaborator Author

Thanks for helping out! The format keyword implementation is a good place to start.

@Vishv0407
Copy link

Hi @jdesrosiers ,

I would like to work on this issue and believe I understand the problem described. I have forked and cloned the repository and tried exploring the codebase, but I couldn’t identify where to make the necessary modifications for the "format" validation.

Could you please guide me on which files/modules are relevant? Also, it would be great if you could provide instructions on how to run this project locally to test my changes.

@jdesrosiers
Copy link
Collaborator Author

@Vishv0407 Thanks for offering, but @techmannih is already working on it. I have no problem with multiple people working together on it, but I'll leave it up to @techmannih to decide if and how they want to bring someone else in.

@techmannih
Copy link

@Vishv0407 Thank you for showing your interest. I'm glad! Yes, we can discuss this issue on Slack, and we can work together in collaboration.

@Vishv0407
Copy link

Vishv0407 commented Dec 24, 2024

@techmannih sure!, let's start discussion on slack.

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

3 participants