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

Extended generics support #1277

merged 8 commits into from Aug 2, 2022


Copy link

Describe the PR
Extends the generic support for go 1.8

  1. Adds support for nested generics (generic[string, generic[int]])
  2. Adds support for array parameter on generics (generic[string, []string])
  3. Adds support for generic properties on structs
  4. Adds support for built-in types in generics

Relation issue

Additional context
All changes are backward compatible and have been tested with Go 1.15, 1.16, 1.17 and 1.18.4. It is possible that other issues, besides the ones mentioned, have been fixed.

nested generics support and related tests added
- allow usage of arrays as parameter definitions
- tests extended and new body param added to tests
- get generic field type
- support built in types in structs

refs swaggo#1213
@FabianMartin FabianMartin changed the title Generics support Extended generics support Jul 31, 2022
add prefix to generic model names, to prevent renaming, if name annotation exists
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #1277 (a341fc4) into master (cc25410) will increase coverage by 0.11%.
The diff coverage is 92.48%.

Current head a341fc4 differs from pull request most recent head 68fbadb. Consider uploading reports for the commit 68fbadb to get more accurate results

@@            Coverage Diff             @@
##           master    #1277      +/-   ##
+ Coverage   94.84%   94.95%   +0.11%     
  Files          14       14              
  Lines        2620     2717      +97     
+ Hits         2485     2580      +95     
- Misses         74       78       +4     
+ Partials       61       59       -2     
Impacted Files Coverage Δ
generics_other.go 66.66% <66.66%> (+16.66%) ⬆️
generics.go 94.30% <92.17%> (+3.25%) ⬆️
operation.go 95.94% <100.00%> (-0.73%) ⬇️
packages.go 89.94% <100.00%> (+2.64%) ⬆️
parser.go 93.71% <100.00%> (+0.12%) ⬆️
schema.go 100.00% <100.00%> (ø)

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 cc25410...68fbadb. Read the comment docs.

Copy link

@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 so far. Please update according to the comments.

generics.go Show resolved Hide resolved
generics.go Outdated Show resolved Hide resolved
generics.go Show resolved Hide resolved
- The first underscore was replaced instead of checking if the generated name even starts with the package name.
- New Tests added to test the name generation
- schema test extended to test the new behavior
Copy link
Contributor Author

Hi @ubogdan,
thanks for the feedback. I have made the suggested changes and added new tests.

Copy link

@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.


@ubogdan ubogdan merged commit 2f148dd into swaggo:master Aug 2, 2022
10 checks passed
Copy link

ubogdan commented Aug 2, 2022

@FabianMartin Thanks for your contribution.

@FabianMartin FabianMartin deleted the generics-support branch August 2, 2022 16:41
Copy link

Fantastic, much appreciated @FabianMartin ! Looking forward to this getting released so that I can try it with my generic structs that's currently not being picked up correctly 🙏 @ubogdan do you have any publicly available release schedule?

With any luck this might also solve #1253

Copy link
Contributor Author

@johan-lejdung Thank you for your feedback. A fix for your issue is included in PR #1281.

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

Successfully merging this pull request may close these issues.

None yet

3 participants