Skip to content

Allow "$ref" to take a schema, to make inlining easier? #779

Closed
@handrews

Description

@handrews

[EDIT: See better problem statement two comments below]

Now that $ref can have adjacent keywords, dereferencing/inlining is more complex. (for the purpose of this issue, we're just talking about situations where inlining is possible, e.g. no cyclic references- inlining such use cases is common, with numerous libraries dedicated to this operation).

In informal discussions, we've recommended replacing $ref with an allOf containing just the referenced schema, OR if there is already an adjacent allOf, appending the referenced schema to that allOf. This is rather cumbersome.

At the same time, we use runtime JSON Pointer-ish constructs that look like /properties/foo/$ref/properties/bar/$ref, etc., to record the runtime path as we traverse references.

What if we allowed replacing the $ref URI with the target schema? e.g. if {"$ref": "A"} points to {A}, then it can be replaced with {"$ref": {A}}

$ref here is effectively a no-op, it just allows inlining the target without having to re-arrange the context.

Pros:

  • It's much easier to explain
  • It matches how we report runtime paths even when not dereferenced
  • We're already changing $ref inlining, so now is the time to sort this out

Cons:

  • It's a change
  • Strongly typed languages may be unhappy about the string-or-object behavior
  • ???

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions