Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support json tags in embedded structs #1396

Merged
merged 1 commit into from Nov 25, 2022
Merged

Conversation

jgillich
Copy link
Contributor

Describe the PR
This change makes it so json tags on embedded structs are honored.

One example of this:

type RevValueBase struct {
	Status bool `json:"Status"`

	Err int32 `json:"Err,omitempty"`
}
type RevValue struct {
	RevValueBase `json:"rev_value_base"`
}

Previously, RevValueBase was inlined into RevValue. With this change, it matches the behavior of the core json package and the embedded struct becomes a field.

"rev_value_base": {
    "$ref": "#/definitions/web.RevValueBase"
}

It should be noted that this changes the schema generation of embedded structs. However, since it was impossible to unmarshal embedded structs previously, I don't believe this is could cause breakage unless people implemented custom de-serialization.

Relation issue
Fixes #886

@sdghchj
Copy link
Member

sdghchj commented Nov 24, 2022

LGTM, But I'd like to follow @ubogdan 's opinion for this feature.

@codecov
Copy link

codecov bot commented Nov 25, 2022

Codecov Report

Base: 95.10% // Head: 95.03% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (11a00d5) compared to base (29d3d30).
Patch coverage: 85.71% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1396      +/-   ##
==========================================
- Coverage   95.10%   95.03%   -0.07%     
==========================================
  Files          15       15              
  Lines        3062     3064       +2     
==========================================
  Hits         2912     2912              
- Misses         86       87       +1     
- Partials       64       65       +1     
Impacted Files Coverage Δ
parser.go 94.05% <81.81%> (ø)
field_parser.go 97.44% <100.00%> (-0.56%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@ubogdan ubogdan left a comment

Choose a reason for hiding this comment

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

LGTM

@ubogdan
Copy link
Contributor

ubogdan commented Nov 25, 2022

LGTM, But I'd like to follow @ubogdan 's opinion for this feature.

As soon as it doesn't break older contract I'm fine.

@ubogdan ubogdan merged commit 80d5221 into swaggo:master Nov 25, 2022
@ubogdan
Copy link
Contributor

ubogdan commented Nov 25, 2022

@jgillich Thanks for your contribution.

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.

Support embedded struct with json tag
3 participants