-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
[2.0.0 REVIEW] Clarify usage of JSON References (/Pointers) for non-JSON data structures #216
Comments
Yes. This needs to be revised. Thanks for pointing out, Jonathan! |
Deleted all the comments to add "jstoiko", "vromero", and "antoniogarrote" as contributors. To remove noise on this thread. |
Ok, so I've done some initial research on the subject and here's the result. JSON Pointer examples to consider (from RFC 6901)Given the following JSON object: {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
} These are the results for each JSON Pointer:
Following, we're going to apply the same JSON Pointers to a Protobuf file and an XSD file, and see what the result should be. ProtobufWhen using Protobuf, the JSON Pointer MUST point to either a package my.org;
enum MyEnum {
UNKNOWN = 0;
STARTED = 1;
RUNNING = 2;
}
message Outer {
message Inner {
int test = 1;
}
MyEnum enum_field = 9;
} Alternative 1: Using JSON Pointer syntax
Alternative 2: Following Protobuf syntax (not JSON Pointer-compatible as it's lacking the initial
|
Added the following to the initial research: Alternative 2: Following Protobuf syntax (not JSON Pointer-compatible as it's lacking the initial
|
Even though it's possible to hack the JSON Reference object to make it work with non-JSON structures, I'm not quite happy as —in the end— it's a hack. And honestly, I don't like hacks and even less in formal documents like a specification. My gut feeling is telling me so much to stop here and support only JSON/YAML formats but my UX background is holding me hard from abandoning the XSD and Protobuf use cases. In any case, it looks like this requires further investigation and discussion and I don't think it would make it to version 2.0.0 as it is. Therefore, I think @jstoiko proposal of limiting it to JSON/YAML formats is what makes more sense. At least for now. Support for XSD and Protobuf can be brought through tooling that will transform these formats into their JSON Schema equivalent. |
But this shouldn't stop us from keep working on defining support for non-JSON schemas. |
Reopening this issue so we can work on it in the future. |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
🎉 This issue has been resolved in version 1.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
@jstoiko @WaleedAshraf @fmvilas
The described proposal/problem itself is related to my proposal, which I extended to use references to nested non-JSON schema objects - Proposal to allow defining schema format other than default one (AsyncAPI Schema) - please see section Any feedback are more than welcome! :) |
I found this in spec: This issue was specified long time ago. Ok this spec there is contractionary with: Because JSON Reference don't allow refences to external files this way. |
Since the introduction of the Multiformat Schema Object, we already support protobuf for instance. In the docs, we mention the following:
I consider this issue can be closed. In case you still believe it should be kept open, please mention it and I will proceed. |
I am not sure. The feature. $ref or similar to *.proto files is still open and was planned as a 3.1 feature. |
@GreenRover would you mind pasting here any link related to the planned feature? Thanks! |
The introduction of
schemaFormat
in Message Object adds support for schema languages other than JSON Schema. The$ref
erencing mechanism however was designed to only support JSON data structures as it explicitly mentions the JSON Reference mechanism. So this needs additional clarification.To be clear, any schema languages which underlying format is JSON (E.g. Avro) is not of concern. Schema languages which underlying format is YAML (E.g. RAML DataType, OpenAPI in YAML) are of lesser concern because simple wording could be added to the effect that a JSON Reference can be made to the JSON-equivalent of the YAML-formatted schema.
One could always “come-up” with some meaning around what comes after
#
for non-JSON formatted schemas. However, the lack of explicit definition of what it means to use a JSON Reference/Pointer to refer to non-JSON data structures would leave things up to interpretation, and as a result may introduce a divergence of behaviors across tools supporting the AsyncAPI Spec.Let’s take Protobuf for example. What happens when there are nested types and I want to refer to a type within a nesting?
E.g.
How do I refer to
Bar
? Is itFoo.proto#/Foo/Bar
orFoo.proto#/Foo.Bar
? The former looks more “right” to me, however one could make a case thatFoo.Bar
is how one would refer to Bar from within Protobuf and therefor is the way it should be referred to in the Pointer. Since a Protobuff document is not a JSON data structure, there is nothing to contradict this argument.It would be interesting to take protobuff and maybe one more -- say XSD -- and think of all the corner cases, probably by going over the JSON Reference and JSON Pointer specs and attempt to apply each rule to both schema language. If any of those rules are contentious or may leave room for interpretation, then we should think of some wording to add to the AsyncAPI 2.0 spec. Another solution could be to have some kind of registry or mini-spec for each schema languages and have the rules defined there.
IMO, a much (much!) simpler -- and arguably better -- solution would be to restrict the use of JSON Reference to JSON and YAML -formatted schemas. We would say something along the lines of:
To sum-up:
$ref
can be applied to YAML data structuresThe text was updated successfully, but these errors were encountered: