Skip to content

Commit 8dccee5

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
Add display_name to the Blueprint protos.
PiperOrigin-RevId: 780375554
1 parent cfec87b commit 8dccee5

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

policy/src/main/java/dev/cel/policy/CelPolicy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public abstract static class Variable {
234234

235235
public abstract Optional<ValueString> description();
236236

237+
public abstract Optional<ValueString> displayName();
238+
237239
/** Builder for {@link Variable}. */
238240
@AutoValue.Builder
239241
public abstract static class Builder implements RequiredFieldsChecker {
@@ -244,12 +246,16 @@ public abstract static class Builder implements RequiredFieldsChecker {
244246

245247
abstract Optional<ValueString> description();
246248

249+
abstract Optional<ValueString> displayName();
250+
247251
public abstract Builder setName(ValueString name);
248252

249253
public abstract Builder setExpression(ValueString expression);
250254

251255
public abstract Builder setDescription(ValueString description);
252256

257+
public abstract Builder setDisplayName(ValueString displayName);
258+
253259
@Override
254260
public ImmutableList<RequiredField> requiredFields() {
255261
return ImmutableList.of(

policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ public CelPolicy.Variable parseVariable(
293293
case "description":
294294
builder.setDescription(ctx.newValueString(valueNode));
295295
break;
296+
case "display_name":
297+
builder.setDisplayName(ctx.newValueString(valueNode));
298+
break;
296299
default:
297300
tagVisitor.visitVariableTag(ctx, keyId, keyName, valueNode, policyBuilder, builder);
298301
break;

policy/src/test/java/dev/cel/policy/CelPolicyYamlParserTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ public void parser_setEmpty() throws Exception {
5252
@Test
5353
public void parseYamlPolicy_withDescription() throws Exception {
5454
String policySource =
55-
"rule:\n"
56-
+ " variables:\n"
57-
+ " - name: 'variable_with_description'\n"
58-
+ " description: 'this is a description of the variable'\n"
59-
+ " expression: 'true'";
55+
"""
56+
rule:
57+
variables:
58+
- name: 'variable_with_description'
59+
description: 'this is a description of the variable'
60+
expression: 'true'\
61+
""";
6062

6163
CelPolicy policy = POLICY_PARSER.parse(policySource);
6264

@@ -65,6 +67,24 @@ public void parseYamlPolicy_withDescription() throws Exception {
6567
.hasValue(ValueString.of(10, "this is a description of the variable"));
6668
}
6769

70+
@Test
71+
public void parseYamlPolicy_withDisplayName() throws Exception {
72+
String policySource =
73+
"""
74+
rule:
75+
variables:
76+
- name: 'variable_with_display_name'
77+
display_name: 'Display Name'
78+
expression: 'true'\
79+
""";
80+
81+
CelPolicy policy = POLICY_PARSER.parse(policySource);
82+
83+
assertThat(policy.rule().variables()).hasSize(1);
84+
assertThat(Iterables.getOnlyElement(policy.rule().variables()).displayName())
85+
.hasValue(ValueString.of(10, "Display Name"));
86+
}
87+
6888
@Test
6989
public void parseYamlPolicy_withExplanation() throws Exception {
7090
String policySource =

0 commit comments

Comments
 (0)