Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected List<Element> getDeprecatableElements() {

@Override
protected boolean isMarkedAsNested(MetadataGenerationEnvironment environment) {
return false;
return environment.getNestedConfigurationPropertyAnnotation(this.recordComponent) != null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.boot.configurationprocessor.metadata.Metadata;
import org.springframework.boot.configurationsample.deprecation.Dbcp2Configuration;
import org.springframework.boot.configurationsample.record.ExampleRecord;
import org.springframework.boot.configurationsample.record.NestedPropertiesRecord;
import org.springframework.boot.configurationsample.record.RecordWithGetter;
import org.springframework.boot.configurationsample.recursive.RecursiveProperties;
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
Expand Down Expand Up @@ -510,6 +511,15 @@ void recordWithGetter() {
assertThat(metadata).doesNotHave(Metadata.withProperty("record-with-getter.bravo"));
}

@Test
void recordNested() {
ConfigurationMetadata metadata = compile(NestedPropertiesRecord.class);
assertThat(metadata).has(Metadata.withGroup("record-nested.nested"));
assertThat(metadata).has(Metadata.withProperty("record-nested.nested.my-nested-property"));
assertThat(metadata).has(Metadata.withGroup("record-nested.inner.nested"));
assertThat(metadata).has(Metadata.withProperty("record-nested.inner.nested.my-nested-property"));
}

@Test
void shouldNotMarkDbcp2UsernameOrPasswordAsDeprecated() {
ConfigurationMetadata metadata = compile(Dbcp2Configuration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Phillip Webb
* @since 1.2.0
*/
@Target(ElementType.FIELD)
@Target({ ElementType.FIELD, ElementType.RECORD_COMPONENT })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NestedConfigurationProperty {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.configurationsample.record;

import org.springframework.boot.configurationsample.ConfigurationProperties;
import org.springframework.boot.configurationsample.NestedConfigurationProperty;

@ConfigurationProperties("record-nested")
public record NestedPropertiesRecord(String myProperty, @NestedConfigurationProperty NestedRecord nested,
InnerPropertiesRecord inner) {

public record InnerPropertiesRecord(String myInnerProperty, @NestedConfigurationProperty NestedRecord nested) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.configurationsample.record;

public record NestedRecord(String myNestedProperty) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Phillip Webb
* @since 1.2.0
*/
@Target(ElementType.FIELD)
@Target({ ElementType.FIELD, ElementType.RECORD_COMPONENT })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nested
Expand Down