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

YAML Fragment as alias nodes. #41 #47

Merged
merged 13 commits into from
Jun 20, 2022
Merged

YAML Fragment as alias nodes. #41 #47

merged 13 commits into from
Jun 20, 2022

Conversation

ioggstream
Copy link
Collaborator

@ioggstream ioggstream commented May 25, 2022

This PR

Arose from discussing with @cabo and @eemeli and supports different fragment identifiers:

  • YAML alias nodes starting with *
  • JSON Pointers starting with /
  • empty fragment identifiers
  • JSON pointers can only point to data that is reachable on a path through string-keyed maps and arrays.
  • YAML document tree resolution

This mechanism should be easily extensible to jsonpath (which according to the current I-D must start with a $).

@ioggstream ioggstream requested review from eemeli and dret May 25, 2022 23:34
@ioggstream
Copy link
Collaborator Author

@cabo WDYT of this text?

@ioggstream ioggstream marked this pull request as draft May 25, 2022 23:36
@eemeli
Copy link
Collaborator

eemeli commented May 26, 2022

Is there existing prior art using / as a fragment identifier prefix for JSON pointers? I'm a bit concerned that this might be an application/yaml specific thing, rather than common practice.

@ioggstream
Copy link
Collaborator Author

@eemeli iiuc JSON Pointers must start with /.

   The ABNF syntax of a JSON Pointer is:

      json-pointer    = *( "/" reference-token )

pinging @mnot for a check

@cabo
Copy link
Contributor

cabo commented May 26, 2022

@eemeli iiuc JSON Pointers must start with /.

... or be empty (* is 0 or more).
I think you should make up your mind about empty fragment identifiers and possibly define them as a synonym for an empty JSON pointer (i.e., root value of the JSON tree). See also Section 6 of RFC 6901 , the actual fragment identifier representation.

All non-empty JSON pointers indeed start with a /. So you don't need to add a marker; just pass any fragment identifier starting with a / to the JSON pointer machinery.

The semantics of JSON pointers as defined in Section 4 of RFC 6901 unsurprisingly do not discuss YAML data that are not JSON data. I would simply leave it at that -- JSON pointers can only point to data that is reachable on a path through string-keyed maps and arrays.

We use JSON pointers in SDF. Nobody considered this to be an innovation of any kind, so I'd expect the perception that they are widespread as fragment identifiers to be widespread.

Copy link
Collaborator

@eemeli eemeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the general idea; not in a position to deeply consider the exact wording just now, or for the next week or so.

Co-authored-by: cabo <cabo@tzi.org>
@ioggstream
Copy link
Collaborator Author

About empty fragment identifiers

Are they used in the wild is association with yaml (e.g. in OpenAPI?) cc: @dret could you make a brief investigation on that?

Since the empty `` fragment identifier in JSON Pointer references the whole document, this seems a reasonable
general behavior for any document that represent structured data so we could define that separately.

About using JSON-* fragment identifiers with YAML

JSON pointers can only point to data that is reachable on a path through string-keyed maps and arrays.

This needs to be addressed better.

Notes

@cabo @eemeli do you think there's interest for an extension of JSONPath/JSONPointer to better cover the YAML specifications? Sincerely I don't know how to do it, but since there's some interest in the YAML world for defining pathlike alias nodes, maybe a discussion could be useful.

@dret
Copy link
Collaborator

dret commented May 26, 2022 via email

@ioggstream
Copy link
Collaborator Author

not sure i can help here. but we could ask to... [one of the fantastic friends of Erik]

That's exactly what I meant :P Let's wait for feedback.

@jdesrosiers
Copy link
Contributor

Are they used in the wild is association with yaml (e.g. in OpenAPI?)

Empty fragment identifiers are used in JSON Schema for recursive references. For example, this schema modeling a family tree.

type: object,
properties:
  name: 
    type: string
  children:
    $ref: '#'
required:
  - name

@ioggstream
Copy link
Collaborator Author

@jdesrosiers in this case it is a "full" JSON Pointer, right? Should it resolve to openapi.yaml# or is it processed directly on the parsed JSON document?

@jdesrosiers
Copy link
Contributor

@ioggstream If this schema we part of an OpenAPI document, then yes, the reference would resolve to root of the document. So, in an OpenAPI document, an empty fragment reference never makes sense. You would only do this in a JSON Schema document, which are often written in YAML. In OpenAPI, it would look like this,

components:
  schemas:
    Person:
      type: object,
      properties:
        name: 
          type: string
        children:
          $ref: '#/components/Person'
      required:
        - name

@handrews
Copy link
Collaborator

handrews commented Jun 8, 2022

@ioggstream

in this case it is a "full" JSON Pointer, right? Should it resolve to openapi.yaml# or is it processed directly on the parsed JSON document?

Both "" (the empty string) and "/" (a single forward slash) are normal JSON Pointers and fully usable in fragments the same way as any other JSON Pointer.

@eemeli

Is there existing prior art using / as a fragment identifier prefix for JSON pointers? I'm a bit concerned that this might be an application/yaml specific thing, rather than common practice.

JSON Schema has done this since the beginning. A fragment that is empty or starts with a '/' is parsed as a JSON Pointer fragment per RFC 6901. Any other fragment is parsed as a plain name fragment, which (as we follow that linked document's recommendations and use the NCName syntax) cannot start with a /.

@cabo
Copy link
Contributor

cabo commented Jun 9, 2022 via email

Co-authored-by: cabo <cabo@tzi.org>
ioggstream and others added 2 commits June 20, 2022 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

YAML fragment: is switching from named anchor to alias nodes seamles?
7 participants