oapi-codegen
oapi-codegen copied to clipboard
Is that possible to add handlers on paths not defined in scheme?
I try to add handler for K8S readiness probe (GET /health), which is not defined in open api scheme.
r.Get("/health", func(writer http.ResponseWriter, request *http.Request) {
if _, err := writer.Write(nil); err != nil {
logger.Error("failed to write response", zap.Error(err))
}
})
There is no panics during route registration, but when i call it with browser (GET host:port/health) it returns me an no matching operation was found error.
+1
The issue is that the middleware.OapiRequestValidator validates the path exists in the spec so when other routes are added it triggers no matching operation was found.
The workaround for chi at least is to create a sub router to apply OapiRequestValidator to.