Support mapping every controller as a REST resource - #16273
Open
codeconsole wants to merge 2 commits into
Open
Conversation
An application whose controllers all follow the RESTful resource conventions had to declare a resources mapping per controller, or hand-write the eight equivalent method-prefixed mappings. The first grows the mapping table with the controller count; the second copies a framework convention into application code, where it drifts when the convention changes. Passing '*' as the resources argument now generates the eight mappings once and leaves the controller to be resolved from the URL's own capture when a request is matched, which the existing runtime constraint evaluator already supports. includes, excludes and group prefixes compose as they do for a named resource. Because the controller is not known until a request is matched, two cases are rejected when the mappings are evaluated rather than left to produce mappings that cannot match: a URL that does not capture the controller, and a nested child resource, which would otherwise build a constraint named "nullId".
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16273 +/- ##
==================================================
- Coverage 54.7149% 54.7043% -0.0106%
+ Complexity 20421 20419 -2
==================================================
Files 2101 2101
Lines 100978 100992 +14
Branches 17907 17913 +6
==================================================
- Hits 55250 55247 -3
- Misses 37860 37878 +18
+ Partials 7868 7867 -1
🚀 New features to boost your workflow:
|
✅ All tests passed ✅Test SummaryGroovy Snapshot Canary Build / Build Grails (shard 1) > :grails-test-examples-gsp-sitemesh3:integrationTest
🏷️ Commit: 6af0bf5 Learn more about TestLens at testlens.app/docs. |
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.
An application whose controllers all follow the RESTful resource conventions has to declare a
resourcesmapping per controller, or hand-write the eight equivalent method-prefixed mappings. The first grows the mapping table with the controller count; the second copies a framework convention into application code, where it drifts when the convention changes.Passing
*as theresourcesargument applies the conventions to every controller:That generates the eight mappings once — not once per controller — and resolves the controller from the URL when a request is matched:
includes,excludesandgroupprefixes compose as they do for a named resource:The captured controller and action are validated as they are for any other wildcard mapping, so a URI that does not correspond to a registered controller and action does not match.
Limitations, both rejected when the mappings are evaluated rather than left to produce mappings that cannot match:
"/books"(resources: '*')is an error