Skip to content

Add core identifier and reference keywords #39

Description

@crmne

Goal

Add support for Draft 2020-12 core identifier and reference keywords:

  • $id
  • $anchor
  • $comment
  • $dynamicAnchor
  • $dynamicRef
  • $vocabulary

The gem already emits $defs and $ref.

Meanings

$id gives a schema or subschema a URI identity.

$anchor creates a named local reference target.

$comment is a schema-author comment.

$dynamicAnchor and $dynamicRef are advanced keywords for recursive and dynamic reference behavior.

$vocabulary declares which JSON Schema vocabularies the schema uses.

Proposed DSL

At the root level:

id "https://example.com/schemas/person"
anchor "person"
comment "Internal note"
dynamic_anchor "node"
dynamic_ref "#node"

Inside nested schemas, these should follow the same current-node modifier direction as #40 where the keyword is valid for that schema node:

define :address do
  anchor "address"
  comment "Reusable address schema"

  string :street
  string :city
end

object :node do
  dynamic_anchor "node"

  string :value
  object :child, of: :node
end

Design notes

  • $comment is informational and similar in feel to metadata annotations, but it belongs to the JSON Schema core vocabulary rather than the annotation vocabulary tracked in Add metadata annotation keywords #40.
  • Identifier/reference methods should configure the enclosing/current schema node when used inside a schema block.
  • Dynamic references need documented semantics before implementation, especially around recursive schemas and $defs.

Acceptance criteria

  • Root schemas can declare $id.
  • Subschemas can declare anchors where appropriate.
  • Core identifier/comment methods work as current-node modifiers inside supported nested schema blocks.
  • Dynamic references have documented behavior before implementation.
  • Generated schemas validate against Draft 2020-12.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions