Provide regular expressions and JSON schemas for UUIDs
See original GitHub issueHi 👋
I’m one of the authors of the uuidv4 module.
With the new 8.3 version of uuid
there is almost everything there that is needed from our POV, and we are planning to deprecate uuidv4
in favor of this module.
However, there are two very small things missing, before we can do this:
First, it would be awesome to have regular expressions for UUIDs.
In uuidv4
we use the following ones:
const regex = {
v4: /(?:^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}$)|(?:^0{8}-0{4}-0{4}-0{4}-0{12}$)/u,
v5: /(?:^[a-f0-9]{8}-[a-f0-9]{4}-5[a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}$)|(?:^0{8}-0{4}-0{4}-0{4}-0{12}$)/u
};
Besides, it would be great to have JSON schemas for UUIDs. Again, we’re using this code here, which builds on top of the aforementioned regexs:
const jsonSchema = {
v4: { type: 'string', pattern: regex.v4.toString().slice(1, -2) },
v5: { type: 'string', pattern: regex.v5.toString().slice(1, -2) }
};
Unfortunately, we are missing the time to update the uuid
module ourselves, however this should be fairly easy to integrate.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top Results From Across the Web
How to define UUID property in JSON Schema and Open API ...
The only way I found so far is to manually specify the RegEx pattern as reusable schema component: openapi: 3.0.1 paths: /transactions/: ...
Read more >string — Understanding JSON Schema 2020-12 documentation
Regular Expressions The pattern keyword is used to restrict a string to a particular regular expression. The regular expression syntax is the ......
Read more >JSON Schema - Advanced Example
This example shows a possible JSON representation of a hypothetical machine's mount points as represented in an /etc/fstab file.
Read more >uuidv4 - npm
Please note that the regular expressions also consider empty() to be a valid UUID. Using a JSON schema. If you want to perform...
Read more >Solved: Object property name as UUID - SmartBear Community
"patternProperties" lets you define a regular expression for allowed property names. Whereas "propertyNames" lets you provide a schema for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@broofa We used
ajv
historically, but it is huge (which makes it a bad use case for the frontend), and its error messages are… well, they could better 😉Hence we switched to jjv, which is way smaller (compare https://bundlephobia.com/result?p=ajv@6.12.3 to https://bundlephobia.com/result?p=jjv@1.0.2), and which produces – when combined with jjve – nice, human-readable error messages.
Unfortunately, its last release has been 6 years ago, which is probably the main reason why it doesn’t support UUIDs.
So, not that you get this wrong:
ajv
is a great module, it’s just too large for small client-side bundles.Closing, as it doesn’t seem like a compelling enough argument has been made to add this.