Keep $ref some how when bundle
See original GitHub issueIssue Description
Because $ref offen mean type of something, when render views, need the ref type to select the component.
e.g.
Address.json
{
"type": "object",
"properties": {
"a": {
"type": "string"
}
}
}
User.json
{
"type": "object",
"properties": {
"address": {
"$ref":"Address.json"
}
}
}
If the bundled result is
{
"type": "object",
"properties": {
"address": {
"_ref": "Address.json",
"type": "object",
"properties": {
"a": {
"type": "string"
}
}
}
}
}
Then the frontend can use the "_ref": "Address.json"
to match the component more precisely.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Bundle: option to keep all refs but turn them into internal refs #29
Currently, with no special option, the bundle command inlines all $ref s it finds on the first encounter, and then makes a reference...
Read more >Why some Bundle objects will update by reference and some ...
This is a normal way of passing data to fragments. because of shallow copy, When I change this user object and update its...
Read more >git-bundle Documentation - Git
git-bundle - Move objects and refs by archive ... Then, git bundle prints a list of missing commits, if any. Finally, information about...
Read more >Bundle - Android Developers
Constructs a new, empty Bundle sized to hold the given number of elements. ... Reports whether the bundle contains any parcelled file descriptors....
Read more >Accessing a Bundle's Contents - Apple Developer
Explains how to use bundle objects to organize resources.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JamesMessinger That’s a great catch!
Thinking about it more, I wonder if a simpler and more general-purpose approach might be to avoid setting a property at all, and exposing an
onDereference
hook instead.One possible API:
A consumer might then use this API to build up a mapping:
This approach has a few benefits over the
Symbol
-based approach:Symbol
-based approach is notSymbol
-based approach does not (say, also collecting the original$ref
-containing schemas)onDereference
callback, without breaking clients (not so for theSymbol
-based approach)Author of json-schema-to-typescript here. We’d love this features, as it would unblock a handful of issues related to emitting more intelligent TypeScript types.
As specific example, consider the following JSON Schema:
We’d like to emit the following TypeScript types for this schema:
Today, we accomplish this by always emitting standalone type names (here,
A
andB
) for tuple members. However, this isn’t the right behavior; it would be nice to refine our heuristic, where we look for the presences of$ref
s as a sign that a type is meant to be reused, and therefore, named (we already useid
s andtitle
s for this today).To do that, we’d love a way to know what a schema’s original
$ref
pointed to. Any key name is fine for us, though you might consider using aSymbol
in order to avoid a backwards-incompatible change to this library, and to avoid colliding with existing keys.As a side note: It’s possible to infer something like this today (roughly: traverse over a dereferenced schema and its source schema at the same time, and annotate the dereferenced schema where you see a
$ref
in its source schema). But this is a hack that doesn’t work when a source node is in another file, since$RefParser.resolve(..).get(..)
returns a dereferenced schema, not a source schema.Please let me known if this is not something you’re interested in, and I’ll go ahead and fork
json-schema-ref-parser
so we can patch it in for our use case.