ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.86k stars 1.22k forks source link

Implement nested `with` support in parameter DSL #2434

Closed numbata closed 2 months ago

numbata commented 2 months ago

Motivation

Previously, the with' method in the Parameter DSL did not support nested structures. This forced to redefine the entire attribute set for each nested scope, which was cumbersome and prone to errors, especially in complex parameter structures.

Solution

This PR introduces enhanced functionality to the with method that allows nested scopes to inherit and extend the attributes defined in parent scopes. By merging attributes from the current group with the new attributes, it simplifies parameter declarations and ensures a clean, DRY approach to specifying shared attributes in nested parameter contexts.

dblock commented 2 months ago

Looks good. Document it in README please? Maybe add a test with 3 levels just to be sure ;)

numbata commented 2 months ago

@dblock Sorry to keep you waiting. README updated: https://github.com/ruby-grape/grape/pull/2434/commits/6bc75fc7ba7e61104da386b7332da607da1bae61.