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

fix: split extensions param respecting open/close brackets #1107

Merged
merged 4 commits into from
Feb 7, 2022

Conversation

helder-jaspion
Copy link
Contributor

@helder-jaspion helder-jaspion commented Jan 20, 2022

Describe the PR
split extensions param respecting open/close brackets
// @Param range query string true "Range" default([0, 9]) extensions(x-example=[0,9])

Relation issue
None.

Additional context
When using extensions param with text containing comma the extensions were getting splited wrong.

@ubogdan
Copy link
Contributor

ubogdan commented Jan 20, 2022

It this PR related to any open issue?

@helder-jaspion
Copy link
Contributor Author

No. I needed to use extensions params and had problems with texts containing comma and then opened this PR.

@helder-jaspion
Copy link
Contributor Author

@ubogdan could you please approve running the workflows?

@ubogdan
Copy link
Contributor

ubogdan commented Jan 28, 2022

@ubogdan could you please approve running the workflows?

It seems I missed this notification.

@codecov
Copy link

codecov bot commented Jan 28, 2022

Codecov Report

Merging #1107 (b76c3af) into master (32f02b9) will increase coverage by 0.13%.
The diff coverage is 94.73%.

❗ Current head b76c3af differs from pull request most recent head c9cb002. Consider uploading reports for the commit c9cb002 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1107      +/-   ##
==========================================
+ Coverage   94.59%   94.73%   +0.13%     
==========================================
  Files           9       10       +1     
  Lines        2370     2433      +63     
==========================================
+ Hits         2242     2305      +63     
  Misses         67       67              
  Partials       61       61              
Impacted Files Coverage Δ
field_parser.go 98.82% <87.50%> (-1.18%) ⬇️
formater.go 100.00% <100.00%> (ø)
gen/gen.go 93.33% <100.00%> (+0.29%) ⬆️
operation.go 95.91% <100.00%> (+0.05%) ⬆️
spec.go 100.00% <100.00%> (ø)
packages.go 85.87% <0.00%> (+2.25%) ⬆️

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 32f02b9...c9cb002. Read the comment docs.

field_parser.go Outdated
@@ -207,7 +207,9 @@ func (ps *tagBaseFieldParser) ComplementSchema(schema *spec.Schema) error {
extensionsTag := ps.tag.Get(extensionsTag)
if extensionsTag != "" {
structField.extensions = map[string]interface{}{}
extensionsTag := strings.ReplaceAll(extensionsTag, `,,`, `{{escape-comma}}`)
for _, val := range strings.Split(extensionsTag, ",") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding double-quoted is an ugly hack.

The solution is to line instead of split by comma by respection open/close brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. double-comma was a quick fix. I'll try the solution you suggested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as suggested

@helder-jaspion helder-jaspion changed the title feat: escape comma with double comma (,,) in extensions param fix: split extensions param respecting open/close brackets Feb 7, 2022
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 3a778dc into swaggo:master Feb 7, 2022
@ubogdan
Copy link
Contributor

ubogdan commented Feb 7, 2022

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

2 participants