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

encoding/jsonschema: implement more format constraints #3479

Open
rogpeppe opened this issue Oct 3, 2024 · 0 comments
Open

encoding/jsonschema: implement more format constraints #3479

rogpeppe opened this issue Oct 3, 2024 · 0 comments

Comments

@rogpeppe
Copy link
Member

rogpeppe commented Oct 3, 2024

The format keyword in jsonschema could be implemented more fully.

As a very rough guide to prioritization, here are the set of formats used in schemastore.org,
each with the count of how many schemas use that keyword (ignoring different versions
of the same schema):

82   uri
26   date-time
20   uri-reference
14   regex
12   email
7    date
3    uuid
2    hostname
1    time
1    iri
1    ipv6
1    ipv4
1    int64
1    int32
1    duration
1    double
1    byte

Note that some of the formats used above are not actually recognized in JSON Schema. For example, int32 and int64 are OpenAPI-specific.

cueckoo pushed a commit that referenced this issue Oct 7, 2024
We put these inside the net package because the net package
already contains URL-related functionality (`QueryEscape`
and `QueryUnescape`) so URL-checking seems appropriate
to put there too.

We provide a different function for absolute vs possibly-relative
URL because JSON Schema has both `uri` and `uri-reference`.

For #3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Id8676c96f09b2e8e0ad69cbae0823182efa40730
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202104
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
cueckoo pushed a commit that referenced this issue Oct 7, 2024
There will be a bunch more format-related functionality
to add, and format is not actually string-specific (some format
constraints can apply to non-string values too), so
factor it into its own file.

For #3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ief66a284f0175bacb45c2e1ff8139f52aad19f8a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202105
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
cueckoo pushed a commit that referenced this issue Oct 7, 2024
The specification has a technical distinction between URI and IRI,
but there are no tests in the test suite that exercise that distinction,
and it's likely that almost everywhere that uses `"format": "uri"` actually
intends to allow non-ASCII characters too. Go's URL.Parse certainly
does.

For #3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I9644fc63b5cd9f52ad657145eeb342023188d797
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202106
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
cueckoo pushed a commit that referenced this issue Oct 7, 2024
This is a bit more restrictive than the spec allows,
as the TODO comment suggests, but it's probably OK for
now, and better than not supporting date-time at all.

For #3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ib0302c1fcf5b6a2f0ca669d17907a599a5d4f11f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202107
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
cueckoo pushed a commit that referenced this issue Oct 7, 2024
As the TODO says, this is a bit stricter than the specification,
but it will probably be OK for now.

For #3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Icbc9bf6a98058d5f6ca9c0fe87f5e29e4685255b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202108
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
We put these inside the net package because the net package
already contains URL-related functionality (`QueryEscape`
and `QueryUnescape`) so URL-checking seems appropriate
to put there too.

We provide a different function for absolute vs possibly-relative
URL because JSON Schema has both `uri` and `uri-reference`.

For cue-lang#3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Id8676c96f09b2e8e0ad69cbae0823182efa40730
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202104
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
There will be a bunch more format-related functionality
to add, and format is not actually string-specific (some format
constraints can apply to non-string values too), so
factor it into its own file.

For cue-lang#3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ief66a284f0175bacb45c2e1ff8139f52aad19f8a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202105
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
The specification has a technical distinction between URI and IRI,
but there are no tests in the test suite that exercise that distinction,
and it's likely that almost everywhere that uses `"format": "uri"` actually
intends to allow non-ASCII characters too. Go's URL.Parse certainly
does.

For cue-lang#3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I9644fc63b5cd9f52ad657145eeb342023188d797
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202106
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
This is a bit more restrictive than the spec allows,
as the TODO comment suggests, but it's probably OK for
now, and better than not supporting date-time at all.

For cue-lang#3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Ib0302c1fcf5b6a2f0ca669d17907a599a5d4f11f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202107
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
vanhtuan0409 pushed a commit to anduintransaction/cue that referenced this issue Oct 15, 2024
As the TODO says, this is a bit stricter than the specification,
but it will probably be OK for now.

For cue-lang#3479.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: Icbc9bf6a98058d5f6ca9c0fe87f5e29e4685255b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202108
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant