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

Recognizing the hyper-schema meta-schema? #33

Open
handrews opened this issue May 1, 2017 · 7 comments
Open

Recognizing the hyper-schema meta-schema? #33

handrews opened this issue May 1, 2017 · 7 comments
Labels

Comments

@handrews
Copy link

handrews commented May 1, 2017

Similar to #28, would it be possible to automatically recognize http://json-schema.org/draft-04/hyper-schema and http://json-schema.org/draft-06/hyper-schema as built-in supported meta-schemas?

(venv) HenrysMacBookPro:schemas henry$ ajv compile -s common/user.json
schema common/user.json is invalid
error: no schema with key or ref "http://json-schema.org/draft-04/hyper-schema#"
(venv) HenrysMacBookPro:schemas henry$ curl http://json-schema.org/draft-04/hyper-schema > hyper-schema
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4639  100  4639    0     0  21803      0 --:--:-- --:--:-- --:--:-- 21882
(venv) HenrysMacBookPro:schemas henry$ ajv compile -m hyper-schema -s common/user.json
schema common/user.json is valid
(venv) HenrysMacBookPro:schemas henry$ 
@epoberezkin
Copy link
Member

I'd rather have #29 to be honest - it would cover it.

@handrews
Copy link
Author

handrews commented May 1, 2017

You mean it would only work by fetching over the network? That's actually against the advice of the spec:

JSON Schema implementations SHOULD implement support for
current and previous published drafts of JSON Schema vocabularies as
deemed reasonable.

plus various notes about things being identifiers and how implementations SHOULD NOT automatically download (presumably if you are passing a custom meta-schema via a URI you know that it's fine to download, but do we really want constant traffic hitting json-schema.org?)

@handrews
Copy link
Author

handrews commented May 1, 2017

(actually I'm not sure why I thought that quote indicated local support, but there are things about not overburdening schema servers)

@handrews
Copy link
Author

handrews commented May 3, 2017

I'll probably end up using a modified local schema for testing anyway, but wearing my json-schema-org hat, I'm still a bit concerned about an extremely popular tool regularly fetching the meta-schemas, especially if that is the default behavior.

Happy to do a PR for this if I can sell you on it :-)

@epoberezkin
Copy link
Member

Ok. Should it be an option (--hyper)? Or just add them?
I think it won't hurt much, they are only validated, not compiled.

But if your idea is to use modified meta-schema as a substitute for hyper-schema (without changing $schema) which can be valuable for testing you will have name conflict if they are added by default.

So maybe an option --hyper to add hyper-schemas

And maybe even an option --meta=false to avoid adding standard meta-schemas (for the same reason - to allow testing with modified meta-schemas). The latter is a bit more tricky, as this option would affect how schemas are validated, not only whether meta-schemas are added or not.

@handrews
Copy link
Author

handrews commented May 3, 2017

I definitely like the idea of a switch to disable standard meta schemas, whether that by default includes the meta-hyper-schema or not. In production I expect to use the standard meta-schemas, the modified ones that spoof the standard ids are only for internal dev/test mode. If they were in production they'd make evolving the APIs very difficult because of the strictness.

With my JSON Schema spec author hat on, I want to say "implementation should automatically support all standards-defined meta-schemas equally", but thinking from an implementor/validation-only user, I can see not including it.

The best argument I can think of for including it is that validating hyper-schemas is still validation and will hopefully be an increasingly common thing, so the UX is nicer if it's supported. But I'm not inclined to dig in on this.

I think if it is included, it should be automatic. That keeps UX parity which I think is the main reason to do it, and I can think of why that would be a problem (unless there's some internal performance reason).

@epoberezkin
Copy link
Member

I am not that fussed about what it the default, to include or to skip. The performance impact is negligible in this case.

As long as there is an option to control it it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants