-
-
Notifications
You must be signed in to change notification settings - Fork 308
Add Defined Format: UUID #542
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
Comments
@JLLeitschuh since UUIDs are URIs, we've generally taken the position that to require a specific sort of URI you use both format and pattern: {
"type": "string",
"format": "uri",
"pattern": "^urn:uuid:"
} This is a pretty concise and readable way to indicate uuids (or https URIs, or mailto URIs, or whatever scheme you want) without having an explosion of format values. This has come up before so perhaps a note about this usage in the spec would help? |
Yes, noting this would be very useful. |
@JLLeitschuh why wouldn't it be? bash$ node
> let r = /^urn:uuid:/;
undefined
> r.test('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6');
true
> r.test('https://example.com/foo');
false
> |
Sorry, I guess I'm confused. I thought that the regex I totally misunderstood. |
@JLLeitschuh Oh, I see! Yeah, what I mean is that if the implementation you are using understands validating UUID URNs as part of I'm also realizing that maybe you just want the UUID part and not the URN? In that case, you are best off just defining a schema using that regex and referencing it with The I don't think that UUIDs on their own are a good candidate for a standardized format value. They are not as universal as URIs in general or IP addresses, nor are they particularly hard to validate with existing keywords such as |
I think you hit the nail on the head. I'm only referring to validating UUID's not that it is a URN.
I agree that they aren't that hard to validate with a regex, it just seemed like a common format that would allow code generators for languages like Java to see and know that they should be using the Just my 10¢. Thanks! |
We also need/use a
OpenAPI defines a few additional formats, and the OAI discusses creating a format registry, see OAI/OpenAPI-Specification#845 and OAI/OpenAPI-Specification#1345. |
@ralfhandl I don't think RFC 3339 includes duration, though. Anyway, if you'd like durations please file that separately, let's keep this issue focused on UUID. We're still working out the right threshold for standardizing formats. It's currently an awkward balancing act of extensibility vs interoperability vs implementation costs (right now if you implement one format, you are supposed to implement all of them, which is an increasingly high bar and somewhat problematic). The concept of modular vocabularies (#561) may help with this, although that issue as filed does not address the specifics of |
@JLLeitschuh regarding:
one of the main drivers of multi-vocabulary support (see #561) is to add a code generation vocabulary that would include hints for this kind of thing. Also hints as to whether an The validation spec is not really a good place for that sort of thing. See also #513 which moves some keywords out of validation so that they can sever as a basis for validation, hyper-schema, code generation, etc. If anyone out there likes the multi-vocabulary idea, even if the exact details of #561 aren't quite ideal for you, adding comments to #561 supporting the general direction would be most helpful. |
Formats usually serve the dual purpose of a programming-language-independent code-generation hint for the recipient and a production/validation instruction for the sender or an intermediate validator. So pulling formats out of validation seems to be the right direction. Opened #565 for |
It's probably worth pointing out that in the most popular language on Github (JS), the most popular module for schema validation (AJV @ 40M downloads/month) already supports Kinda feels like the standard has some catching up to do on this. :-/ [FWIW, came here because I'm using JSON schema for what I suspect is a very common use-case: server-API validation of REST resources backed by a DB where all the keys are UUIDs.] |
Hello I landed here as I'm learning JSON Schema and I want to represent a field in a document that's a UUID v4. I'm ready to extend https://pypi.org/project/jsonschema/ to add support for it. However, after reading this discussion, I'm not sure what's the recommend way to represent UUIDs. The documents will be of the form
Is there now an official stance? Should it be what OpenAPI suggests?
Or something else? Also, I'm not sure it's desirable to have Can someone please shed some light? |
I'd say "uuid" seems like a good format to add, as it's described in a standard endorsed by a major organization (IETF), it's in common use "in the wild", and it provides some semantic meaning (it's not merely a bunch of characters with dashes, if you know it's a UUID then you also know its URI). |
The UUID format is covered in RFC 4122. This standard could be a very simple addition to the default set of Defined Formats that JSON schema comes built in with.
There is a standard format that could be encoded as a pattern: https://en.wikipedia.org/wiki/Universally_unique_identifier#Format
Something like the following would work:
The text was updated successfully, but these errors were encountered: