-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to define reusable headers that can be used in both request and response #1574
Comments
As of now it needs to be defined twice. Because in case of Request it is considered as parameter, in case of response it needs to be defined as the header. https://swagger.io/docs/specification/components/. But providing an option to re use this will help us avoid DRY. |
I will take a look at if/how overlays can solve this problem as part of determining whether overlay spec is sufficient. Possibly this could be solved with OpenAPI's components.headers - but request parameters and response headers have slightly different formats. Strictly on how overlays might solve this problem, I think the example below would work. It's 2 actions to account for the aforementioned difference. What do you think? {
"overlay": "1.0.0",
"info": {
"title": "Common Headers Overlay",
"version": "1.0.0"
},
"actions": [
{
"target": "info",
"update": {
"x-overlay-applied": "common-headers"
}
},
{
"description": "Add request header",
"target": "paths[*].get.parameters",
"update": {
"name": "request-id",
"in": "header",
"description": "API consumers send this header with a unique ID identifying the request header for tracking purpose, sent header back as a response header",
"schema": {
"type": "string"
}
}
},
{
"description": "Add response header",
"target": "paths[*].get.responses[*].headers",
"update": {
"request-id": {
"description": "API consumers send this header with a unique ID identifying the request header for tracking purpose, sent header back as a response header",
"schema": {
"type": "string"
}
}
}
}
]
} |
As we must specify the |
How to define reusable headers that can be used in both request and response?
if a headers is defined in components.parameters it is not allowing to use in response.headers and vice-versa. What if an header that will present in both request and response? do I have to define it twice in component.parameters and component.headers?
thanks
The text was updated successfully, but these errors were encountered: