Skip to content

fail finalize with a default that isn't allowed by its schema - #77

Merged
ahl merged 8 commits into
mainfrom
newtype-default-constraints
Nov 23, 2026
Merged

ahl merged 8 commits into
mainfrom
newtype-default-constraints

Conversation

@ahl

@ahl ahl commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

ahl added 8 commits November 22, 2026 14:58
A property default on a constrained newtype is constructed directly in
the generated defaults:: function, so a value the newtype's TryFrom would
refuse is accepted at finalize and baked into the output. The test
expects Error::InvalidDefault instead and fails until the check lands.
A default on a constrained newtype is constructed directly in the
generated code, so nothing applied the newtype's constraints to it: a
value the newtype's TryFrom would refuse finalized and rendered. The
default walk checks the value as it passes each newtype, through
NewtypeConstraints::check_value beside the rendering it matches, and
reports a violation as InvalidDefault. A float constraint compares in
the inner type's precision; a list compares numbers by value. An allow
or deny list of structs and a JSON schema constraint are not matched
exactly, which the method's doc states. A pattern that does not compile
is an InvalidConstraints error whether or not a default uses it.

regress becomes a library dependency; the check compiles patterns.

The known_gaps test moves to render.rs as two passing tests over every
constraint kind and a whole-type default, plus one for the pattern
error.
The schema is compiled once in check_constraints, so one that does not
compile is refused there as InvalidConstraints, and check_value validates
the default as written against it under the draft the rendered check
uses. jsonschema moves from a dev-dependency to a dependency.
@ahl
ahl merged commit 4e6235f into main Nov 23, 2026
10 checks passed
@ahl
ahl deleted the newtype-default-constraints branch November 23, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant