@@ -112,9 +112,9 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsEmpty) {
112112 auto constexpr kOptionalEmptyFieldJson = R"""( {})""" ;
113113 auto json = nlohmann::json::parse (kOptionalEmptyFieldJson , nullptr , false );
114114 ASSERT_TRUE (json.is_object ());
115- EXPECT_THAT (
116- DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " , json),
117- Eq (" [json_name=\" testField\" ]" ));
115+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " ,
116+ json, false ),
117+ Eq (" [json_name=\" testField\" ]" ));
118118}
119119
120120TEST (DiscoveryTypeVertexTest, FormatFieldOptionsRequired) {
@@ -127,7 +127,8 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsRequired) {
127127 auto json = nlohmann::json::parse (kOptionalRequiredFieldJson , nullptr , false );
128128 ASSERT_TRUE (json.is_object ());
129129 EXPECT_THAT (
130- DiscoveryTypeVertex::FormatFieldOptions (" test_field" , " testField" , json),
130+ DiscoveryTypeVertex::FormatFieldOptions (" test_field" , " testField" , json,
131+ false ),
131132 Eq (" [(google.api.field_behavior) = REQUIRED,json_name=\" testField\" ]" ));
132133}
133134
@@ -141,10 +142,10 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsOperationRequestField) {
141142 auto json =
142143 nlohmann::json::parse (kOptionalOperationRequestFieldJson , nullptr , false );
143144 ASSERT_TRUE (json.is_object ());
144- EXPECT_THAT (
145- DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " , json),
146- Eq (" [(google.cloud.operation_request_field) = "
147- " \" test_field\" ,json_name=\" testField\" ]" ));
145+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " ,
146+ json, false ),
147+ Eq (" [(google.cloud.operation_request_field) = "
148+ " \" test_field\" ,json_name=\" testField\" ]" ));
148149}
149150
150151TEST (DiscoveryTypeVertexTest, FormatFieldOptionsRequiredOperationRequestField) {
@@ -158,11 +159,11 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsRequiredOperationRequestField) {
158159 auto json =
159160 nlohmann::json::parse (kOptionalOperationRequestFieldJson , nullptr , false );
160161 ASSERT_TRUE (json.is_object ());
161- EXPECT_THAT (
162- DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " , json),
163- Eq (" [(google.api.field_behavior) = "
164- " REQUIRED,(google.cloud.operation_request_field) = "
165- " \" test_field\" ,json_name=\" testField\" ]" ));
162+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " ,
163+ json, false ),
164+ Eq (" [(google.api.field_behavior) = "
165+ " REQUIRED,(google.cloud.operation_request_field) = "
166+ " \" test_field\" ,json_name=\" testField\" ]" ));
166167}
167168
168169TEST (DiscoveryTypeVertexTest, FormatFieldOptionsRequiredIsResource) {
@@ -176,10 +177,10 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsRequiredIsResource) {
176177 auto json =
177178 nlohmann::json::parse (kRequiredIsResourceFieldJson , nullptr , false );
178179 ASSERT_TRUE (json.is_object ());
179- EXPECT_THAT (
180- DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " , json),
181- Eq (" [(google.api.field_behavior) = "
182- " REQUIRED,json_name=\" __json_request_body\" ]" ));
180+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions ( " test_field " , " testField " ,
181+ json, false ),
182+ Eq (" [(google.api.field_behavior) = "
183+ " REQUIRED,json_name=\" __json_request_body\" ]" ));
183184}
184185
185186TEST (DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactString) {
@@ -191,7 +192,7 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactString) {
191192 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
192193 ASSERT_TRUE (json.is_object ());
193194 EXPECT_THAT (
194- DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json),
195+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, false ),
195196 Eq (" [debug_redact = true,json_name=\" rawKey\" ]" ));
196197}
197198
@@ -204,7 +205,7 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactBytes) {
204205 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
205206 ASSERT_TRUE (json.is_object ());
206207 EXPECT_THAT (
207- DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json),
208+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, false ),
208209 Eq (" [debug_redact = true,json_name=\" rawKey\" ]" ));
209210}
210211
@@ -220,7 +221,7 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactArrayString) {
220221 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
221222 ASSERT_TRUE (json.is_object ());
222223 EXPECT_THAT (
223- DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json),
224+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, false ),
224225 Eq (" [debug_redact = true,json_name=\" rawKey\" ]" ));
225226}
226227
@@ -236,7 +237,7 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactArrayBytes) {
236237 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
237238 ASSERT_TRUE (json.is_object ());
238239 EXPECT_THAT (
239- DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json),
240+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, false ),
240241 Eq (" [debug_redact = true,json_name=\" rawKey\" ]" ));
241242}
242243
@@ -248,15 +249,18 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactNonMatches) {
248249)""" ;
249250 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
250251 ASSERT_TRUE (json.is_object ());
251- EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" monkey" , " monkey" , json),
252- Eq (" [json_name=\" monkey\" ]" ));
253252 EXPECT_THAT (
254- DiscoveryTypeVertex::FormatFieldOptions (" keyboard" , " keyboard" , json),
255- Eq (" [json_name=\" keyboard\" ]" ));
256- EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" hockey" , " hockey" , json),
257- Eq (" [json_name=\" hockey\" ]" ));
258- EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" keypad" , " keypad" , json),
259- Eq (" [json_name=\" keypad\" ]" ));
253+ DiscoveryTypeVertex::FormatFieldOptions (" monkey" , " monkey" , json, false ),
254+ Eq (" [json_name=\" monkey\" ]" ));
255+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" keyboard" , " keyboard" ,
256+ json, false ),
257+ Eq (" [json_name=\" keyboard\" ]" ));
258+ EXPECT_THAT (
259+ DiscoveryTypeVertex::FormatFieldOptions (" hockey" , " hockey" , json, false ),
260+ Eq (" [json_name=\" hockey\" ]" ));
261+ EXPECT_THAT (
262+ DiscoveryTypeVertex::FormatFieldOptions (" keypad" , " keypad" , json, false ),
263+ Eq (" [json_name=\" keypad\" ]" ));
260264}
261265
262266TEST (DiscoveryTypeVertexTest,
@@ -268,8 +272,9 @@ TEST(DiscoveryTypeVertexTest,
268272)""" ;
269273 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
270274 ASSERT_TRUE (json.is_object ());
271- EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" key_id" , " keyId" , json),
272- Eq (" [json_name=\" keyId\" ]" ));
275+ EXPECT_THAT (
276+ DiscoveryTypeVertex::FormatFieldOptions (" key_id" , " keyId" , json, false ),
277+ Eq (" [json_name=\" keyId\" ]" ));
273278}
274279
275280TEST (DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactRequired) {
@@ -282,11 +287,52 @@ TEST(DiscoveryTypeVertexTest, FormatFieldOptionsDebugRedactRequired) {
282287 auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
283288 ASSERT_TRUE (json.is_object ());
284289 EXPECT_THAT (
285- DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json),
290+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, false ),
286291 Eq (" [(google.api.field_behavior) = "
287292 " REQUIRED,debug_redact = true,json_name=\" rawKey\" ]" ));
288293}
289294
295+ TEST (DiscoveryTypeVertexTest,
296+ FormatFieldOptionsDebugRedactKeyWithSiblingValueNotRedacted) {
297+ auto constexpr kFieldJson = R"""(
298+ {
299+ "type": "string"
300+ }
301+ )""" ;
302+ auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
303+ ASSERT_TRUE (json.is_object ());
304+ EXPECT_THAT (DiscoveryTypeVertex::FormatFieldOptions (" key" , " key" , json, true ),
305+ Eq (" [json_name=\" key\" ]" ));
306+ }
307+
308+ TEST (DiscoveryTypeVertexTest,
309+ FormatFieldOptionsDebugRedactKeyWithoutSiblingValueRedacted) {
310+ auto constexpr kFieldJson = R"""(
311+ {
312+ "type": "string"
313+ }
314+ )""" ;
315+ auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
316+ ASSERT_TRUE (json.is_object ());
317+ EXPECT_THAT (
318+ DiscoveryTypeVertex::FormatFieldOptions (" key" , " key" , json, false ),
319+ Eq (" [debug_redact = true,json_name=\" key\" ]" ));
320+ }
321+
322+ TEST (DiscoveryTypeVertexTest,
323+ FormatFieldOptionsDebugRedactKeyCompoundWithSiblingValueRedacted) {
324+ auto constexpr kFieldJson = R"""(
325+ {
326+ "type": "string"
327+ }
328+ )""" ;
329+ auto json = nlohmann::json::parse (kFieldJson , nullptr , false );
330+ ASSERT_TRUE (json.is_object ());
331+ EXPECT_THAT (
332+ DiscoveryTypeVertex::FormatFieldOptions (" raw_key" , " rawKey" , json, true ),
333+ Eq (" [debug_redact = true,json_name=\" rawKey\" ]" ));
334+ }
335+
290336struct DetermineTypesSuccess {
291337 std::string name;
292338 std::string json;
@@ -1458,6 +1504,37 @@ TEST_F(DiscoveryTypeVertexDescriptorTest, JsonToProtobufCustomerEncryptionKey) {
14581504 EXPECT_THAT (*result, Eq (kExpectedProto ));
14591505}
14601506
1507+ TEST_F (DiscoveryTypeVertexDescriptorTest, JsonToProtobufMapItemsKeyValuePair) {
1508+ auto constexpr kSchemaJson = R"""(
1509+ {
1510+ "id": "DataItem",
1511+ "properties": {
1512+ "key": {
1513+ "type": "string"
1514+ },
1515+ "value": {
1516+ "type": "string"
1517+ }
1518+ }
1519+ }
1520+ )""" ;
1521+
1522+ auto constexpr kExpectedProto = R"""( message DataItem {
1523+ optional string key = 1 [json_name="key"];
1524+
1525+ optional string value = 2 [json_name="value"];
1526+ }
1527+ )""" ;
1528+
1529+ auto json = nlohmann::json::parse (kSchemaJson , nullptr , false );
1530+ ASSERT_TRUE (json.is_object ());
1531+ DiscoveryTypeVertex t (" DataItem" , " test.package" , json, &pool ());
1532+ std::map<std::string, DiscoveryTypeVertex> types;
1533+ auto result = t.JsonToProtobufMessage (types, " test.package" );
1534+ ASSERT_THAT (result, ::google::cloud::testing_util::IsOk ());
1535+ EXPECT_THAT (*result, Eq (kExpectedProto ));
1536+ }
1537+
14611538} // namespace
14621539} // namespace generator_internal
14631540} // namespace cloud
0 commit comments