Skip to content

fix(canonical): prevent non-deterministic field name qualification when field name collides with record type name - #314

Open
reginaldalfret wants to merge 1 commit into
linkedin:masterfrom
reginaldalfret:linkedin/issue-307-deterministic-canonical-schema
Open

reginaldalfret wants to merge 1 commit into
linkedin:masterfrom
reginaldalfret:linkedin/issue-307-deterministic-canonical-schema

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

Fixes non-deterministic canonical schema generation in CanonicalSchema() when a field name and a record type name share the same local name within the same namespace.

Problem

In canonical.go, pcfObject processes JSON objects and namespace-qualifies any "name" property while populating typeLookup. When a field object (e.g. {"name": "items", ...}) was processed, its declared field name was incorrectly registered in typeLookup as a named type (com.example.items). Due to non-deterministic Go map iteration order, if items was registered before pcfString evaluated the field's "name" attribute, the field name "items" was replaced with "com.example.items".

Solution

  • Gate "name" property qualification and typeLookup registration in pcfObject so it only applies to actual named types (record, enum, fixed).
  • Format "name" attribute key-value pairs directly without looking up declared name values in typeLookup.
  • Added unit test regression in canonical_test.go covering same-named field and record type schemas.

Testing

  • Ran go test ./... and go test -v -run TestCanonicalSchema -count=100 .. All tests passed cleanly.

Related Issue

Closes #307

…en field name collides with record type name

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CanonicalSchema() is non-deterministic when a field name matches a record type name in the same namespace

1 participant