cue icon indicating copy to clipboard operation
cue copied to clipboard

jsonschema: model URI and IRI formats

Open mahdanoura opened this issue 1 year ago • 2 comments

The JSON Schema specification allows for modeling resource identifiers, such as URIs and IRIs, using the format keyword to specify that a string is of a specific type (e.g., uri, iri, uuid).

For example, in JSON Schema, this can be defined as follows:

"properties": {
  "id": {
    "type": "string",
    "format": "uri"
  }
}

To the best of my understanding, CUE does not directly support the URI or IRI string formats as part of its standard types. What is the recommended approach or best practice in CUE for modeling such formats?

mahdanoura avatar Sep 13 '24 10:09 mahdanoura

cc @rogpeppe

mvdan avatar Sep 16 '24 13:09 mvdan

Currently AFAIK best approach is to use a regular expression (the first one I came across is here) but that's not ideal, clearly, given the size of it.

We should add a validator for this format, perhaps in a new net/url package. Given that we will want to support JSONSchema formats directly when importing JSON Schema into CUE, we will probably have direct support for most or all of those formats in the near(ish) future. Watch this space!

rogpeppe avatar Sep 16 '24 15:09 rogpeppe

I believe this was done in https://review.gerrithub.io/c/cue-lang/cue/+/1202106, as part of https://github.com/cue-lang/cue/issues/3479, back in October 2024.

mvdan avatar Dec 02 '25 21:12 mvdan