-
-
Notifications
You must be signed in to change notification settings - Fork 544
Closed
Description
Is your feature request related to a problem? Please describe.
In my org, we have a common header that is used for internal log correlation between microservices, X-TraceId. This means that every API route should accept this header so it can be propagated accordingly.
I would like this to be included on our generate OpenAPI spec.
However, I cannot find a DRY way to include the same request header on every route.
It would be helpful to be able to define ninja request parameters, such as query args or headers on a router (or even NinjaAPI) level. This would avoid unnecessary repetition.
Describe the solution you'd like
Currently, it is possible to add these request parameters in two ways.
Method 1: Function parameters
@api.get("/ready", tags=["k8s"], response={200: None})
def ready(request, trace_id: str = Header(alias="X-TraceId")):
return 200, None
Method 2: openapi_extra
@api.get("/ready", tags=["k8s"], response={200: None}, openapi_extra={
"parameters": [
{
"in": "header",
"name": "X-TraceId",
"required": False,
"schema": {"type": "string"},
"description": "Tracking ID for log correlation"
}
]
})
def ready(request):
return 200, None
It would be great to be able to define either:
- request method parameters that are automatically "inherited" by all routes in that router
openapi_extrathat are "inherited" by all routes in the router
Metadata
Metadata
Assignees
Labels
No labels