JRef from an AsyncAPI perspective
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- backend-api-design
Research direction
Start by reading issue #14 and the referenced discussion in referencing issue #7, then compare the JRef behavior described here with AsyncAPI's reference requirements. Done would require a decided direction for how AsyncAPI should handle media types, embedded schemas, and nested references, rather than an isolated code change.
Written by the indexing model from the issue text.
Description
This is a response to #14. By request, I'm responding here so we can fork the discussion for JRef specific discussion.
Here's how I see that JRef applies to your requirements for AsyncAPI. I hope it's helpful.
- Should always produce a valid JSON document (resolving referenced resource should always be compatible with JSON)
In JRef, references are always transparent. Developers are always working only with the standard JSON types. When you get a value from a JRef document, the JRef tooling follows the reference automatically and gives you the referenced value as if the referenced value was always there.
Example
const doc = JRef.load({
"foo": { "$href": "#/bar" },
"bar": "42"
});
const foo = JRef.get("/foo", doc); // => 42
const bar = JRef.get("/bar", doc); // => 42
- Should define the behavior for referencing non-JSON resources in a JSON document (this can be as simple as resolving the content into a string value)
JRef allows implementations to define how they want non-JSON values to be represented. Everything is based on media types. You can have XML converted into a JRef compatible document, or just return it as a string. You would write a plugin for the JRef tooling describing the behavior you expect for each media type.
Example:
const doc = JRef.load({
"schema": { "$href": "./my-xml-schema.xml" }
});
const xmlSchema = JRef.get("/schema", doc); // => Some representation of an XML document
const value = XML.get(someXPathExpression, xmlSchema); // => The value of applying the XPath expression to the XML document
- Should define the behavior for referencing JSON data
The JRef proposal covers the behavior of references in JRef documents. Although JRef is syntactically compatible with JSON, it's considered a different media type and must be configured as a plugin the same way you would for XML.
Example
const doc = JRef.load({
"foo": { "$href": "./my-json-document.json" }
});
// ./my-json-document.json
// {
// "aaa": { "$href": "#/bbb" },
// "bbb": 42
// }
const foo = JRef.get("/foo", doc);
const aaa = foo.aaa; // => { "$href": "#/bbb" } # A value that looks like a JRef reference, but is actually just a plain JSON object with no special meaning
const bar = foo.bbb; // => 42
- Should define the behavior for referencing JSON data that also have reference behavior, and how they interconnect / or not (say two standards both use $ref the new standard should define a clear separation between the two and how referencing tools should interpret it)
Every document has a media type and each media type has it's own rules for referencing. If you reference a JSON Schema from a JRef document, once you follow that reference, then only the rules for JSON Schema apply. Because it's document based, there are some consequences to be aware of. If your AsyncAPI document identifies as a JRef media type, you can't embed a JSON Schema in that document because it's a different media type. You can only reference to a JSON Schema. That shouldn't be a big deal because it's what you already have to do for non-JSON compatible types already.
One way around that is to define AsyncAPI as a separate media type that defines that certain locations are to be interpreted as JSON Schemas. Then it can be a reference or inline. But, that would require extra work to extend the standard JRef tooling.
Another way around that is to introduce some syntax for embedding external documents in a JRef document. I've explained why an embedding/bundling feature is not included in https://github.com/json-schema-org/referencing/issues/7, but I'm open to discussion if there's demand for it.
If both AsyncAPI and JSON Schema decide to adopt JRef, this problem goes away, but I don't think that's likely from the JSON Schema side.
- Should define the behavior of nested schemas within the same file (so there is no difference between what the spec allows and what tooling enables)
JRef doesn't restrict where a reference can be or what can be referenced. Because the tooling abstracts away references, there should be no developer burden and AsyncAPI document authors are empowered to use references however fits their needs. If AsyncAPI does want to make restrictions like this, they would need to define their own media type and would have to extend the standard tooling.
- Dominant language
- Makefile
- Stars
- 9
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from json-schema-org/referencing
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
json-schema-org/referencing#17 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
json-schema-org/referencing#15 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
json-schema-org/referencing#14 · 9 comments ·
-
jri security
json-schema-org/referencing#13 · 1 assignee ·
-
jri
Difficulty 5/5 Over a week Newbie friendliness 20/100
All issues in json-schema-org/referencing
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-api#45 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·