Skip to content

Nested rules on dry-schema - #17

Merged
numbata merged 2 commits into
numbata:mainfrom
slbug:nested_rules_on_dry_schema_new
Dec 23, 2025
Merged

Nested rules on dry-schema#17
numbata merged 2 commits into
numbata:mainfrom
slbug:nested_rules_on_dry_schema_new

Conversation

@slbug

@slbug slbug commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

I wanted to use this gem for some dry-schema to oas generation and found following issues:

  1. no support for nested things like size/min_size/ignored formats/enums/etc, basically nothing nested supported
  2. size: (1..10) not supported for arrays - extracted to Support for range size predicate #18
  3. required missing on nested
  4. useless "x-unhandledPredicates": ["set"]
  5. found discrepancies in gem tests with incorrect understanding how array macro works

optional(:tags).array(:string, min_size?: 1, max_size?: 3) - here sizes related to items, not array

optional(:tags).value(:array, min_size?: 1, max_size?: 3).each(:string) - here to array

@numbata

numbata commented Dec 21, 2025

Copy link
Copy Markdown
Owner

Thanks for pushing this! I mostly run Grape::Entity endpoints today and am just starting to move toward dry-contracts, so it’s great to see this work coming in.

Would you be willing to split this into two PRs? It’ll make review easier and get some value shipped faster:

  1. Range syntax support for size? (ArgumentExtractor + PredicateHandler) - just the size?: (3..8) syntax enhancement with a focused test. This is self-contained and can merge immediately.
  2. Path-aware nested rule handling (RuleIndex, TypeSchemaBuilder, DryIntrospector) - the core feature for handling constraint isolation in deeply nested schemas. This is where the real substance is, and it’ll be easier to review without the range syntax mixed in.

That way we can land the quick win while the bigger piece gets the attention it deserves. Great job, btw! 🎉

@numbata numbata self-assigned this Dec 21, 2025
@slbug
slbug force-pushed the nested_rules_on_dry_schema_new branch from acbeb94 to a22fc5a Compare December 21, 2025 18:56
@slbug

slbug commented Dec 21, 2025

Copy link
Copy Markdown
Contributor Author

@numbata done

@slbug
slbug force-pushed the nested_rules_on_dry_schema_new branch 2 times, most recently from 77e7008 to 13b9e3c Compare December 21, 2025 22:01
@numbata
numbata requested a review from Copilot December 21, 2025 22:03
Comment thread lib/grape_oas/introspectors/dry_introspector.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/grape_oas/introspectors/dry_introspector_test.rb Outdated
Comment thread test/grape_oas/introspectors/dry_introspector_test.rb Outdated
Comment thread lib/grape_oas/introspectors/dry_introspector_support/rule_index.rb Outdated
Comment thread lib/grape_oas/introspectors/dry_introspector_support/rule_index.rb
@slbug
slbug force-pushed the nested_rules_on_dry_schema_new branch from 13b9e3c to 699f147 Compare December 21, 2025 22:13
@numbata

numbata commented Dec 21, 2025

Copy link
Copy Markdown
Owner

@slbug Can you rebase again? I changed a way how the CI reporting a coverage here #20. So, the failed CI check should becomes green now. I hope 🤞.

@slbug
slbug force-pushed the nested_rules_on_dry_schema_new branch from 699f147 to e6f49d9 Compare December 21, 2025 22:38
Comment thread lib/grape_oas/introspectors/dry_introspector.rb
@numbata
numbata merged commit d87d0b8 into numbata:main Dec 23, 2025
7 checks passed
@numbata

numbata commented Dec 23, 2025

Copy link
Copy Markdown
Owner

@slbug released as v1.0.3

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.

3 participants