Skip to content

Omit XML tags#482

Merged
jakub-id merged 1 commit intomainfrom
omit-xml-tags
Mar 25, 2026
Merged

Omit XML tags#482
jakub-id merged 1 commit intomainfrom
omit-xml-tags

Conversation

@jakub-id
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 11:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the common.StructToMap helper to omit fields explicitly ignored via JSON tags (e.g., metadata fields like XMLName), preventing them from appearing in map-converted API payloads.

Changes:

  • Skip struct fields tagged with json:"-" when converting a struct to map[string]any.
  • Add unit test coverage to ensure json:"-" fields are omitted.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
broker/common/common.go Updates StructToMap to ignore json:"-" fields.
broker/common/common_test.go Adds a test ensuring ignored fields (e.g., XMLName) are skipped.
Comments suppressed due to low confidence (1)

broker/common/common.go:39

  • StructToMap treats any json tag with options (i.e. containing a comma) as an explicit field name, but json:",omitempty" (empty name) is valid and should fall back to the struct field name per encoding/json rules. As written, this would produce an empty-string map key. Consider only overriding fieldName with the part before the comma when that part is non-empty (and not "-").
			before, _, found := strings.Cut(jsonTag, ",")
			if before == "-" {
				continue
			}
			if found {
				fieldName = before
			} else {
				fieldName = jsonTag
			}

@jakub-id jakub-id merged commit e61c138 into main Mar 25, 2026
8 checks passed
@jakub-id jakub-id deleted the omit-xml-tags branch March 25, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants