Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 4c3b7e8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A JSON Schema export describes only the last encoding of a codec. When a transformation along the way can reject encoded values, or drops checks on its decoded side, the exported schema accepts more than the codec, so oneOf unions must fall back to anyOf. Links are treated as exact only when they are on an internal allowlist of total links: the primitive JSON lowerings, Class constructors, Option/ReadonlyMap/ReadonlySet codecs and decoding defaults.
…route A decoding default is total only when it is a successful Exit whose value decodes through the schema it fills. The check runs lazily, the first time the JSON Schema export inspects the link, so suspended schemas still work. SchemaRepresentation.toRepresentation now always records approximate encoded sides, so the public representation route exports the same JSON Schema as Schema.toJsonSchemaDocument.
tim-smart
force-pushed
the
agent/nelson/aee60a6d5f8c
branch
from
October 29, 2026 22:34
8fee1f7 to
60ed00e
Compare
This branch has not been deployed
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.
Stacked on #10079. Retarget once that PR merges.
Problem
Schema.toJsonSchemaDocumentexports only the last encoding of a codec. If a transformation on the way can reject encoded values (Date,URL,DateFromString,NumberFromString, ...), drops checks on its decoded side (Date.check(...),Number.check(isGreaterThan(0))), or uses a decoding default that fails or doesn't decode, the exported schema accepts more than the codec does. The exporter still treated it as exact, so aoneOfwhose branch encodings overlap rejected values the codec accepts.Change
toRepresentationmarks a representation with"~approximateJson": truewhen it is reached through an encoding chain that isn't exact. A chain is exact when every link is total, keeps the checks of its decoded side, and every codec nested in a decoded side is exact too. The nested rule coversOption(NumberFromString)and a decoding default overNumberFromString.$refcan't carry the marker, so an approximate use of a shared definition marks the definition. That can only downgrade a union toanyOf.toRepresentation,SchemaRepresentation.toJsonSchemaDocument(SchemaRepresentation.toRepresentation(...))gives the same result asSchema.toJsonSchemaDocument.SchemaAST.total(link, predicate?)/isTotal, backed by aWeakMap. It covers:numberToJson,undefinedToNull, bigint/symbol/literal links,unknownToJson,objectKeywordToJson);Classconstructor links;Option,ReadonlyMapandReadonlySet;withDecodingDefaultandwithDecodingDefaultKey. These are total only when the default is a successfulExitwhose value decodes through the schema it fills. That check runs lazily, on first inspection, so suspended schemas still work.mapLinkkeeps the mark when the codec derivation re-encodes a link's target.decodeToand passthroughs. Declarations without a JSON codec lower through a partialopaqueToJsonlink, so their{}export is approximate too.Compatibility
"~approximateJson"annotation. That updates 8 expectations intoRepresentation.test.ts/toRepresentations.test.ts. The key is excluded from code generation and JSON Schema annotations.Tests
The regressions from the two test commits now pass. A table test checks that
Class,Optionand decoding defaults keeponeOf, and that nested partial codecs and droppedNumberchecks switch toanyOf.Closes EFF-3104