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

Implement error (and any) like interface #1212

Merged
merged 5 commits into from Jun 16, 2022

Conversation

sapk
Copy link
Contributor

@sapk sapk commented May 22, 2022

This manage error and any like interface.

Previously, any would result in a primitive type any which seem not valid in swagger definition.

This basically, set an empty definition like for interface{} previously for any and error types.

Relation issue

Additional context
This fix cases when you cannot override with tag swaggertype in case the struct is from an external dependency.
Previously this case need to redefine the struct locally to override the field type but can be cumbersome in case of deeply nested struct and It is also not possible to override go types with .swaggo file.

I first try to implement like suggested in this comment but after reviewing some cases (like in the testdata test) this feel better and more logical to consider error (and any) like interface. Let me know if it doesn't fit you.

@codecov
Copy link

codecov bot commented May 23, 2022

Codecov Report

Merging #1212 (1e6f665) into master (e767abb) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1212      +/-   ##
==========================================
- Coverage   95.02%   94.96%   -0.07%     
==========================================
  Files          12       12              
  Lines        2515     2524       +9     
==========================================
+ Hits         2390     2397       +7     
- Misses         68       69       +1     
- Partials       57       58       +1     
Impacted Files Coverage Δ
parser.go 93.57% <100.00%> (+0.01%) ⬆️
schema.go 100.00% <100.00%> (ø)
field_parser.go 98.54% <0.00%> (-0.57%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e767abb...1e6f665. Read the comment docs.

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.

Good job! Please write unit test to cover new added functionality

Comment on lines +871 to +873
if IsInterfaceLike(typeName) {
return &spec.Schema{}, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to cover this with unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should already be covered by TestGen_ErrorAndInterface and TestIsInterfaceLike but I can recheck.

Copy link
Contributor Author

@sapk sapk May 25, 2022

Choose a reason for hiding this comment

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

I added a test similar to TestGen_ErrorAndInterface based on testdata in the root package.

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 ubogdan merged commit 213f6b8 into swaggo:master Jun 16, 2022
@sapk sapk deleted the error-like-interface branch June 16, 2022 10:00
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.

None yet

2 participants