Skip to content

Commit dd2c002

Browse files
authored
fix: make title and description of Condition Nullable (#1063)
According to https://cloud.google.com/iam/docs/conditions-overview#syntax_overview both title and description are optional. Currently, AutoValue treats these fields as non-null which goes against the definition from the API. This change may be considered breaking by some criteria, however this class is annotated @BetaApi.
1 parent 60a8ee5 commit dd2c002

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

java-core/google-cloud-core/src/main/java/com/google/cloud/Condition.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.api.core.BetaApi;
2020
import com.google.auto.value.AutoValue;
21+
import javax.annotation.Nullable;
2122

2223
/**
2324
* Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access
@@ -32,9 +33,11 @@
3233
@AutoValue
3334
public abstract class Condition {
3435
/** Get IAM Policy Binding Condition Title */
36+
@Nullable
3537
public abstract String getTitle();
3638

3739
/** Get IAM Policy Binding Condition Description */
40+
@Nullable
3841
public abstract String getDescription();
3942

4043
/** Get IAM Policy Binding Condition Expression */
@@ -51,10 +54,10 @@ public static Builder newBuilder() {
5154
@AutoValue.Builder
5255
public abstract static class Builder {
5356
/** Set IAM Policy Binding Condition Title */
54-
public abstract Builder setTitle(String title);
57+
public abstract Builder setTitle(@Nullable String title);
5558

5659
/** Set IAM Policy Binding Condition Description */
57-
public abstract Builder setDescription(String description);
60+
public abstract Builder setDescription(@Nullable String description);
5861

5962
/** Set IAM Policy Binding Condition Expression */
6063
public abstract Builder setExpression(String expression);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2023 Google LLC
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+
17+
package com.google.cloud;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import org.junit.Test;
22+
23+
public final class ConditionTest {
24+
25+
@Test
26+
public void title_nullable() {
27+
Condition condition =
28+
Condition.newBuilder().setTitle(null).setDescription("desc").setExpression("expr").build();
29+
30+
assertThat(condition.getTitle()).isNull();
31+
}
32+
33+
@Test
34+
public void description_nullable() {
35+
Condition condition =
36+
Condition.newBuilder().setTitle("title").setDescription(null).setExpression("expr").build();
37+
38+
assertThat(condition.getDescription()).isNull();
39+
}
40+
}

0 commit comments

Comments
 (0)