How to set cookie/headers when running query/mutation?
I really like codegens, which make the life of developers easy.
How ever with this codegen, I was unable to find a way to set cookie/header per query/mutation level. I couldnt find anything in documentation either.
Did someone achieved this?
@vinaybedre, one way to achieve that with this package as of now would be to add an interceptor on the OpenAPI object that is exported from requests/core/OpenAPI.ts
In the interceptor, you could check the URL and method and add the header. I haven't tried that though.
It might be nice if we exposed an ability to pass service overrides per hook but that will involve code changes.
I have opened an issue in @hey-api/openapi-ts#465 to add the functionality to override the OpenAPI config per request.
I was able to set headers by specifying them in the swagger definitions:
/brokers:
get:
summary: retrieve the broker mbean
description: >
**Get the broker mbean**
The return value is a one-element array that contains
the broker's mbean object name.
**Example:**
**Request url:** https://localhost:9443/api/v1/brokers
**Response:**
```json
[
"org.apache.activemq.artemis:broker=\"amq-broker\""
]
```
tags:
- jolokia
operationId: getBrokers
parameters:
- in: header
name: jolokia-session-id
schema:
type: string
required: true
- in: header
name: jolokia-target-pod-session-id
schema:
type: integer
required: true
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/BrokersResponse'
I was able to set headers by specifying them in the swagger definitions:
/brokers: get: summary: retrieve the broker mbean description: > **Get the broker mbean** The return value is a one-element array that contains the broker's mbean object name. **Example:** **Request url:** https://localhost:9443/api/v1/brokers **Response:** ```json [ "org.apache.activemq.artemis:broker=\"amq-broker\"" ] ``` tags: - jolokia operationId: getBrokers parameters: - in: header name: jolokia-session-id schema: type: string required: true - in: header name: jolokia-target-pod-session-id schema: type: integer required: true responses: 200: description: Success content: application/json: schema: $ref: '#/components/schemas/BrokersResponse'
This is the correct way to document the need for the headers!
Thanks for sharing :)