codeconsole commented on code in PR #16772:
URL: https://github.com/apache/grails-core/pull/16772#discussion_r4383232694
##########
grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy:
##########
@@ -416,6 +416,17 @@ class NavigableMap implements Map<String, Object>,
Cloneable {
}
}
+ /**
+ * Whether the entry is one of a map written by map subscripts that the
root holds under its bracketed flat key, as
+ * {@code app.routes[/api/**]} holds the entry {@code /api/**} of the map
{@code app.routes}: that key exports it, and
+ * its dotted name, {@code app.routes./api/**}, would export it a second
time under a name Spring Boot binds as
+ * {@code api}.
+ */
+ private boolean isEntryOfBracketedKey(Map currentMap, List<String> path,
String key) {
+ path && !(currentMap instanceof NavigableMap) && rootConfig.is(this) &&
Review Comment:
Done in 0db23f17a4. The `NavigableMap` exemption is gone. There was one more
source of the duplicate in this shape: once `app.routes` is a nested map, its
merge also writes the root key `app.routes./api/**`, the root alias every
nested entry gets. The relative check doesn't reach it, since the relative path
is empty at the root. At the root, the walk now also skips a dotted key that a
bracketed key of the root names at one of its dots (`app.routes./api/**` →
`app.routes[/api/**]`). `PropertySourcesConfigSpec` loads your YAML through
`YamlPropertySourceLoader` and binds `app.routes` from the export with
`Binder`, which gives `[default:z, /api/**:x]`.
##########
grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy:
##########
@@ -416,6 +416,17 @@ class NavigableMap implements Map<String, Object>,
Cloneable {
}
}
+ /**
+ * Whether the entry is one of a map written by map subscripts that the
root holds under its bracketed flat key, as
+ * {@code app.routes[/api/**]} holds the entry {@code /api/**} of the map
{@code app.routes}: that key exports it, and
+ * its dotted name, {@code app.routes./api/**}, would export it a second
time under a name Spring Boot binds as
+ * {@code api}.
+ */
+ private boolean isEntryOfBracketedKey(Map currentMap, List<String> path,
String key) {
+ path && !(currentMap instanceof NavigableMap) && rootConfig.is(this) &&
+ delegateMap.containsKey("${path.join('.')}[${key}]".toString())
Review Comment:
I took your lookup in 0db23f17a4. `isEntryOfBracketedKey` and both guards
are gone, and each entry is checked against its nearest enclosing
`NavigableMap`, with the path relative to that map. The only addition is the
root check described on the previous thread. The `grails-bootstrap` (212) and
`grails-core` (516) suites pass.
##########
grails-core/src/test/groovy/org/grails/config/PropertySourcesConfigSpec.groovy:
##########
@@ -116,4 +119,34 @@ class PropertySourcesConfigSpec extends Specification {
then: 'the second value is not merged with the first value'
cfg.foo.bar == ['two': '2']
}
+
+ void 'a map written by map subscripts is exported by its bracketed keys
only, which Spring Boot binds as written'() {
Review Comment:
Added in 0db23f17a4. `ConfigMapSpec` has a `where:` over the four shapes:
- a dotted key before the subscript in the same map
- a subscript after a subscript
- `navigate('app')`
- `clone()`
Each is merged through `merge(map, true)`, and each row asserts the key sets
of both `toFlatConfig()` and `toProperties()`. `PropertySourcesConfigSpec` has
rows for the first two loaded through `YamlPropertySourceLoader` and bound with
`Binder`. Every new row fails at 8a58047ade. The follow-up commit's message
records that `toFlatConfig()` is now asserted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]