-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
added function in openapi3.operation #370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! 🥳
Please fix formatting and add some tests to check that it works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need some tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better, thank you!
But you've made weird choices for testing. Please test your feature, not an helper function! This does not make sense, is there any reason?
Hii @EwenQuim sorry for the mistakes i did previously. I have made some changes,Can you have a look at them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, when submitting a PR, re-read yourself. There are a lot of things you could have seen yourself.
When submitting a PR, you can click on the "Files changed" tab and review your changes. There, you'll see that there are a lot of changes that are useless, typos or mistakes. Reviewing yourself before asking for a maintainer to review is something usual in CS, don't hesitate to get used to it :)
I hope you'll understand!
Hii @EwenQuim I am extremely sorry because make lint is not working in in laptop so i am not aware of the linting errors if they are present.That is why i reduced the newlines as they were showing me lint error in the actions. |
No problem! What is not working when you run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice! Just a few comments but we're almost there! Thank you for your great work! 🥳
openapi.go
Outdated
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists != nil { | ||
continue | ||
} | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
if strings.HasSuffix(pathParam, "...") { | ||
parameter.Description += " (might contain slashes)" | ||
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists == nil { | ||
if strings.Contains(route.Path, "{"+pathParam+"}") { | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
route.Operation.AddParameter(parameter) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change it? Did you spot any bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of my test was failing so i had to modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why resolved???
Fixed tests to make them test the right behaviour
I've removed some useless changes and used Thanks a lot @TheRanomial for setting up the structure of all this, this was very useful! Don't hesitate to look at my commits and the current PR. @dylanhitt what do you think about it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this looks great. Not sure what you want to do about that linting issue though.
openapi.go
Outdated
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists != nil { | ||
continue | ||
} | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
if strings.HasSuffix(pathParam, "...") { | ||
parameter.Description += " (might contain slashes)" | ||
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists == nil { | ||
if strings.Contains(route.Path, "{"+pathParam+"}") { | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
route.Operation.AddParameter(parameter) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one?
openapi.go
Outdated
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists != nil { | ||
continue | ||
} | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
if strings.HasSuffix(pathParam, "...") { | ||
parameter.Description += " (might contain slashes)" | ||
if exists := route.Operation.Parameters.GetByInAndName("path", pathParam); exists == nil { | ||
if strings.Contains(route.Path, "{"+pathParam+"}") { | ||
parameter := openapi3.NewPathParameter(pathParam) | ||
parameter.Schema = openapi3.NewStringSchema().NewRef() | ||
route.Operation.AddParameter(parameter) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why resolved???
Thanks @TheRanomial for this PR! 🎉 Happy to count you in our contributors |
Let me explain the purpose of the parameter registration code I added. It handles automatic OpenAPI3 documentation for strongly-typed request parameters.
Consider this example:
type ListBooksParams struct {
APIKey string
header:"API-Key"
PageSize *int
query:"page_size"
SessionID string
cookie:"my-cookie"
}
The parameter registration code I added will:
*Read the struct tags from ListBooksParams
*Create OpenAPI parameter definitions for each tagged field:
This means that when someone looks at your API documentation, they'll see exactly what parameters are expected, where they should be placed (header/query/cookie), and their types - all generated automatically from your Go code's type definitions.
Without this code, you'd have to manually document these parameters in your OpenAPI spec, which could get out of sync with your actual code.