fix(api): add JSON tags to TripDetailResp and PlaceDetailsResp - #420
Open
Ronnie434 wants to merge 1 commit into
Open
fix(api): add JSON tags to TripDetailResp and PlaceDetailsResp#420Ronnie434 wants to merge 1 commit into
Ronnie434 wants to merge 1 commit into
Conversation
These two structs lacked JSON tags, causing Go to serialize field names in PascalCase (e.g. OriginalPlanID, LatLongs, PlaceDetails). This made it impossible for frontend clients to reliably parse the response using standard snake_case conventions. Also marks ApiKey with json:"-" to prevent it from being exposed in API responses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
TripDetailRespandPlaceDetailsRespstructs lack JSON struct tags, causing Go'sencoding/jsonto serialize field names in PascalCase (e.g.OriginalPlanID,LatLongs,PlaceDetails). This is inconsistent with every other response struct in the codebase (PlanningResponse,TravelPlan,TimeSectionPlace, etc.) which all use snake_case JSON tags.This makes it difficult for frontend clients to parse the
/plans/:idand/users/plan/:idendpoints reliably, since all other endpoints return snake_case keys.Before (no JSON tags):
{ "OriginalPlanID": "abc-123", "LatLongs": [[37.31, -121.95]], "PlaceDetails": [{"ID": "...", "Name": "...", "PhotoURL": "..."}], "ApiKey": "EXPOSED_KEY" }After (with JSON tags):
{ "original_plan_id": "abc-123", "lat_longs": [[37.31, -121.95]], "place_details": [{"id": "...", "name": "...", "photo_url": "..."}], }Changes
json:"snake_case"tags to all fields ofTripDetailRespandPlaceDetailsRespApiKeywithjson:"-"to prevent it from being exposed in API responses (security fix)Testing
go build ./...