-
Notifications
You must be signed in to change notification settings - Fork 4
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
Define fragment identifier specifications for OAS / Schema #2
Comments
This might be tricky for OAS 3.1. Prior to 3.1, it's pretty straightforward, fragments are JSON Pointers (RFC 6901). But, 3.1 adopts all of JSON Schema which means plain name fragments are allowed as well. But, how plain name fragments are defined depends on which JSON Schema draft is used. |
We might want to limit fragment identifiers in an OpenAPI document to be only OpenAPI objects. So you could reference |
References need to be able to point to sub-schemas because they can in JSON Schema and there are JSON Schemas in OpenAPI documents. I think this document just needs to define how to identify a location. It can defer to the specific OAS/JSONSchema version to determine whether a reference to that particular location makes sense or is allowed. |
This may be a bad assumption: The JSON media type registration does not provide for fragments. It's more of an opportunity than a problem; simply stipulate that rfc6901: JSON Pointer be applied the same for YAML as it would be for JSON. The inclusion of support for plain names could be considered as well. When +yaml is used for an object of type |
Per @darrelmiller
And per @jdesrosiers
For Openapi 3.1 and forward, we ought to be able to reference independently managed JSON Schemas, not just OpenAPI specs. And if the JSON Schema rules apply to OpenAPI documents, shouldn't they be able to reference anywhere in that document? Good practice might dictate a narrower set of patterns, but I'd hope to not create new one-off rules for OpenAPI; the move to JSON Schema was to take on its advantages, right? |
@cjaccino as of now
Sure: this should be addressed in |
@jdesrosiers @darrelmiller WRT Fragment identifiers, IIUC
Is that correct? |
That's not correct. Consider this example located at components:
schemas:
foo:
$anchor: foo
type: string
bar:
$ref: '#foo'
minLength: 3 In this example, |
I think that "Plain names" cannot be easily supported unless the media type is explicitly declared as "application/schema+" or "application/openapi+". This means that an application producing an |
@jdesrosiers This example you show worries me. Promoting JSON Schema anchors to root level names in an OpenAPI document seems like a big risk to OpenAPI being able to introduce new keywords in the future. |
@darrelmiller how are URI fragment and keyword namespaces related? |
@handrews OAS Reference objects can use OAS keywords as part of their URI fragment
Having read a bit more about the allowed values in $anchor members, it does appear that we could disambiguate between these anchors and JSON Pointers into OAS documents. However, it is concerning that JSON schema is effectively taking ownership of a big chunk of the OAS URI fragment space. |
@darrelmiller A fragment is always either unambiguously a JSON Pointer fragment (which MUST either be the empty string or start with a JSON Schema's plain name fragments are derived from the WC3's Best Practices for Fragment Identifiers and Media Type Definitions, specifically:
and
JSON Schema uses the NCName production as it seemed like a reasonable one, particularly back when it was common for APIs to offer both JSON and XML representations (which I'm sure some still do). So completely aside from JSON Schema, it would make sense for OpenAPI to support plain name fragments. I guess my question is, what else would you want to do with fragments that would match the plain name / NCName syntax? There's no reason that plain name fragments couldn't be created by some part of OAS other than JSON Schema as well. There is always the possibility of defining the same fragid multiple times within the same resource, which would be a little more likely if some aspect of OAS automatically creates fragids. But it's entirely possible already (and also possible in HTML and any number of other media types). Plus, if you really need a 3rd type of fragid, there are many ways to design a syntax that wouldn't conflict with either JSON Pointer fragments or plain name fragments. |
Ok. I think that in this case though, this approach can be problematic since JSON Schema can be referenced inside documents of other formats. I think that OAS / JSON Schema folks should deep dive on that, if you haven't already planned it. Moreover, if one day you may decide to dismiss plain names (e.g. maybe you decide to use something like
But... with which format? For example, OAS could decide to use FYI for YAML the current setup:
My proposal for now is just to delegate the fragment processing to the relevant specs: this means that the implementation needs to identify the specific media type (e.g. OAS version, JSchema version) before processing. I think that it's a quite high price for supporting plain names, but that's up to you. I just hope this wouldn't delay the registration too much :) |
JSON Schema allows embedding multiple resources in a document (JSON Schema or otherwise) based on the presence of This is possible in OpenAPI 3.1 (the first OAS version that supports JSON Schema's If your schema objects don't set a |
It would be entirely reasonable for OAS to warn that using |
I had assumed that each JSON Schema is treated as its own "schema resource", and therefore cannot be referenced as you suggest. Can you point to anything in the spec which supports your understanding? |
My issue here is, if you did allow such a thing, you would be making any schema bundling process potentially create different validation results. What happens if |
How is this discussion relevant for the YAML fragment identifier syntax? |
@Relequestual it's in the explanation of base URIs. The OAS document isn't a bundle, unless schema objects use
It's exactly the same as if OAS's In any media type that allows document authors to define anchors, it's possible to define the same anchor twice. People do it in HTML all the time (to the continual irritation of QA departments everywhere trying to write automation using anchors as stable references).
OAS can be written in JSON or YAML and essentially imports JSON Schema's fragment behavior. Although plain name fragments an only be defined within schema objects (using None of that imposes constraints on |
@darrelmiller, were your concerns get adequately addressed?
The way I see it, the OAS media-type should just define that plain-name fragments identify a named location in the document. They don't identify a schema, just a location. What is expected at that location depends on the context. JSON Schema defines the If OAS wants to introduce additional fragment types, there are many characters that aren't allowed in plain-name fragments that can be used for disambiguation such as using "$" for JSON Path. |
OK to summarize here for the OpenAPI media types only only (all applies to both
Objections that the above is not a good idea in some way are, at this point, fairly irrelevant. OAS 3.1 has been out for more than three years now, and this is how it works. OAS 3.1.1 will come out this year and clarify the referencing and identification behavior in the 3.1 line. |
It's also worth noting that OAS 4 (a.k.a. moonwalk) will likely have a different approach to fragments, or at least have component-name-based plain name fragments or other JSON Pointer-alternative syntax. |
I don't see the problem here for So if we're bound by
So I don't see the problem. I don't expect parsers of |
Briefly:
This means that: With openapi+* and schema+* we can decide whatever we like |
@ioggstream thanks! OK so I just misread where the difficulties are, and since we are defining |
I expect
The text was updated successfully, but these errors were encountered: