format: tighten type and context validation constraints - #279
Open
gnidan wants to merge 1 commit into
Open
Conversation
Six constraint fixes from the schema sweep, each closing a case where an
invalid instance validated (or a valid one could not be expressed):
- type/elementary: the canonical elementary schemas never forbade a
`contains` field, so e.g. {kind: bool, contains: ...} validated as an
elementary type while the same object was a *complex* type under
type/base — breaking the elementary-vs-complex discriminator. Elementary
types now reject `contains`, matching type/base.
- type/complex/function: alone among the complex types it had no top-level
`required: [kind, contains]`, so {external: true} validated as a
function. Now required.
- type/complex/function: `parameters` (and the external `contract`) were
pinned to a concrete type, so they could not be given as an { id }
reference even though `returns` and the wrapper machinery allow it. Both
now accept a type reference.
- type/elementary/contract: `library` and `interface` were only
constrained inside the oneOf consts, so {library: true, interface: 42}
passed. Both are now typed `boolean` at the top level.
- program/context/name: `name` was a bare string, so `name: ""`
validated; it now carries minLength: 1, matching the identifier-like
strings elsewhere in the context family.
- pointer/region: the location dispatcher's `if` clauses omitted
`required: [location]`, so a location-less object vacuously satisfied
all seven branches and was rejected only by accident (with errors
implicating every region type). `location` is now required at the top
level, and each `if` guards on it, so a missing location yields one
clear error.
Contributor
|
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.
This PR closes six validation gaps found in the schema sweep. Each is a case where an invalid instance validated, or a legitimate one could not be expressed. All existing schema examples still validate, and I verified each fix against its offending instance.
contains. The canonical elementary schemas never forbade acontainsfield, so{ kind: bool, contains: { type: { id: 1 } } }validated as an elementary type — while the very same object is a complex type undertype/base. That breaks the elementary-vs-complex discriminator the format relies on. Elementary types now rejectcontains, matchingtype/base.kindandcontains.functionwas the only one of the six complex-type schemas without a top-levelrequired: [kind, contains], so{ external: true }alone validated as a function and{ kind: function, internal: true }(nocontains) validated through the whole canonical type chain. Now required.parameters/contractby reference. TheParameterswrapper (and the externalcontractwrapper) pinnedtypeto a concrete type, so neither could be given as an{ id }reference — even thoughreturnsin the same file already permits one and the wrapper/specifier machinery exists precisely to allow it. Both now accept a type reference.libraryandinterfacewere constrained only inside theoneOfconsts, so a nonsense value on the non-discriminating flag slipped through:{ kind: contract, library: true, interface: 42 }validated. Both are nowtype: booleanat the top level.nameis meant to identify a context, but it was a baretype: string, soname: ""validated. It now carriesminLength: 1, matching the identifier-like strings elsewhere in the context family.location. The location dispatcher's sevenifclauses omittedrequired: [location], so an object with nolocationvacuously satisfied all seven and was rejected only by accident — with validator errors implicating every region type at once.locationis now required at the top level (the change that actually rejects a location-less region), and eachifguards on it so a missing location produces one clear error instead of seven.Schema example and validity tests pass.