URI format validation

2,689 views
Skip to first unread message

Ivan Porto Carrero

unread,
Jan 24, 2015, 12:52:00 PM1/24/15
to json-...@googlegroups.com
Hi

The json schema test suite says that for the uri format a relative reference is not allowed.


But the swagger schema defines a host property, there it's defined as:


It's my guess that the intended format in the swagger spec is actually hostname but the threads about uri's are conflicting in their responses. So I would like to get a definitive resolution and perhaps the json schema rfc can be clarified to this point as outcome of this thread.  

At this moment it's impossible for both the test suites (jsonschema and swagger) to pass, clearly that's not ideal. And to settle the discussion in the swagger group, a resolution is first required here. 

Sebastian Lasse

unread,
Jan 25, 2015, 6:02:09 AM1/25/15
to json-...@googlegroups.com
Off course: relative references ARE allowed.
The spec. says: "A string instance is valid against this attribute if it is a valid URI, according to [RFC3986]."

I think while 'abc' is not valid './abc' is valid. See 'relative references' in RFC 3986.
Correct me if I'm wrong, but I just raised this issue :

Tim Becker

unread,
Jan 26, 2015, 4:09:01 AM1/26/15
to json-...@googlegroups.com
I've been running into some problems with this as well.

E.g. https://github.com/fge/json-schema-validator/ complains about relative URIs saying:

    URI \"./base_types/base_types.json#definitions/updated_at\" is not normalized

Perhaps I'm missing something, but while the URI is not absolute, imo it's normalized. Unfortunately, every single validation suite I've tried seems to handle this differently, hence my asking for a "definitive" meta-validator as a final judge for disputes (https://groups.google.com/forum/#!topic/json-schema/ViZwCSeEZPg)

In cases where "open" questions like this pop up, we could always add more tests ...

     -tim

Austin Wright

unread,
Feb 4, 2015, 5:44:51 AM2/4/15
to json-...@googlegroups.com
A URI is by definition absolute, so a URI Reference wouldn't be allowed. There's an outstanding bug to add a "uriref" production to formats, if you need to declare a URI Reference.

The lack of the "uriref" production in the current draft might be because there's not really a regex defining what a URI Reference is, the _vast_ majority of ASCII strings can validate as a valid URI Reference. It doesn't help that the draft is very inconsistent in its usage of the URI vocabulary, that's also under fix.

Austin.

Austin Wright

unread,
Feb 4, 2015, 5:47:53 AM2/4/15
to json-...@googlegroups.com


On Sunday, January 25, 2015 at 4:02:09 AM UTC-7, Sebastian Lasse wrote:
Off course: relative references ARE allowed.

Relative references are not allowed under the "uri" production.

Relative references aren't URIs, they're URI References. Given a base URI, they can be resolved into a URI, however (hence the term URI Reference, it refers to a URI, given a base).

Sebastian Lasse

unread,
Feb 4, 2015, 6:08:53 AM2/4/15
to json-...@googlegroups.com
Ok - so the specification is wrong ?
That would mean: 
You can't say "anything according to RFC3986" because RFC3986 includes "relativeURI" ...

Austin Wright

unread,
Feb 4, 2015, 2:54:45 PM2/4/15
to json-...@googlegroups.com
JSON Schema specifically references the "URI" ABNF production from RFC3986, not "pick any ABNF production defined from RFC3986" which wouldn't make very much sense, I think.

Austin.

Sebastian Lasse

unread,
Feb 5, 2015, 5:07:56 AM2/5/15
to json-...@googlegroups.com
Ok, I agree to Ivan:
"And to settle the discussion in the swagger group, a resolution is first required here."
So I just mailed to the inventor of JSON Schema.

If URI References would not be allowed that would also mean that many implementations have to update their code,
for instance heroku or jayschema, saying
"
Format specifiers
• uri: As in RFC 3986 Appendix A, including relative URIs (no scheme part, fragment-only), with the exception that well-formedness of internal elements, including percent encoding and authority strings, is not verified.
"

Sebastian Lasse

unread,
Feb 5, 2015, 3:16:01 PM2/5/15
to json-...@googlegroups.com
Got a quick reply by Kris Zyp:

"I would think that relative uris should be legal."

just saying ...

Austin Wright

unread,
Feb 5, 2015, 5:39:27 PM2/5/15
to json-...@googlegroups.com
All I really have to say is that the use of terminology is inconstistent, and this is a known bug: https://github.com/json-schema/json-schema/issues/8


If "uri" indeed means URI Reference, then there's no way to validate an actual (absolute) URI, and validating a URI Reference doesn't really make too much sense because almost most any arbitrary string is a valid URI Reference.

There's lots of people using "uri" to mean absolute URI only. Someone is wrong, someone is going to have to fix their code no matter what, which is unfortunate.

However, I doubt very many implementations allow URI References, the official test suite tests that a URI Reference is disallowed for a format:"uri" rule: https://github.com/json-schema/JSON-Schema-Test-Suite/blob/0ba672265758f09405b14a6508ff696a35e857ca/tests/draft4/optional/format.json#L38

Austin. 

Austin Wright

unread,
Feb 5, 2015, 5:40:44 PM2/5/15
to json-...@googlegroups.com

Argh, wrong URL, this should read:

 All I really have to say is that the use of terminology is inconstistent, and this is a known bug: https://github.com/json-schema/json-schema/issues/81

Austin.
Reply all
Reply to author
Forward
0 new messages