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

Struct fields supported for header and path param types #1740

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

tanenbaum
Copy link
Contributor

@tanenbaum tanenbaum commented Jan 15, 2024

Describe the PR
Supports "object" (i.e. struct model) data types for header and path parameter types via @Param operation comment in the same way that query and formData already work - basic structs are supported to represent multiple paramters at once.

This allows struct models, e.g. for a number of related headers, to be used directly rather than duplicating all the @Param comments for every field in those structs.

This works similarly to existing formData and query types and largely reuses all the same operation parsing logic.

In addition this supports using struct tags header:"name" and uri:"name" for header and path params respectively. This follows the Gin specific tag naming conventions.

Relation issues
A few issues with similar feature requests:

@tanenbaum tanenbaum changed the title Joe/path header struct support Object data type support for header and path param types Jan 15, 2024
@tanenbaum
Copy link
Contributor Author

tanenbaum commented Jan 16, 2024

Looking at rebasing this and fixing the conflicts - I'm not sure if the change introduced in #1706 return strings.TrimRight(strings.TrimSpace(strings.Split(ps.tag.Get(formTag), ",")[0]), "[]") is in fact backwards compatible - what about API definitions where people want to include the [] characters at the end of their parameter names? While not common, it could cause unwanted doc changes.

@sdghchj what do you think about this? Should all the fields trim "[]"? I'm not so sure.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (76695ca) 83.25% compared to head (c7eb9f5) 83.32%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1740      +/-   ##
==========================================
+ Coverage   83.25%   83.32%   +0.06%     
==========================================
  Files          16       16              
  Lines        3811     3815       +4     
==========================================
+ Hits         3173     3179       +6     
+ Misses        542      541       -1     
+ Partials       96       95       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tanenbaum tanenbaum changed the title Object data type support for header and path param types Struct fields supported for header and path param types Jan 17, 2024
@sdghchj sdghchj requested a review from ubogdan January 18, 2024 06:49
@sdghchj
Copy link
Member

sdghchj commented Jan 19, 2024 via email

@tanenbaum tanenbaum force-pushed the joe/path_header_struct_support branch from 42d478d to c7eb9f5 Compare January 21, 2024 12:08
@tanenbaum
Copy link
Contributor Author

tanenbaum commented Jan 21, 2024

[] is trivial, make nonsense.  trim them.

Fair enough - rebased and updated.

@sdghchj sdghchj merged commit d4218f2 into swaggo:master Jan 22, 2024
12 checks passed
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