Skip to content

Comments

fix: handle nested Metadata types in structpb conversion #63

Merged
mfiedorowicz merged 2 commits intodevelopfrom
fix-flatten-metadata
Feb 5, 2026
Merged

fix: handle nested Metadata types in structpb conversion #63
mfiedorowicz merged 2 commits intodevelopfrom
fix-flatten-metadata

Conversation

@mfiedorowicz
Copy link
Member

This pull request improves how entity metadata is handled when converting to protobuf Struct objects. Specifically, it introduces a helper function to recursively convert nested Metadata maps, ensuring that all nested metadata is properly processed. This change is applied across all entity types that expose metadata, making metadata serialization more robust and reliable.

Key changes:

Metadata Handling Improvements

  • Added a new helper function convertMetadata to recursively convert Metadata (including nested Metadata values) to map[string]any, ensuring compatibility with structpb.NewStruct.
  • Updated all entity GetMetadata methods (e.g., ASN, ASNRange, Aggregate, Cable, CablePath, CableTermination, Circuit, CircuitGroup, CircuitGroupAssignment, CircuitTermination, CircuitType, Cluster, ClusterGroup, ClusterType, ConsolePort, ConsoleServerPort, Contact, ContactAssignment, ContactGroup, ContactRole, Device, DeviceBay, DeviceRole, DeviceType, FHRPGroup, FHRPGroupAssignment, FrontPort, IKEPolicy, IKEProposal, IPAddress, IPRange, IPSecPolicy, IPSecProfile, IPSecProposal, Interface) to use convertMetadata before calling structpb.NewStruct, ensuring correct handling of nested metadata. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35]

Other

  • Updated the generated code timestamp.

Add convertMetadata helper function to recursively convert nested
Metadata type values to map[string]any before passing to structpb.NewStruct,
which doesn't recognize the Metadata type alias for nested maps.
Add unit tests for the convertMetadata function and integration test
verifying nested Metadata types are properly converted to protobuf structs.
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 0.00s github.com/netboxlabs/diode-sdk-go/cmd/diode-replay-dryrun 0.0% 0 0 0
🟢 PASS 1.60s github.com/netboxlabs/diode-sdk-go/diode 21.1% 315 0 0

Total coverage: 74.5%

@mfiedorowicz mfiedorowicz merged commit f8eace7 into develop Feb 5, 2026
6 checks passed
@mfiedorowicz mfiedorowicz deleted the fix-flatten-metadata branch February 5, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants