github-advanced-security[bot] commented on code in PR #3247:
URL: https://github.com/apache/avro/pull/3247#discussion_r1954271858
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -1266,5 +1273,102 @@
return
$@"""namespace""{m.Groups[1].Value}:{m.Groups[2].Value}""{ns}""";
});
}
+ /// <summary>
+ /// Replace namespaces in a parsed JSON schema object for all "type"
fields.
+ /// </summary>
+ /// <param name="schemaJson">The JSON schema as a string.</param>
+ /// <param name="namespaceMapping">The mapping of old namespaces to new
namespaces.</param>
+ /// <returns>The updated JSON schema as a string.</returns>
+ private static string ReplaceMappedNamespacesInSchemaTypes(string
schemaJson, IEnumerable<KeyValuePair<string, string>> namespaceMapping)
+ {
+ if (string.IsNullOrWhiteSpace(schemaJson) || namespaceMapping == null)
+ {
+ return schemaJson;
+ }
+
+ var schemaToken = JToken.Parse(schemaJson);
+
+ UpdateNamespacesInJToken(schemaToken, namespaceMapping);
+
+ return schemaToken.ToString(Formatting.Indented);
}
+
+ /// <summary>
+ /// Recursively navigates and updates "type" fields in a JToken.
+ /// </summary>
+ /// <param name="token">The current JToken to process.</param>
+ /// <param name="namespaceMapping">The mapping of old namespaces to new
namespaces.</param>
+ private static void UpdateNamespacesInJToken(JToken token,
IEnumerable<KeyValuePair<string, string>> namespaceMapping)
+ {
+ if (token is JObject obj)
+ {
+ if (obj.ContainsKey("type"))
Review Comment:
## Inefficient use of ContainsKey
Inefficient use of 'ContainsKey' and [indexer](1).
[Show more
details](https://github.com/apache/avro/security/code-scanning/3302)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]