@@ -48,20 +48,16 @@ std::optional<std::string> CheckForScalarType(nlohmann::json const& j) {
4848bool IsStringOrBytes (nlohmann::json const & field_json) {
4949 std::string const type = field_json.value (" type" , " " );
5050 if (type == " string" || type == " bytes" ) return true ;
51- if (type == " array" && field_json.contains (" items" ) &&
52- field_json[" items" ].is_object ()) {
51+ if (type == " array" && field_json.contains (" items" )) {
5352 std::string const item_type = field_json[" items" ].value (" type" , " " );
5453 if (item_type == " string" || item_type == " bytes" ) return true ;
5554 }
5655 return false ;
5756}
5857
5958bool ContainsKeyWord (std::string_view s) {
60- for (std::size_t pos = s.find (" key" ); pos != std::string_view::npos;
61- pos = s.find (" key" , pos + 1 )) {
62- bool const prefix_ok = (pos == 0 || s[pos - 1 ] == ' _' );
63- bool const suffix_ok = (pos + 3 == s.size () || s[pos + 3 ] == ' _' );
64- if (prefix_ok && suffix_ok) return true ;
59+ for (auto const & token : absl::StrSplit (s, ' _' )) {
60+ if (token == " key" ) return true ;
6561 }
6662 return false ;
6763}
@@ -133,7 +129,7 @@ DiscoveryTypeVertex::DetermineTypeAndSynthesis(nlohmann::json const& v,
133129 }
134130
135131 if (type == " any" ) {
136- if (v.contains (" format" ) && v[ " format " ]. is_string () ) {
132+ if (v.contains (" format" )) {
137133 type = v[" format" ];
138134 } else {
139135 type = " google.protobuf.Value" ;
@@ -174,11 +170,9 @@ DiscoveryTypeVertex::DetermineTypeAndSynthesis(nlohmann::json const& v,
174170 properties_for_synthesis = &additional_properties;
175171 is_message = true ;
176172 } else if (map_type == " any" ) {
177- if (additional_properties.is_object () &&
178- additional_properties.contains (" format" ) &&
179- additional_properties[" format" ].is_string ()) {
173+ if (additional_properties.contains (" format" )) {
180174 map_type = additional_properties[" format" ];
181- } else if (v.contains (" format" ) && v[ " format " ]. is_string () ) {
175+ } else if (v.contains (" format" )) {
182176 map_type = v[" format" ];
183177 } else {
184178 map_type = " google.protobuf.Struct" ;
@@ -219,26 +213,21 @@ DiscoveryTypeVertex::DetermineTypeAndSynthesis(nlohmann::json const& v,
219213 if (scalar_type) {
220214 type = *scalar_type;
221215 } else if (type == " any" ) {
222- if (items.is_object () && items.contains (" format" ) &&
223- items[" format" ].is_string ()) {
216+ if (items.contains (" format" )) {
224217 type = items[" format" ];
225218 } else {
226219 type = " google.protobuf.Value" ;
227220 }
228221 return TypeInfo{type, compare_package_name, nullptr , false , false };
229- } else if (type == " object" && items.is_object () &&
230- items.contains (" properties" )) {
222+ } else if (type == " object" && items.contains (" properties" )) {
231223 // Synthesize a nested type for this array.
232224 type = CapitalizeFirstLetter (field_name + " Item" );
233225 return TypeInfo{type, compare_package_name, &items, false , true };
234- } else if (type == " object" && items.is_object () &&
235- items.contains (" additionalProperties" ) &&
236- items[" additionalProperties" ].is_object () &&
237- items[" additionalProperties" ].value (" type" , " " ) == " any" ) {
238- if (items.contains (" format" ) && items[" format" ].is_string ()) {
226+ } else if (type == " object" && items.contains (" additionalProperties" ) &&
227+ (items[" additionalProperties" ]).value (" type" , " " ) == " any" ) {
228+ if (items.contains (" format" )) {
239229 type = items[" format" ];
240- } else if (items[" additionalProperties" ].contains (" format" ) &&
241- items[" additionalProperties" ][" format" ].is_string ()) {
230+ } else if (items[" additionalProperties" ].contains (" format" )) {
242231 type = items[" additionalProperties" ][" format" ];
243232 } else {
244233 type = " google.protobuf.Struct" ;
0 commit comments