Add JSON Schema validation and arithmetic operators for expressions#1000
Open
jnunemaker wants to merge 6 commits into
Open
Add JSON Schema validation and arithmetic operators for expressions#1000jnunemaker wants to merge 6 commits into
jnunemaker wants to merge 6 commits into
Conversation
Open
10 tasks
Enforce expression types from a single source of truth: the JSON Schema vendored from flippercloud/expressions. Validation (Q2): - Vendor schemas into lib/flipper/expression/schemas (no npm, no separate gem) - Flipper::Expression::Schema loads them via json_schemer (2.x). The gem is an optional dependency, lazily required, so core stays lightweight — validation is a write-time tool, not needed on the evaluate hot path - Add #validate / #valid? to Expression and Constant - build now handles null constants, rejects multi-key hashes, and stops corrupting a single Hash argument via Array() Property types (Q1): - Gates::Expression#properties warns about and drops flipper_properties values that aren't String/Numeric/true/false/nil, matching the schema's scalar property definition, instead of mis-evaluating them Operator parity: - Add Add, Subtract, Multiply, Divide, Min, Max and restore Duration so Ruby evaluates everything the schema defines (Duration + Add enable relative-time windows, e.g. Now < Time(signup_at) + Duration(7, "days")) Testing: - spec/flipper/expression/schema_spec.rb runs the example JSON files vendored from the expressions repo, so Ruby and JS test the same cases - rake expressions:vendor re-copies schemas (to lib) and examples (to spec) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The merged expressions PR dropped the `property` definition (it described context values, not expressions). Sync the vendored copy and update the gate comment; Q1 enforcement is unaffected since it uses ALLOWED_PROPERTY_TYPES. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fad402a to
f366d92
Compare
Reject schema-invalid expression payloads in the API before saving, and make arithmetic expression operators fail closed when operands are missing or incompatible.
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.
Adds optional JSON Schema validation for expressions using schemas vendored from flippercloud/expressions (no npm), exposed as
Expression#validate/#valid?and backed by a lazily-required, optionaljson_schemerdependency so core stays lightweight and unburdened on the evaluate hot path. Enforcesflipper_propertiesvalue types inGates::Expressionby warning about and dropping values that aren'tString/Numeric/true/false/nil, matching the schema's scalar property definition. Brings Ruby to parity with the schema by adding theAdd,Subtract,Multiply,Divide,Min,Maxoperators and restoringDuration, which together enable relative-time windows likeNow < Time(signup_at) + Duration(7, "days"). Addsspec/flipper/expression/schema_spec.rb, which runs the example JSON files vendored from the expressions repo so Ruby and JS test the same cases, plus arake expressions:vendortask to re-copy schemas and examples.Note: this pairs with companion changes in flippercloud/expressions (new
FeatureEnabledschema, scalarpropertydefinition); it should land after that repo is published so the vendored schemas match a release.