Skip to content
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

How to set cookie/headers when running query/mutation? #71

Open
vinaybedre opened this issue Apr 17, 2024 · 4 comments
Open

How to set cookie/headers when running query/mutation? #71

vinaybedre opened this issue Apr 17, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@vinaybedre
Copy link

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?

@seriouslag
Copy link
Collaborator

@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.

@seriouslag seriouslag added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested and removed good first issue Good for newcomers labels Apr 17, 2024
@seriouslag
Copy link
Collaborator

I have opened an issue in @hey-api/openapi-ts#465 to add the functionality to override the OpenAPI config per request.

@lavocatt
Copy link

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'

@seriouslag
Copy link
Collaborator

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants