-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
"$schema" guidance for OAS 3.1 #2017
Comments
(added a TL;DR up top for those who got the long initial email and decided not to read it 😄 ) |
For these two:
Yes to both, and will be part of #1977. I've taken a swing at the wording but I'm sure it'll take some polishing. |
@philsturgeon the text at https://github.com/OAI/OpenAPI-Specification/pull/1977/files#diff-b83206d953b4be5d312b068f82ba0217R2324 indicates "no" to the first and "yes" to the second, which I think is actually what we want. In any event, we should resolve this as a follow-up to 1977 and not burden it with further subtleties and wording debates. |
@handrews I believe we've got the answers we needed here, what is the next move? |
@philsturgeon no, we haven't had this answered. You can't answer "yes to both" because they contradict each other (I could have phrased that question better, sorry). PR 1977 at last check implied no/yes, which I think is correct but needs confirmation from @OAI/tsc |
@handrews the answer I was referring to was not my earlier comment, but the PR 1977 implying no/yes. So... yeah who is the best person to ask? If we ask a specific person like... @darrelmiller then better chance of an answer. |
@philsturgeon I'm still confused. I assume you are referring to this part of PR 1977, which does say that everything is allowed, but my recollection was that we deferred a final decision on that and needed TSC consideration. [Edit: Was not at my best when posting this because (gestures vaguely at pandemic), cleaned up the tone a bit- my apologies.] |
I do not recall having this conversation. I do remember reading about the issue and thinking that getting an answer is going to hurt my brain. I will review the material and thing more about this. I'm going to /cc @OAI/tsc and ask for folks to form opinions. I do not believe we want to allow arbitrary keywords and just ask tooling to ignore them. Should we allow $schema to introduce additional keywords. That I will have a better answer for once I have read Henry's essay. |
@darrelmiller note that we're considering treating unknown keywords as annotations per json-schema-org/json-schema-spec#698 If/when we have a machine-readable indication of what keywords are part of a vocabulary, then we could restrict that behavior to unknown vocabularies. But right now we can't tell which keywords are part of an unknown vocabulary and which are just unknown entirely. |
Aha! We have a plan.
Originally posted by @darrelmiller in #2188 (comment) I'll take charge of writing up some words for this, pending a chat on OpenAPI Slack with @Relequestual once he gets an invite. |
@philsturgeon @Relequestual @darrelmiller
As a reminder, an example of both the dialect and vocabulary meta-schemas and possible
meta-schemas are set on a per-resource basis, and the main OAS file is a resource. So schema objects in the OAS file are part of that resource, and that resource can (and should) define the default meta-schema like this.
Yup, this is correct. To make certain we're all on the same page: Schema objects that are separate files, or are inline schema objects or subschemas with their own If they are inline schema objects or subschemas that have an |
Had a go at this in #2266. |
#1977 includes support for
$schema
along with all of the other JSON Schema keywords. This is really important for being able to experiment with things like new code gen vocabularies or using Hyper-Schema and OAS together, but we'll want to put some boundaries on it. We don't want people thinking they can just shove anything in there and expect tooling to support it.I opened PR #2016 primarily to have something concrete to reference for this.
TL;DR:
exclusive*
).x-
? Requiring this would mean that the standard JSON Schema meta-schemas cannot be used, even though they are compatible, which would seem to defeat the purpose of JSON Schema compatibilityx-
prefixes? Examples would be hyper-schema and some future hypothetical code generation vocabulary that might get designed outside of OAS.Default
$schema
valueI used
https://spec.openapis.org/oas/3.1/meta/validation/2019-10
as a placeholder URI for what I think the default Schema Object meta-schema should be. This meta-schema declares that all of the JSON Schema Core and Validation semantics are present, with the same level of requirement as the standardhttps://json-schema.org/draft/2019-09/schema
meta-schema (everything except the Format vocabulary is required, while support forformat
is somewhat best effort- as far as I can tell, that matches how OpenAPI managesformat
).The meta-schema also requires support for OpenAPI extension keywords, and compatibility syntax for
exclusiveMinimum
andexclusiveMaximum
. It uses a somewhat tweaked version of the standard validation meta-schema plus a meta-schema for the extensions in order for this to work. It also enforces that the only extension keywords allowed must start withx-
.OpenAPI should define this as its default for
$schema
(as a special-purpose implementation, it can determine its own default assumptions.Possible alternate values
The standard core/validation meta-schema
To facilitate interoperability with regular JSON Schema implementations, we should allow the standard
https://json-schema.org/draft/2019-09/schema
meta-schema. As it declares strictly a subset of the keyword semantics and syntax declared by the OAS Schema object meta-schema, this should work just fine.The only exception to compatibility is that it does not forbid unknown keywords that start with something other than
x-
. I think it is fine for us to document that just because a meta-schema does not enforce that restriction, that does not mean that OpenAPI implementations must suddenly support non-x-
-prefixed extension keywords.The standard hyper-schema meta-schema
If we want to encourage experimentation with Hyper-Schema, we should also allow
https://json-schema.org/draft/2019-09/hyper-schema
. Of course, that introduces two additional non-x-
-prefixed keywords,links
andbase
. This is where things get interesting.If we want to have a strict adherence to the
x-
policy, then that would mean that in order to use Hyper-Schema, its vocabulary should be added to the default Schema Object meta-schema (probably with valuefalse
indicating that tools can decide to process the schema even if they do not understand Hyper-Schema- Hyper-Schema is safe for tools that don't care about it to ignore).OR, we could say that only keywords that are defined outside of the JSON Schema vocabulary concept need to be prefixed with
x-
. So any keyword with semantics defined by a vocabulary referenced in the meta-schema's$vocabulary
object would be allowable. Only keywords that do not have formally defined semantics need anx-
prefix. I assume thex-
prefix was designed to avoid future name clashes. The$vocabulary
system reduces the need for that somewhat, I think.Future code-gen or other vocabularies
The main reason I wanted to bring up this idea of allowing keywords from defined vocabularies to not be prefixed with
x-
is that one of the goals of updating to2019-09
is to allow using the vocabulary concept to facilitate use cases like code generation.This is something for which there is substantial demand both inside and outside of the OpenAPI ecosystem. If a new vocabulary is developed for this outside of OpenAPI, then it will not have
x-
-prefixed keywords. It would seem to me to be important to allow tools to add support for such a vocabulary without forcing the existence of a parallel vocabulary with all of the keywords renamed withx-
prefixes.Vocabulary-based compatibility
One of the key reasons for separating vocabularies and meta-schemas is that new/unknown meta-schemas are expected to be far more common than new/unknown vocabularies.
So, defining what is allowable in
$schema
based on the vocabulary set is the most flexible option. In this approach, any meta-schema declaring a subset of the vocabularies inhttps://spec.openapis.org/oas/3.1/meta/validation/2019-10
would be allowed (which would include the standard core/validation meta-schema).The question would again be whether additional vocabularies that do not contradict those declared in
https://spec.openapis.org/oas/3.1/meta/validation/2019-10
would also be allowed, even though their keywords do not start withx-
(for example, Hyper-Schema, or a code gen vocabulary). A good option might be to say that they are, but only if they are declared withfalse
(meaning that tooling can safely ignore them if it is not designed to work with them).This exact scenario is why the
true
/false
vocabulary declarations exist: we did not want to force all tooling to understand irrelevant vocabularies that do not impact validation outcomes.The text was updated successfully, but these errors were encountered: