-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
refactor: move accept header from mux to server options #324
base: main
Are you sure you want to change the base?
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.
Thank you for this PR! 🙏🏼
Fixes #266 |
@@ -402,10 +402,10 @@ func TestGroupParams(t *testing.T) { | |||
t.Log(document.Paths.Find("/").Get.Parameters[0].Value.Name) | |||
require.Len(t, document.Paths.Find("/").Get.Parameters, 1) | |||
require.Equal(t, document.Paths.Find("/").Get.Parameters[0].Value.Name, "Accept") |
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.
Not your change, but we may want to check if require.NotNil(t, document.Paths.Find("/").Get.Parameters[0].Value)
Also could probably change all the require.Equal
below to assert
.
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.
This is just a nitpick feel free to resolve
Please rebase your branch on Thanks for the PR! |
Please fix the tests. I think you can run |
900e219
to
ea60340
Compare
route := fuego.Get(s, "/test", func(c fuego.ContextNoBody) (string, error) { | ||
name := c.QueryParam("name") | ||
age := c.QueryParamInt("age") | ||
isok := c.QueryParamBool("is_ok") |
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.
nitpicking: I would like to suggest
isok := c.QueryParamBool("is_ok") | |
isOK := c.QueryParamBool("is_ok") |
require.Equal(t, "Age", route.Params["age"].Description) | ||
require.True(t, route.Params["age"].Nullable) | ||
require.Equal(t, 18, route.Params["age"].Default) | ||
require.Equal(t, "integer", route.Params["age"].GoType) |
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.
require.Equal(t, "Age", route.Params["age"].Description) | |
require.True(t, route.Params["age"].Nullable) | |
require.Equal(t, 18, route.Params["age"].Default) | |
require.Equal(t, "integer", route.Params["age"].GoType) | |
require.Contains(t, route.Params, "age") | |
require.Equal(t, "Age", route.Params["age"].Description) | |
require.True(t, route.Params["age"].Nullable) | |
require.Equal(t, 18, route.Params["age"].Default) | |
require.Equal(t, "integer", route.Params["age"].GoType) |
Or, maybe you could do this, the readability will be increased
require.Equal(t, "Age", route.Params["age"].Description) | |
require.True(t, route.Params["age"].Nullable) | |
require.Equal(t, 18, route.Params["age"].Default) | |
require.Equal(t, "integer", route.Params["age"].GoType) | |
require.Contains(t, route.Params, "age") | |
paramAge := route.Params["age"] | |
require.Equal(t, "Age", paramAge.Description) | |
require.True(t, paramAge.Nullable) | |
require.Equal(t, 18, paramAge.Default) | |
require.Equal(t, "integer", paramAge.GoType) |
require.Equal(t, "Name", route.Params["name"].Description) | ||
require.True(t, route.Params["name"].Required) | ||
require.Equal(t, "hey", route.Params["name"].Default) | ||
require.Equal(t, "you", route.Params["name"].Examples["example1"]) | ||
require.Equal(t, "string", route.Params["name"].GoType) |
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.
This would be safer if something is refactored, it won't panic
require.Equal(t, "Name", route.Params["name"].Description) | |
require.True(t, route.Params["name"].Required) | |
require.Equal(t, "hey", route.Params["name"].Default) | |
require.Equal(t, "you", route.Params["name"].Examples["example1"]) | |
require.Equal(t, "string", route.Params["name"].GoType) | |
require.Contains(t, route.Params, name) | |
require.Equal(t, "Name", route.Params["name"].Description) | |
require.True(t, route.Params["name"].Required) | |
require.Equal(t, "hey", route.Params["name"].Default) | |
require.Contains(t, route.Params["name"].Examples, "example1") | |
require.Equal(t, "you", route.Params["name"].Examples["example1"]) | |
require.Equal(t, "string", route.Params["name"].GoType) |
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.
Also this would be more readable
require.Equal(t, "Name", route.Params["name"].Description) | |
require.True(t, route.Params["name"].Required) | |
require.Equal(t, "hey", route.Params["name"].Default) | |
require.Equal(t, "you", route.Params["name"].Examples["example1"]) | |
require.Equal(t, "string", route.Params["name"].GoType) | |
require.Contains(t, route.Params, name) | |
paramName := route.Params["name"] | |
require.Equal(t, "Name", paramName.Description) | |
require.True(t, paramName.Required) | |
require.Equal(t, "hey", paramName.Default) | |
require.Contains(t, paramName.Examples, "example1") | |
require.Equal(t, "you", paramName.Examples["example1"]) | |
require.Equal(t, "string", paramName.GoType) |
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "X-Test-Header") | ||
require.Equal(t, document.Paths.Find("/api/test2").Get.Parameters[1].Value.Name, "Accept") | ||
require.Equal(t, document.Paths.Find("/api/test2").Get.Parameters[0].Value.Name, "X-Test-Header") | ||
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "Accept") |
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.
Not related to this PR, but something like this should be added to avoid panics if there is a refactoring
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "Accept") | |
require.Len(t, document.Paths.Find("/api/test").Get.Parameters, 2) | |
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "Accept") |
@@ -376,8 +376,8 @@ func TestGroupHeaderParams(t *testing.T) { | |||
require.Equal(t, "test-value", route.Operation.Parameters.GetByInAndName("header", "X-Test-Header").Description) | |||
|
|||
document := s.OutputOpenAPISpec() | |||
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[1].Value.Name, "Accept") | |||
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "X-Test-Header") | |||
require.Equal(t, document.Paths.Find("/api/test").Get.Parameters[0].Value.Name, "Accept") |
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.
Same about testing Get.Parameters with require.Len
And in the next tests you are updating
Is that updating that file for you? |
Damn, it isn't. Hmm something is going on here. |
Oh nevermind the test s are failing cause their are two functions named TestParams |
Also the change to golden is the ordering so that should be fine. |
refactor: move accept header from mux to server options
fixes #266