Skip to content

Commit 4c8ab50

Browse files
committedNov 17, 2018
[FLINK-10880] Add Documentation.ExcludeFromDocumentation to exclude ConfigOptions from documentation
The annotation Documentation.ExcludeFromDocumentation can be used to annotate ConfigOptions with in order to not include them in the documentation.
1 parent 1175dba commit 4c8ab50

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
 

‎flink-annotations/src/main/java/org/apache/flink/annotation/docs/Documentation.java

+13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ public final class Documentation {
5959
int position() default Integer.MAX_VALUE;
6060
}
6161

62+
/**
63+
* Annotation used on config option fields to exclude the config option from documentation.
64+
*/
65+
@Target(ElementType.FIELD)
66+
@Retention(RetentionPolicy.RUNTIME)
67+
@Internal
68+
public @interface ExcludeFromDocumentation {
69+
/**
70+
* The optional reason why the config option is excluded from documentation.
71+
*/
72+
String value() default "";
73+
}
74+
6275
private Documentation(){
6376
}
6477
}

‎flink-docs/src/main/java/org/apache/flink/docs/configuration/ConfigOptionsDocGenerator.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static List<OptionWithMetaInfo> extractConfigOptions(Class<?> clazz) {
202202
List<OptionWithMetaInfo> configOptions = new ArrayList<>(8);
203203
Field[] fields = clazz.getFields();
204204
for (Field field : fields) {
205-
if (field.getType().equals(ConfigOption.class) && field.getAnnotation(Deprecated.class) == null) {
205+
if (isConfigOption(field) && shouldBeDocumented(field)) {
206206
configOptions.add(new OptionWithMetaInfo((ConfigOption<?>) field.get(null), field));
207207
}
208208
}
@@ -213,6 +213,15 @@ static List<OptionWithMetaInfo> extractConfigOptions(Class<?> clazz) {
213213
}
214214
}
215215

216+
private static boolean isConfigOption(Field field) {
217+
return field.getType().equals(ConfigOption.class);
218+
}
219+
220+
private static boolean shouldBeDocumented(Field field) {
221+
return field.getAnnotation(Deprecated.class) == null &&
222+
field.getAnnotation(Documentation.ExcludeFromDocumentation.class) == null;
223+
}
224+
216225
/**
217226
* Transforms this configuration group into HTML formatted table.
218227
* Options are sorted alphabetically by key.

‎flink-docs/src/test/java/org/apache/flink/docs/configuration/ConfigOptionsDocGeneratorTest.java

+41
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,45 @@ public void testCommonOptions() throws IOException, ClassNotFoundException {
266266

267267
assertEquals(expected, output);
268268
}
269+
270+
static class TestConfigGroupWithExclusion {
271+
public static ConfigOption<Integer> firstOption = ConfigOptions
272+
.key("first.option.a")
273+
.defaultValue(2)
274+
.withDescription("This is example description for the first option.");
275+
276+
@Documentation.ExcludeFromDocumentation
277+
public static ConfigOption<String> excludedOption = ConfigOptions
278+
.key("excluded.option.a")
279+
.noDefaultValue()
280+
.withDescription("This should not be documented.");
281+
}
282+
283+
/**
284+
* Tests that {@link ConfigOption} annotated with {@link Documentation.ExcludeFromDocumentation}
285+
* are not documented.
286+
*/
287+
@Test
288+
public void testConfigOptionExclusion() {
289+
final String expectedTable =
290+
"<table class=\"table table-bordered\">\n" +
291+
" <thead>\n" +
292+
" <tr>\n" +
293+
" <th class=\"text-left\" style=\"width: 20%\">Key</th>\n" +
294+
" <th class=\"text-left\" style=\"width: 15%\">Default</th>\n" +
295+
" <th class=\"text-left\" style=\"width: 65%\">Description</th>\n" +
296+
" </tr>\n" +
297+
" </thead>\n" +
298+
" <tbody>\n" +
299+
" <tr>\n" +
300+
" <td><h5>first.option.a</h5></td>\n" +
301+
" <td style=\"word-wrap: break-word;\">2</td>\n" +
302+
" <td>This is example description for the first option.</td>\n" +
303+
" </tr>\n" +
304+
" </tbody>\n" +
305+
"</table>\n";
306+
final String htmlTable = ConfigOptionsDocGenerator.generateTablesForClass(TestConfigGroupWithExclusion.class).get(0).f1;
307+
308+
assertEquals(expectedTable, htmlTable);
309+
}
269310
}

0 commit comments

Comments
 (0)
Please sign in to comment.