Skip to content

Commit 454d719

Browse files
fix(core): Property's type should be nullable (#117)
1 parent d033b38 commit 454d719

8 files changed

Lines changed: 56 additions & 10 deletions

File tree

spring-configuration-property-documenter-core/src/main/java/org/rodnansol/core/generator/template/data/Property.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Property {
2222
/**
2323
* Type of the property, most likely to be a Java class.
2424
*/
25-
@NonNull
25+
@Nullable
2626
private final String type;
2727
/**
2828
* Property's key.
@@ -47,7 +47,7 @@ public class Property {
4747

4848
public Property(String fqName, String type) {
4949
this.fqName = Objects.requireNonNull(fqName, "fqName is NULL");
50-
this.type = Objects.requireNonNull(type, "type is NULL");
50+
this.type = type;
5151
}
5252

5353
public Property(String fqName, String type, String key, String description, String defaultValue, PropertyDeprecation propertyDeprecation) {
@@ -96,7 +96,7 @@ public void setDefaultValue(@Nullable String defaultValue) {
9696
this.defaultValue = defaultValue;
9797
}
9898

99-
@NonNull
99+
@Nullable
100100
public String getType() {
101101
return type;
102102
}

spring-configuration-property-documenter-core/src/main/resources/templates/partials/adoc/content.adoc.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ ifdef::property-group-discrete-heading[]
1616
=== {{groupName}}
1717
endif::[]
1818
{{#is_included "class" ~}}
19+
{{#if type ~}}
1920
*{{i18n "template.class"}}:* `{{type}}`
21+
{{/if ~}}
2022
{{/is_included ~}}
2123

2224
{{> templates/partials/adoc/content-table-header.adoc}}
@@ -25,7 +27,7 @@ endif::[]
2527
|{{key}}
2628
{{/is_included ~}}
2729
{{#is_included "type" ~}}
28-
|{{type}}
30+
|{{#if type}}{{type}}{{/if}}
2931
{{/is_included ~}}
3032
{{#is_included "description" ~}}
3133
|{{description}}

spring-configuration-property-documenter-core/src/main/resources/templates/partials/html/compact-content.html.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<td>{{fqName}}</td>
55
{{/is_included ~}}
66
{{#is_included "type" ~}}
7-
<td>{{type}}</td>
7+
<td>{{#if type}}{{type}}{{/if}}</td>
88
{{/is_included ~}}
99
{{#is_included "description" ~}}
1010
<td>{{description}}</td>

spring-configuration-property-documenter-core/src/main/resources/templates/partials/html/content.html.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{#each propertyGroups ~}}
77
<h2 id="{{#if moduleName}}{{moduleName}}-{{/if}}{{groupName}}">{{groupName}}</h2>
88
{{#is_included "class" ~}}
9-
<b>{{i18n "template.class"}}:</b> <code>{{type}}</code>
9+
{{#if type}}<b>{{i18n "template.class"}}:</b> <code>{{type}}</code>{{/if}}
1010
{{/is_included ~}}
1111
<table class="table">
1212
{{> templates/partials/html/content-table-header.html}}
@@ -17,7 +17,7 @@
1717
<td>{{key}}</td>
1818
{{/is_included ~}}
1919
{{#is_included "type" ~}}
20-
<td>{{type}}</td>
20+
<td>{{#if type}}{{type}}{{/if}}</td>
2121
{{/is_included ~}}
2222
{{#is_included "description" ~}}
2323
<td>{{description}}</td>

spring-configuration-property-documenter-core/src/main/resources/templates/partials/md/content.md.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
{{#each propertyGroups~}}
99
### {{groupName}}
1010
{{#is_included "class" ~}}
11+
{{#if type~}}
1112
**{{i18n "template.class"}}:** `{{type}}`
13+
{{/if~}}
1214
{{/is_included}}
1315
{{> templates/partials/md/content-table-header.md}}
1416
{{#each properties ~}}
15-
| {{#is_included "key"}}{{key}}|{{/is_included}} {{#is_included "type"}}{{type}}|{{/is_included}} {{#is_included "description"}}{{description}}|{{/is_included}} {{#is_included "defaultValue"}}{{defaultValue}}|{{/is_included}} {{#is_included "deprecation"}}{{propertyDeprecation}}|{{/is_included}} {{#is_included "envFormat"}}`{{as_env fqName}}`|{{/is_included}}
17+
| {{#is_included "key"}}{{key}}|{{/is_included}} {{#is_included "type"}}{{#if type~}}{{type}}{{/if}}|{{/is_included}} {{#is_included "description"}}{{description}}|{{/is_included}} {{#is_included "defaultValue"}}{{defaultValue}}|{{/is_included}} {{#is_included "deprecation"}}{{propertyDeprecation}}|{{/is_included}} {{#is_included "envFormat"}}`{{as_env fqName}}`|{{/is_included}}
1618
{{/each ~}}
1719
{{/each}}

spring-configuration-property-documenter-core/src/main/resources/templates/partials/xml/content.xml.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<propertyGroups>{{#each propertyGroups}}
55
<propertyGroup>
66
<groupName>{{groupName}}</groupName>
7-
<type>{{type}}</type>
7+
{{#if type}}<type>{{type}}</type>{{/if}}
88
<properties>{{#each properties}}
99
<property>
1010
<key>{{key}}</key>
11-
<type>{{type}}</type>
11+
{{#if type}}<type>{{type}}</type>{{/if}}
1212
<description>{{description}}</description>
1313
<defaultValue>{{defaultValue}}</defaultValue>
1414
<propertyDeprecation>{{propertyDeprecation}}</propertyDeprecation>

spring-configuration-property-documenter-core/src/test/java/org/rodnansol/core/generator/reader/MetadataReaderTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,26 @@ void readPropertiesAsPropertyGroupList_whenProperyParentIsNotHavingName() throws
323323
assertThat(propertyGroups)
324324
.containsAll(expectedYourProperties1);
325325
}
326+
327+
@Test
328+
@Issue("#115")
329+
@DisplayName("Should parse property with null type and not fail")
330+
void shouldParsePropertyWithNullType() throws Exception {
331+
// Given
332+
String file = TEST_RESOURCES_DIRECTORY + "regression/spring-configuration-metadata-property-without-type.json";
333+
334+
// When
335+
List<PropertyGroup> propertyGroups = underTest.readPropertiesAsPropertyGroupList(new FileInputStream(file));
336+
337+
// Then
338+
PropertyGroup testGroup = new PropertyGroup("test.group", "com.example.springpropertysources.MyProperties", "com.example.springpropertysources.MyProperties");
339+
testGroup.addProperty(new Property("test.group.with.type", "java.lang.String", "with.type", "Property with type field", null, null));
340+
testGroup.addProperty(new Property("test.group.without.type", null, "without.type", "Property without type field", null, null));
341+
342+
List<PropertyGroup> expectedGroups = List.of(PropertyGroup.createUnknownGroup(), testGroup);
343+
assertThat(propertyGroups)
344+
.containsAll(expectedGroups);
345+
}
326346
}
327347

328348
static class ReadPropertiesAsPropertyGroupListTestCase {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"groups": [
3+
{
4+
"name": "test.group",
5+
"type": "com.example.springpropertysources.MyProperties",
6+
"sourceType": "com.example.springpropertysources.MyProperties"
7+
}
8+
],
9+
"properties": [
10+
{
11+
"name": "test.group.without.type",
12+
"description": "Property without type field",
13+
"sourceType": "com.example.springpropertysources.MyProperties"
14+
},
15+
{
16+
"name": "test.group.with.type",
17+
"type": "java.lang.String",
18+
"description": "Property with type field",
19+
"sourceType": "com.example.springpropertysources.MyProperties"
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)