Understand the ogen request lifecycle
When a request hits an ogen server, it follows this sequence:
- net/http Middleware: The request passes through any standard
net/httpmiddleware wrapping the generatedServer. - Routing: The
Serverroutes the request to the specific operation handler. - OpenTelemetry: A trace is created and the request counter is incremented.
- Security Handlers: Security requirements are validated. If the OpenAPI spec defines security schemes, ogen generates a
SecurityHandlerinterface. The handler validates the presence and correctness of security values. If requirements are not met, it returnsogenerrors.ErrSecurityRequirementIsNotSatisfiedor aogenerrors.SecurityError. - Parameters Decoding: Request parameters are decoded. Failures result in a
ogenerrors.DecodeParamsError. - Request Body Decoding: The
Content-Typeis matched against the spec. If no match is found, avalidate.InvalidContentTypeErroris generated. Decoding failures result in aogenerrors.DecodeRequestError. - User Handler: The user-defined
Handleris executed. IfWithMiddlewareoptions were provided, the handler is passed as thenextparameter to that middleware. - Error Handling: If any step fails, the server increments the error counter, sets the trace status to error, and records the error via OpenTelemetry
Span.RecordError.