-
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
What is the rationale behind allowing YAML alias nodes as fragment ids? #72
Comments
Hi @MikeRalphson! We had a long discussion on this topic. See #47 Shortly:
you mean anchor names are not preserved, right? That's right, and this is highlighted here
Can you please clarify with a little example? Let us know, R. |
Hi @ioggstream thanks for the welcome.
Correct.
This is getting a bit implementation-specific but using @eemeli's function parseWithAliases(str) {
const aliases = new Map();
const ast = yaml.parseDocument(str);
const walker = new AList(ast); // fast recurse through every object in the AST
for (let [value,metadata] of walker) {
if (yaml.isAlias(value)) {
aliases.set(value.source,value.resolve(ast));
}
}
return { data: ast.toJS(), aliases };
} which, given the following input: hello: &a
world:
message: Hello, world
outputs:
*a gives the following output: {
hello: { world: { message: 'Hello, world' } },
outputs: { world: { message: 'Hello, world' } }
} where Map(1) {
'a' => YAMLMap {
items: [
Pair {
key: Scalar {
value: 'world',
range: [ 13, 18, 18 ],
source: 'world',
type: 'PLAIN'
},
value: YAMLMap {
items: [
Pair {
key: Scalar {
value: 'message',
range: [ 24, 31, 31 ],
source: 'message',
type: 'PLAIN'
},
value: Scalar {
value: 'Hello, world',
range: [ 33, 45, 46 ],
source: 'Hello, world',
type: 'PLAIN'
}
}
],
range: [ 24, 46, 46 ]
}
}
],
range: [ 13, 46, 46 ],
anchor: 'a'
}
} As you can maybe see, the problem is the metadata available about the YAML aliases still refers to objects within the AST, and doesn't share any objects with the output JS object. If what I consider the best Javascript YAML library doesn't provide this functionality (or I can't find it) and many other YAML parsers don't even have an abstraction above the output native object, then where is the universal utility in allowing YAML aliases as fragments? |
wrt the codeLet me check if I understand the issue, and please (cc: @eemeli @perlpunk) correct me if I didn't get it:
Note: even using JSON Pointers on YAML (e.g. # what.yaml
what: &a
a: &wonderful
world: *a I hope I didn't miss the point though (it's midnight now in Italy, after all) I think @eemeli / @perlpunk can provide some insight. I am happy to extend the security/interoperability considerations sections! wrt the specHere I will share my 2¢ that go a bit beyond current implementations: I think we tried to create a common discussion ground between different communities (YAML, JSON, OAS, ...). on OAS:
on YAML:
Thanks for reading this long answer! |
@ioggstream thanks for providing the long answer!
Would love to know where this sentence was going to end up. By guidance, do you mean fragment id resolution rules are optional or non-normative? |
My understanding of where we ended up is that for To me, this strikes the right balance for compatibility. If you're working with Now, as for e.g. my JS import { Alias, parseDocument } from 'yaml'
const doc = parseDocument(`
hello: &a
world:
message: Hello, world
outputs:
*a
`)
new Alias('a').resolve(doc).toJSON()
// { world: { message: 'Hello, world' } } To be fair, this only sort of works, as any further aliases within the resolved tree are not properly resolved, and duplicated aliases do not behave as specified for |
Thanks @eemeli! Do you want me to raise an issue on |
If you could, as two separate issues? Already working on the mediatypes/draft-ietf-httpapi-yaml-mediatypes.md Lines 153 to 154 in 0d2cef8
|
@MikeRalphson Can we consider this issue as closed, based on on @eemeli rationale? |
@MikeRalphson thanks for raising this issue, and 👏 to @eemeli for his support. I think that type of exchanges are great for interoperability. 🚀 |
mediatypes/draft-ietf-httpapi-yaml-mediatypes.md
Lines 119 to 124 in 0d2cef8
Again, raising here as suggested by @dret, but please direct me to existing issue/comments.
My concern is one of complexity and tooling support, with regard to parsing YAML to an in-memory object form, often the alias node identifiers are lost (replaced with object identity).
YAML alias nodes effectively exist only in the textual representation of a YAML resource, not the parsed version most applications are likely to be dealing with.
This may mean that for some languages a YAML parser which can output an AST representation of the YAML object tree, or some other mechanism such as an adjacency list may be required.
See #71 for concerns over different subtypes of
application/yaml
having different fragment resolution rules.The text was updated successfully, but these errors were encountered: