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

Add operationId uniqueness check #732

Merged
merged 7 commits into from
Jun 18, 2020

Conversation

idexter
Copy link
Contributor

@idexter idexter commented Jun 10, 2020

Describe the PR

Add operationId uniqueness check, in accordance with OpenAPI v2 Specification

Relation issue

Closes #731

Additional context

I added a uniqueness check after the parsing phase, so it shows a path when an error happens (E.g. GET /foo/bar) but did not show the file where duplication happens.

I did that in this way because I did not succeed adding check inside ParseRouterAPIInfo(). The reason I did not succeed is that because when you are going through this range:

swag/parser.go

Lines 171 to 175 in 67cb097

for fileName, astFile := range parser.files {
if err := parser.ParseRouterAPIInfo(fileName, astFile); err != nil {
return err
}
}

parser.files can contain the same file twice. Once with absolute path and once with a relative path. So in some situations, errors happens even if there are no duplications in operationId

@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2020

Codecov Report

Merging #732 into master will increase coverage by 2.14%.
The diff coverage is 48.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #732      +/-   ##
==========================================
+ Coverage   81.50%   83.65%   +2.14%     
==========================================
  Files           8        7       -1     
  Lines        1665     1835     +170     
==========================================
+ Hits         1357     1535     +178     
+ Misses        195      189       -6     
+ Partials      113      111       -2     
Impacted Files Coverage Δ
parser.go 78.41% <48.83%> (+1.28%) ⬆️
operation.go 87.56% <0.00%> (-0.90%) ⬇️
types.go
packages.go
property.go 91.66% <0.00%> (ø)
schema.go 96.82% <0.00%> (+10.07%) ⬆️

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 c5fb1a1...124d4a4. Read the comment docs.

Copy link
Member

@sdghchj sdghchj left a comment

Choose a reason for hiding this comment

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

LGTM in function.
however, operationsIds is better to be in a local scope.

@idexter
Copy link
Contributor Author

idexter commented Jun 12, 2020

however, operationsIds is better to be in a local scope.

@sdghchj I tried to move it inside the checkOperationIDUniqueness() function. Is that thing you was talking about?

https://github.com/swaggo/swag/pull/732/files#diff-f615844d3497ff38db57e459d6ef657bR1508-R1521

@sdghchj
Copy link
Member

sdghchj commented Jun 12, 2020

however, operationsIds is better to be in a local scope.

@sdghchj I tried to move it inside the checkOperationIDUniqueness() function. Is that thing you was talking about?

https://github.com/swaggo/swag/pull/732/files#diff-f615844d3497ff38db57e459d6ef657bR1508-R1521

That's it

Copy link
Member

@sdghchj sdghchj left a comment

Choose a reason for hiding this comment

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

LGTM

@easonlin404 easonlin404 merged commit 366e536 into swaggo:master Jun 18, 2020
@easonlin404
Copy link
Member

@idexter Thanks for your contributions.

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.

Add "operationId" uniqueness check
4 participants