oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Is that possible to add handlers on paths not defined in scheme?

Open MetalRex101 opened this issue 4 years ago • 2 comments

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.

MetalRex101 avatar Oct 04 '21 11:10 MetalRex101

+1

gshel avatar Mar 21 '22 19:03 gshel

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.

stevenh avatar Mar 29 '22 15:03 stevenh