Skip to content

refactor: optimize JSON parsing for core types#321

Open
nahapetyan-serob wants to merge 3 commits intomainfrom
serob/json-parsing-for-types
Open

refactor: optimize JSON parsing for core types#321
nahapetyan-serob wants to merge 3 commits intomainfrom
serob/json-parsing-for-types

Conversation

@nahapetyan-serob
Copy link
Copy Markdown
Collaborator

@nahapetyan-serob nahapetyan-serob commented Apr 14, 2026

Refactor custom JSON marshal/unmarshal logic across core.go and auth.go to use typed wrapper structs instead of type discriminator patterns.
Behavioral Change: Empty URLs are now skipped during part serialization instead of being serialized as empty strings.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors JSON marshaling and unmarshaling logic for several types, including SecurityRequirementsOptions, NamedSecuritySchemes, OAuth2SecurityScheme, StreamResponse, and Part. The changes replace anonymous types and generic maps with dedicated private wrapper structs to improve type safety and simplify validation. Feedback was provided regarding Part.UnmarshalJSON, noting that it should validate that exactly one content field is present to prevent potential nil interface assignments and ensure adherence to API specifications.

Comment thread a2a/core.go
Comment thread a2a/core.go Outdated
Comment thread a2a/core.go
Comment thread a2a/auth.go Outdated
Comment thread a2a/auth.go
type oauth2 struct {
Description string `json:"description,omitempty"`
Oauth2MetadataURL string `json:"oauth2MetadataUrl,omitempty"`
Flows oauthFlows `json:"flows"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

have we deliberately removed omitempty?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, flows is a required filed in OAuth2SecurityScheme, so I kept the same for the wrapper as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants