question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide regular expressions and JSON schemas for UUIDs

See original GitHub issue

Hi 👋

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
golorodencommented, Jul 29, 2020

@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.

0reactions
broofacommented, Aug 11, 2022

Closing, as it doesn’t seem like a compelling enough argument has been made to add this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found