Fix #463: Omit empty repository from JSON output for remote-only servers #466
+288
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where remote-only servers (servers with no repository) were still including an empty repository object with blank URL and source fields in their JSON output. This adds unnecessary noise to the API responses.
What Changed
Added omitempty tags to Repository struct fields: The
URL
andSource
fields in the Repository struct now haveomitempty
tags to prevent empty string values from being serialized.Implemented custom MarshalJSON for ServerJSON: A custom marshaling method was added to properly handle the case where a Repository struct is initialized but contains only empty values. This ensures the entire repository field is omitted from the JSON output when all its fields are empty.
Added comprehensive tests: Test coverage was added for both the Repository struct marshaling and the ServerJSON marshaling to verify the behavior works correctly.
Technical Details
The fix uses a two-pronged approach:
omitempty
tags so individual empty fields are omittedThis ensures backward compatibility while fixing the issue for remote-only servers.
Testing
Fixes #463