Skip to content

Support mapping every controller as a REST resource - #16273

Merged
codeconsole merged 5 commits into
apache:8.0.xfrom
codeconsole:feat/wildcard-resources-mapping
Sep 2, 2026
Merged

codeconsole merged 5 commits into
apache:8.0.xfrom
codeconsole:feat/wildcard-resources-mapping

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

An application whose controllers all follow the RESTful resource conventions has 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 applies the conventions to every controller:

"/$controller"(resources: '*')

That generates the eight mappings once — not once per controller — and resolves the controller from the URL when a request is matched:

get    "/$controller(.$format)?"(action: 'index')
post   "/$controller(.$format)?"(action: 'save')
get    "/$controller/create"(action: 'create')
get    "/$controller/$id/edit"(action: 'edit')
get    "/$controller/$id(.$format)?"(action: 'show')
put    "/$controller/$id(.$format)?"(action: 'update')
patch  "/$controller/$id(.$format)?"(action: 'patch')
delete "/$controller/$id(.$format)?"(action: 'delete')

includes, excludes and group prefixes compose as they do for a named resource:

group "/api/v1", {
    "/$controller"(resources: '*', excludes: ['create', 'edit'])
}

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:

  • the URL must capture the controller, so "/books"(resources: '*') is an error
  • child resources cannot be nested within the mapping, since the parent controller is not known until a request is matched

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

codecov Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.7536%. Comparing base (c1b532a) to head (c427432).

Files with missing lines Patch % Lines
...grails/web/mapping/DefaultUrlMappingEvaluator.java 93.3333% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16273        +/-   ##
==================================================
+ Coverage     54.7365%   54.7536%   +0.0171%     
- Complexity      20470      20473         +3     
==================================================
  Files            2103       2103                
  Lines          101077     101091        +14     
  Branches        17928      17934         +6     
==================================================
+ Hits            55326      55351        +25     
+ Misses          37876      37861        -15     
- Partials         7875       7879         +4     
Files with missing lines Coverage Δ
...grails/web/mapping/DefaultUrlMappingEvaluator.java 78.6913% <93.3333%> (+0.3408%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

"/$namespace/$controller"(resources: '*') already worked, since the
namespace token registers its own constraint and RegexUrlMapping has a
runtime evaluator for it, but nothing pinned that down. The constraint
ordering is what makes it work and is easy to break: namespace, then
controller, then the id and format the resource mappings append, which
have to line up with the regex group positions.

Adds a spec asserting all four bind correctly, that literal segments
still beat the id, and that a second namespace reuses the same eight
mappings. Documents the form in the guide.
@testlens-app

testlens-app Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

⚠️ TestLens detected flakiness ⚠️

Test Summary

CI / Build Grails-Core (Windows JDK 25 shard 2) > :grails-async-core:test

Test Runs Flakiness
FutureTaskPromiseFactorySpec > Test promise onError handling ❌ ✅ 1% 🟡

🏷️ Commit: c427432
▶️ Tests: 21576 executed
⚪️ Checks: 89/89 completed

Test Failures

FutureTaskPromiseFactorySpec > Test promise onError handling (:grails-async-core:test in CI / Build Grails-Core (Windows JDK 25 shard 2) | Attempt 1/2)
Expected exception of type 'java.util.concurrent.ExecutionException', but got 'java.lang.RuntimeException'
	at grails.async.FutureTaskPromiseFactorySpec.Test promise onError handling(FutureTaskPromiseFactorySpec.groovy:118)
Caused by: java.lang.RuntimeException: bad
	at grails.async.FutureTaskPromiseFactorySpec.Test promise onError handling_closure17(FutureTaskPromiseFactorySpec.groovy:110)
	at grails.async.FutureTaskPromiseFactorySpec.Test promise onError handling_closure17(FutureTaskPromiseFactorySpec.groovy)

Learn more about TestLens at testlens.app/docs.

@codeconsole
codeconsole merged commit 19157d8 into apache:8.0.x Sep 2, 2026
156 of 157 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants