Repository navigation
describe/title metadata for toJsonSchema - #24
Merged
Merged
Conversation
describe(text) and title(text) attach JSON Schema metadata via a transparent nkMeta wrapper: validation, parsing, Infer, and round trips are unaffected; nodeToSchema merges the metadata into the emitted schema. Chained calls merge into one wrapper with last-wins semantics, a titled recursive schema names its $defs entry, and the built-in timestamp description becomes overridable. The wrapper is peeled wherever node kinds are inspected: fieldDefOf (alias in either order), strict (re-wrapped after), primKind (coerce chains), isOptionalField (requiredness), and objFields (object algebra).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the last item from the JSON Schema polish list:
describe(text)andtitle(text), chainable type-preserving modifiers that attach metadata emitted bytoJsonSchemaand ignored by everything else:Semantics:
Infer,toJson, and re-validation are unaffected; the cost is one pass-through node.titleanddescribecoexist.$defsentry (#/$defs/TreeNodeinstead of#/$defs/def0), with a uniqueness fallback.timestamp()description becomes overridable.Implementation
One transparent
nkMetanode plus pass-through arms invalidate/normalize/denormalizeand a merge arm innodeToSchema. The subtle part was peeling the wrapper everywhere node kinds are inspected, each now metadata-tolerant and covered by a test:fieldDefOf:aliasworks in either order relative to metadatastrict(): peels, applies strictness, re-wraps (metadata survives)primKind:integer().describe(...).coercestill passes the coerce guardisOptionalField: a describedoptionalfield stays out ofrequiredobjFields:pick/omit/partial/mergesee fields through the wrapperTests
9 new tests (244 total, passing under orc and arc locally). README (modifiers table, JSON Schema section with an LLM tool-definition example, snippets compile-verified) and DESIGN.md updated.