Skip to content

Commit eb9d51b

Browse files
authored
Docs generator: do not print all enum constants for all enums (#4156)
For enums with more than 3 constants, we are now printing just the first 3, in order to avoid messing up the HTML table rendering. The full list of names is still viewable through an HTML tooltip. The format also now includes the token `enum` before the list of enum names, for clarity.
1 parent 23360a0 commit eb9d51b

8 files changed

Lines changed: 89 additions & 11 deletions

File tree

site/content/in-dev/unreleased/configuration/config-sections/smallrye-polaris_authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ build:
2525

2626
| Property | Default Value | Type | Description |
2727
|----------|---------------|------|-------------|
28-
| `polaris.authentication.type` | `internal` | `INTERNAL, EXTERNAL, MIXED` | The type of authentication to use. |
28+
| `polaris.authentication.type` | `internal` | `enum (INTERNAL, EXTERNAL, MIXED)` | The type of authentication to use. |
2929
| `polaris.authentication.authenticator.type` | `default` | `string` | The type of the identity provider. Must be a registered (`Authenticator`) identifier. |
3030
| `polaris.authentication.token-service.type` | `default` | `string` | The type of the OAuth2 service. Must be a registered (`IcebergRestOAuth2ApiService`) identifier. |
3131
| `polaris.authentication.token-broker.max-token-generation` | `PT1H` | `duration` | The maximum token duration. |
@@ -34,7 +34,7 @@ build:
3434
| `polaris.authentication.token-broker.rsa-key-pair.private-key-file` | | `path` | The path to the private key file. |
3535
| `polaris.authentication.token-broker.symmetric-key.secret` | | `string` | The secret to use for both signing and verifying signatures. Either this option of (`#file()`) must be provided. |
3636
| `polaris.authentication.token-broker.symmetric-key.file` | | `path` | The file to read the secret from. Either this option of (`#secret()`) must be provided. |
37-
| `polaris.authentication.`_`<realm>`_`.type` | `internal` | `INTERNAL, EXTERNAL, MIXED` | The type of authentication to use. |
37+
| `polaris.authentication.`_`<realm>`_`.type` | `internal` | `enum (INTERNAL, EXTERNAL, MIXED)` | The type of authentication to use. |
3838
| `polaris.authentication.`_`<realm>`_`.authenticator.type` | `default` | `string` | The type of the identity provider. Must be a registered (`Authenticator`) identifier. |
3939
| `polaris.authentication.`_`<realm>`_`.token-service.type` | `default` | `string` | The type of the OAuth2 service. Must be a registered (`IcebergRestOAuth2ApiService`) identifier. |
4040
| `polaris.authentication.`_`<realm>`_`.token-broker.max-token-generation` | `PT1H` | `duration` | The maximum token duration. |

site/content/in-dev/unreleased/configuration/config-sections/smallrye-polaris_authorization_opa.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Beta Feature: OPA authorization is currently in Beta and is not a stable releas
3030
| Property | Default Value | Type | Description |
3131
|----------|---------------|------|-------------|
3232
| `polaris.authorization.opa.policy-uri` | | `uri` | |
33-
| `polaris.authorization.opa.auth.type` | `none` | `NONE, BEARER` | Type of authentication |
33+
| `polaris.authorization.opa.auth.type` | `none` | `enum (NONE, BEARER)` | Type of authentication |
3434
| `polaris.authorization.opa.auth.bearer.static-token.value` | | `string` | Static bearer token value |
3535
| `polaris.authorization.opa.auth.bearer.file-based.path` | | `path` | Path to file containing bearer token |
3636
| `polaris.authorization.opa.auth.bearer.file-based.refresh-interval` | | `duration` | How often to refresh file-based bearer tokens (defaults to 5 minutes if not specified) |

tools/config-docs/generator/src/main/java/org/apache/polaris/docs/generator/MarkdownPropertyFormatter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public String propertySuffix() {
3333
}
3434

3535
public String propertyType() {
36+
String tooltip = propertyInfo.enumTooltipText();
37+
if (tooltip != null) {
38+
return "<span title=\""
39+
+ tooltip
40+
+ "\"><code>"
41+
+ propertyInfo.simplifiedTypeName()
42+
+ "</code></span>";
43+
}
3644
return '`' + propertyInfo.simplifiedTypeName() + '`';
3745
}
3846
}

tools/config-docs/generator/src/main/java/org/apache/polaris/docs/generator/PropertyInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public interface PropertyInfo {
3333
DocCommentTree doc();
3434

3535
Optional<Class<?>> groupType();
36+
37+
default String enumTooltipText() {
38+
return null;
39+
}
3640
}

tools/config-docs/generator/src/main/java/org/apache/polaris/docs/generator/SmallRyeConfigPropertyInfo.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public String simplifiedTypeName() {
102102
return simplifiedTypeName(property);
103103
}
104104

105+
@Override
106+
public String enumTooltipText() {
107+
return enumTooltipText(property);
108+
}
109+
105110
public boolean isSettableType() {
106111
return isSettableType(property);
107112
}
@@ -172,10 +177,14 @@ public static String simplifiedTypeName(Property property) {
172177
var leaf = property.asLeaf();
173178
var rawType = leaf.getValueRawType();
174179
if (rawType.isEnum()) {
175-
return Arrays.stream(rawType.getEnumConstants())
176-
.map(Enum.class::cast)
177-
.map(Enum::name)
178-
.collect(Collectors.joining(", "));
180+
Object[] constants = rawType.getEnumConstants();
181+
String firstThree =
182+
Arrays.stream(constants)
183+
.limit(3)
184+
.map(Enum.class::cast)
185+
.map(Enum::name)
186+
.collect(Collectors.joining(", "));
187+
return "enum (" + firstThree + (constants.length > 3 ? ", ..." : "") + ")";
179188
}
180189
if (property.hasConvertWith()) {
181190
// A smallrye-config converter always takes a string.
@@ -239,6 +248,31 @@ public static String simplifiedTypeName(Property property) {
239248
throw new UnsupportedOperationException("Don't know how to handle " + property);
240249
}
241250

251+
public static String enumTooltipText(Property property) {
252+
if (property.isOptional()) {
253+
return enumTooltipText(property.asOptional().getNestedProperty());
254+
}
255+
if (property.isCollection()) {
256+
return enumTooltipText(property.asCollection().getElement());
257+
}
258+
if (property.isMap()) {
259+
return enumTooltipText(property.asMap().getValueProperty());
260+
}
261+
if (property.isLeaf()) {
262+
var rawType = property.asLeaf().getValueRawType();
263+
if (rawType.isEnum()) {
264+
Object[] constants = rawType.getEnumConstants();
265+
if (constants.length > 3) {
266+
return Arrays.stream(constants)
267+
.map(Enum.class::cast)
268+
.map(Enum::name)
269+
.collect(Collectors.joining(", "));
270+
}
271+
}
272+
}
273+
return null;
274+
}
275+
242276
@Override
243277
public DocCommentTree doc() {
244278
return doc;

tools/config-docs/generator/src/test/java/org/apache/polaris/docs/generator/TestDocGenTool.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ public void docGenTool(@TempDir Path dir) throws Exception {
143143
| `my.types.float-prim` | | `float` | |
144144
| `my.types.bool-boxed` | | `boolean` | |
145145
| `my.types.bool-prim` | | `boolean` | |
146-
| `my.types.enum-thing` | | `ONE, TWO, THREE` | |
147-
| `my.types.optional-enum` | | `ONE, TWO, THREE` | |
148-
| `my.types.list-of-enum` | | `list of ONE, TWO, THREE` | |
149-
| `my.types.map-to-enum.`_`<name>`_ | | `ONE, TWO, THREE` | |
146+
| `my.types.enum-thing` | | `enum (ONE, TWO, THREE)` | |
147+
| `my.types.optional-enum` | | `enum (ONE, TWO, THREE)` | |
148+
| `my.types.list-of-enum` | | `list of enum (ONE, TWO, THREE)` | |
149+
| `my.types.map-to-enum.`_`<name>`_ | | `enum (ONE, TWO, THREE)` | |
150+
| `my.types.large-enum` | | <span title="ONE, TWO, THREE, FOUR"><code>enum (ONE, TWO, THREE, ...)</code></span> | |
151+
| `my.types.optional-large-enum` | | <span title="ONE, TWO, THREE, FOUR"><code>enum (ONE, TWO, THREE, ...)</code></span> | |
152+
| `my.types.list-of-large-enum` | | <span title="ONE, TWO, THREE, FOUR"><code>list of enum (ONE, TWO, THREE, ...)</code></span> | |
150153
| `my.types.optional-bool` | | `boolean` | |
151154
| `my.types.mapped-a.some-weird-name` | `some-default` | `string` | Something that configures something. |
152155
| `my.types.mapped-a.some-duration` | | `duration` | A duration of something. |

tools/config-docs/generator/src/test/java/tests/smallrye/AllTypes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public interface AllTypes extends InterfaceOne {
9797

9898
Map<String, SomeEnum> mapToEnum();
9999

100+
LargeEnum largeEnum();
101+
102+
Optional<LargeEnum> optionalLargeEnum();
103+
104+
List<LargeEnum> listOfLargeEnum();
105+
100106
Optional<Boolean> optionalBool();
101107

102108
/** My {@code MappedA}. */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2024 Dremio
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package tests.smallrye;
17+
18+
public enum LargeEnum {
19+
ONE,
20+
TWO,
21+
THREE,
22+
FOUR
23+
}

0 commit comments

Comments
 (0)