Nested rules on dry-schema - #17
Conversation
|
Thanks for pushing this! I mostly run Would you be willing to split this into two PRs? It’ll make review easier and get some value shipped faster:
That way we can land the quick win while the bigger piece gets the attention it deserves. Great job, btw! 🎉 |
acbeb94 to
a22fc5a
Compare
|
@numbata done |
77e7008 to
13b9e3c
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for nested rules and predicates in dry-schema introspection, fixing several issues with how array constraints and nested schemas are processed.
Key Changes:
- Implements path-aware constraint extraction to properly handle nested validations (e.g.,
min_size?,format?,gteq?) at any nesting level - Corrects array macro usage in tests to distinguish between item constraints (
.array(:string, min_size?: 1)) and array constraints (.value(:array, min_size?: 1).each(:string)) - Enables proper detection of required fields in nested hash schemas
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lib/grape_oas/introspectors/dry_introspector_support/rule_index.rb |
New class that builds path-aware indexes of constraints and required fields from dry-schema AST, supporting deep nesting |
lib/grape_oas/introspectors/dry_introspector_support/type_schema_builder.rb |
Refactored to maintain path context during schema building, enabling proper constraint application to nested properties |
lib/grape_oas/introspectors/dry_introspector.rb |
Integrates RuleIndex to enable path-aware schema building |
test/grape_oas/introspectors/dry_introspector_test.rb |
Adds comprehensive tests for nested array constraints and corrects existing tests to use proper array macro syntax |
test/grape_oas/api_model_builders/request_contract_dry_test.rb |
Updates tests to use correct array macro syntax where constraints apply to arrays rather than items |
test/e2e/generate_oas3_complex_test.rb |
Updates test to use correct array macro syntax |
test/e2e/generate_oas2_complex_test.rb |
Updates test to use correct array macro syntax |
CHANGELOG.md |
Documents the new nested rules support feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
13b9e3c to
699f147
Compare
699f147 to
e6f49d9
Compare
I wanted to use this gem for some dry-schema to oas generation and found following issues:
"x-unhandledPredicates": ["set"]optional(:tags).array(:string, min_size?: 1, max_size?: 3)- here sizes related to items, not arrayoptional(:tags).value(:array, min_size?: 1, max_size?: 3).each(:string)- here to array