Skip to content

Using JSON Pointer fragments with any valid JSON or YAML document #75

Open
@handrews

Description

@handrews

I'm spinning this issue off from #71 (comment).

There is a recurring problem with JSON Schema, OpenAPI, and particularly AsyncAPI, where representations with a variety of media types, and sometimes without any formal media type (therefore defaulting to application/octet-stream), need to be connected using URIs (or IRIs).

For the purpose of this discussion, assume that any URI mentioned is a full URI, either because it was written as such, or because it was a relative URI-reference that has already been successfully resolved against the appropriate base URI. All of this applies to IRIs as well.

@ioggstream has asserted (and please correct me if I get this wrong) that if:

  1. a URI is present in a document conforming to a specification X (for example, an API description conforming to the OpenAPI Specification)
  2. the non-fragment part of the URI can be resolved to a representation
  3. the specification X mandates interpreting the representation as a media type (e.g. application/openapi+json or application/openapi+yaml) that supports JSON Pointer fragments
  4. the mandated interpretation is successful (e.g. it was parsed into application/openapi+yaml without error)

then:

  1. the original media type (such as application/json, application/yaml, or application/octet-stream), if any (e.g. resolving a file: URI might not come with metadata such as a media type) can be ignored in favor of the re-interpreted media type
  2. the URI's fragment can be interpreted according to the fragment syntax and semantics of the re-interpreted media type, e.g. JSON Pointer

Given this, I have the following queetions:

  1. Does any standard directly support this process and usage?
  2. If not, does any standard (such as RFC 3986 §3.5) forbid it?
  3. If not, can/should we create a standard that explicitly endorses such a process?

Having this process ratified by a standard would allow doing something like this:

  • define application/pointable+json and application/pointable+yaml which are simply application/json and application/yaml with JSON Pointer fragment support
  • having specifications such as OpenAPI and even more notably AsyncAPI, which has to incorporate a wide range of schema formats, not all of which have any defined media type, much less one with fragment support, mandate re-interpreting linked resources that can be parsed as JSON or YAML into these media types so that URIs can use JSON Pointer fragments regardless of the media type associated with the representation by the source of that representation

This would solve a great many problems.

For example, in JSON Hyper-Schema, there is an "anchor" keyword for setting the context URI of a link. Often the context URI only needs to change within the instance, which would normally be done with a same-document reference (typically a fragment-only URI reference).

However, JSON Hyper-Schema has to accommodate application/json instances, which cannot use fragments at all. Therefore I added the "anchorPointer" keyword to separately store a plain-text JSON Pointer to adjust the context separately from the URI in "anchor".

If JSON Hyper-Schema could mandate that, for the purpose of the "anchor" keyword, the instance MUST be interpreted as application/pointable+json, then we could dispense with "anchorPointer" entirely.

While work on JSON Hyper-Schema is tabled and may never resume, this pattern has appeared elsewhere. I'm just too lazy at the moment to figure out a realistic AsyncAPI example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    In Discussion

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions