You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the chi-middleware validator setting swagger.Servers = nil will fail every request.
This can be reproduced by starting a server that correctly validates hostnames (i.e. not setting swagger.Servers to nil) and properly handles requests, and then setting swagger.Servers = nil. All requests will fail.
Here is the snippet of code that works as expected:
// Versions of our API to serve
v010123Handler := v010123def.NewStrictHandler(
// Build service interface (business logic impl)
v010123service.NewAPI(highPrioritySQS, normalPrioritySQS),
[]v010123def.StrictMiddlewareFunc{},
)
// Get Swagger defininition for previous version
swagger, err := v010123def.GetSwagger()
if err != nil {
panic(fmt.Errorf("Failed to get swagger for version 010123: %w", err))
}
// swagger.Servers = nil
// This holds the various versioned API routers
handlers := map[string]http.Handler{
"010123": v010123def.HandlerWithOptions(v010123Handler, v010123def.ChiServerOptions{
Middlewares: []v010123def.MiddlewareFunc{
middleware.OapiRequestValidator(swagger),
},
}),
}
Then, changing nothing but uncommenting out // swagger.Servers = nil will cause the server to always fail requests.
I'm having difficulty finding exactly where the bug is, as it's difficult to inject debugging code kin-openapi libraries, but everything seems to be pointing to a similar issue here: getkin/kin-openapi#740, which also found regressions in this code getkin/kin-openapi#705.
I will be bringing this up with the kin-openapi project as well, but given there were recent changes in this project around swagger.Servers being nil I wanted to ensure that the issue was filed here first.
The text was updated successfully, but these errors were encountered:
When using the
chi-middleware
validator settingswagger.Servers = nil
will fail every request.This can be reproduced by starting a server that correctly validates hostnames (i.e. not setting
swagger.Servers
to nil) and properly handles requests, and then settingswagger.Servers = nil
. All requests will fail.Here is the snippet of code that works as expected:
Then, changing nothing but uncommenting out
// swagger.Servers = nil
will cause the server to always fail requests.I'm having difficulty finding exactly where the bug is, as it's difficult to inject debugging code kin-openapi libraries, but everything seems to be pointing to a similar issue here: getkin/kin-openapi#740, which also found regressions in this code getkin/kin-openapi#705.
I will be bringing this up with the
kin-openapi
project as well, but given there were recent changes in this project aroundswagger.Servers
beingnil
I wanted to ensure that the issue was filed here first.The text was updated successfully, but these errors were encountered: