fix: enforce conditional numeric bounds in generated models - #71
Merged
damaz91 merged 1 commit intoAug 13, 2026
Conversation
damaz91
approved these changes
Aug 13, 2026
4 tasks
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
Restore JSON Schema
if/thennumeric bounds, whichdatamodel-code-generator drops, by injecting a
model_validatoralongside theexisting conditional-
requiredfamily.Motivation
total.jsonconstrainsamountbytype:discount/items_discountmust beexclusiveMaximum: 0, andsubtotal/fulfillment/tax/feemust beminimum: 0. The generatedTotalcarries no validator at all, so:find_conditional_requiredalready handles athenthat adds required fields,but returns early on a
thenthat narrows a range, so this family was nevercovered.
Scope
Mirrors the conditional-
requiredtrio (find_/inject_/_patch_) so bothread the same way. Two differences worth calling out:
allOfscoping. These rules are carried asallOfbranches, which have nosibling
propertiesof their own — the object they constrain is the enclosingschema. The scan therefore threads the enclosing property set into each branch.
A rule is still rejected unless it has a single
const/enumdiscriminator anda
thencontaining only numeric-bound keywords; anything else is skipped with awarning rather than approximated.
total_create_request.jsonstrips everyproperty, so the rule names fields the class does not have. That is inapplicable
rather than malformed, and is skipped silently — otherwise every generation run
would print four spurious warnings.
typeremains an open vocabulary: a value carrying no rule (total, or a vendorvalue) is unconstrained, and a
Noneamount is not checked.Validation
python -m unittest discover -s tests— 77 passed (72 before; 5 new).ruff checkadds no diagnostic outside theD,E501set this repo ignores inpre-commit;
ruff formatclean.Regeneration against the pinned
2026-04-08spec touches onlytotal.pyandtotals.py. Runningpostprocess_models.pya second time leaves the outputbyte-identical.
Behaviour of the generated model, all verified:
type="discount", amount=500type="items_discount", amount=1type="tax", amount=-999type="fee", amount=-1type="discount", amount=-500type="tax", amount=100type="subtotal", amount=0type="total", amount=-5(no rule)type="custom_vendor_type", amount=-7js-sdk already enforces the same two rules on
TotalResponseSchema, so thiscloses a cross-SDK divergence.