fix: JSON marshal errors of parameters with optional structs#1427
Merged
ernado merged 6 commits intoogen-go:mainfrom Oct 3, 2025
Merged
fix: JSON marshal errors of parameters with optional structs#1427ernado merged 6 commits intoogen-go:mainfrom
ernado merged 6 commits intoogen-go:mainfrom
Conversation
4b1ce7c to
250c197
Compare
|
has everyone just given up on this by now? |
Member
|
Hey @maelick, very sorry for late responce. |
250c197 to
e10e57b
Compare
Contributor
Author
|
@ernado I rebased on main, but the template changes in #1446 were incompatible and non-trivial to solve. I fixed them by removing the |
Update parameter integration test with: * new /optionalParameters endpoint in test spec * add empty handler for new endpoint * add test for logging and marshaling params
Generated parameter structs have field tags omitempty and/or omitzero annotations: * omitempty for slices, maps and non-optional nullable fields * omitempty and omitzero for optional nullable fields * nothing for other fields
…olving conflicts with ogen-go#1446
fd3bf54 to
db90e0f
Compare
Contributor
Author
|
Fixed the linting issue with imports ordering and the missing regenerated example. |
ernado
approved these changes
Oct 3, 2025
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.
I experienced an issue similar to #660 when passing a parameter struct to stdlib slog (using a JSONHandler).
From what I was able to reproduce, the error occurs when calling encoding/json.Marshal on missing optional parameters that the Opt* struct is used in response types. The problem does not seem to occur if there are no response objects including the optional type (because the Encode/Decode methods are not generated on the Opt* types).
For me the error occurred when using slog with a JSONHandler inside an ogen handler:
Which gives this type of log output:
{"time":"2025-03-17T16:13:56.22672301+01:00","level":"INFO","msg":"test","params":"!ERROR:json: error calling MarshalJSON for type api.OptInt: unexpected end of JSON input"}This PR includes:
OptStringstruct #660Notes:
I didn't change the minimum Go version in go.mod