-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-4094: [C#] Updating mapped namespaces referenced in types #3247
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Paul Podgorsek <[email protected]>
Co-authored-by: Paul Podgorsek <[email protected]>
{ | ||
return mapping.Value; | ||
} | ||
else if (originalNamespace.StartsWith($"{mapping.Key}.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls String.StartsWith(String), which uses StringComparison.CurrentCulture; but should instead use StringComparison.Ordinal.
With StringComparison.CurrentCulture, it is possible that originalNamespace.StartsWith($"{mapping.Key}.")
returns true but originalNamespace.Length < $"{mapping.Key}.".Length
, which would then cause the subsequent Substring call to throw. This would happen if mapping.Key
includes characters that are ignored in linguistic comparisons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point- I've updated this to use Ordinal comparison now
// Recurse into all properties of the object | ||
foreach (var property in obj.Properties()) | ||
{ | ||
UpdateNamespacesInJToken(property.Value, namespaceMapping); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will replace namespace-looking strings in "type" properties even within the "default" property of a field. Those should not be modified because they affect the meaning of the schema, rather than only the local code generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a list of properties which shouldn't be considered for the namespace mapping such as default/ doc/ symbols and a few others- However I'd disagree on type
- this is a property which could have a namespace and I've an example of this in the test I included as part of this PR
Changing string comparison in ReplaceNamespace to use Ordinal string comparison Adding blacklist for unqualified props which we shouldn't be looking to do any namespace replaces on
What is the purpose of the change
Fixing AVRO-4094 - The use of namespace mappings currently updates namespaces, but not types that reference the namespace in the type name. This PR resolves that.
Due to the complexity of the type attribute, being either simple strings, arrays or complex types- potentially even nested combinations of the above, I use newtonsoft to build the object and recursively walk properties as opposed to the regex approach used in the namespace replacement. This feels a far more maintainable approach given this level of potential complexity.
Verifying this change
This change added tests and can be verified as follows:
Documentation