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

feat: parse only specific extension tag #1219

Merged
merged 5 commits into from
Dec 11, 2022

Conversation

igorkova
Copy link
Contributor

@igorkova igorkova commented Jun 2, 2022

Describe the PR
Enable parsing (output) of specific operations which have specific tag (extension).

Relation issue
#661

Additional context

@igorkova igorkova closed this Jun 2, 2022
@igorkova
Copy link
Contributor Author

igorkova commented Jun 2, 2022

This is not 100% ready yet. Let us get back

@ubogdan ubogdan reopened this Jun 2, 2022
@codecov
Copy link

codecov bot commented Jun 2, 2022

Codecov Report

Base: 85.16% // Head: 85.22% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (4d33118) compared to base (3fe9ca2).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1219      +/-   ##
==========================================
+ Coverage   85.16%   85.22%   +0.06%     
==========================================
  Files          19       19              
  Lines        3620     3635      +15     
==========================================
+ Hits         3083     3098      +15     
  Misses        459      459              
  Partials       78       78              
Impacted Files Coverage Δ
gen/gen.go 93.51% <100.00%> (+0.03%) ⬆️
parser.go 94.39% <100.00%> (+0.09%) ⬆️

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.

@sid-rpf
Copy link

sid-rpf commented Jun 7, 2022

This is a nice and must-have feature. 👍

@ubogdan
Copy link
Contributor

ubogdan commented Jun 16, 2022

@igorkova let me know when you are done with this.

@igorkova
Copy link
Contributor Author

igorkova commented Dec 7, 2022

@ubogdan This is done as far as we are concerned.
It covers all of our needs

Example usage will be swag --parseExtension google-backend which will take all routes which have // @x-google-backend comment and export them in a separate file.
That file we can then take and forward to ESPV2 and by doing that we can control which endpoints are exposed on the gateway (or any other external openAPI definition) vs those which will be exposed internally

@igorkova
Copy link
Contributor Author

igorkova commented Dec 7, 2022

@ubogdan great if we can get workflow approved 🙌

Previous implementation had an issue where it was excluding operation after schema
and other parts were parsed. That caused schema definition to be included in the
output file, even though operation didn't match the extension.

New implementation won't even start processing operation if extension isn't matching.

Only potential issue/problem I see with this approach is that we are duplicating logic
for comment line parsing (I basically c/p it from other places) but not sure how big
of an issue that actually is as I noticed we are doing that at other places as well.
}
return true
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing you are using from the parser is parser.ParseExtension, This function is a mimic of in_array func in_array(val string, array []string) bool with default to true if the search value is empty.

Such a simple function should not be attached to the parser.

func matchExtension(textToFind string, comments []*ast.Comment) bool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.
I was basically c/p above matchTags without too much thinking. you have a good point.

I can detach it from the parser, before that just to double check do you recommend to create a "helper" in_array-type method or still keep it specific to extension parsing? (Not sure if we have such a helper file/methods today somewhere - can't find them in the repo)

Copy link
Contributor

Choose a reason for hiding this comment

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

Just detach the function from the parser.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.

@ubogdan
Copy link
Contributor

ubogdan commented Dec 11, 2022

Great job till now.

@ubogdan ubogdan merged commit 7c20f30 into swaggo:master Dec 11, 2022
@ubogdan
Copy link
Contributor

ubogdan commented Dec 11, 2022

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

3 participants