question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Header parameters

See original GitHub issue

What are the steps to reproduce this issue?

At the moment header parameters which occur in the API spec are ignored. This is disadvantageous in our case, as some of them are specified as required in our API.

Consider the following API spec:

openapi: '3.0.0'
info:
    version: 1.0.0
    title: Swagger Petstore
    license:
        name: MIT
servers:
    - url: http://petstore.swagger.io/v1
paths:
    /pets/{uuid}:
        post:
            summary: Create a pet
            operationId: createPets
            tags:
                - pets
            parameters:
                - description: UUID
                  in: path
                  name: uuid
                  required: true
                  schema:
                      type: string
                - description: Offset
                  in: query
                  name: offset
                  schema:
                      type: integer
                - description: Header parameters
                  in: header
                  name: X-EXAMPLE
                  required: true
                  schema:
                      type: string
                      enum:
                          - ONE
                          - TWO
                          - THREE
            requestBody:
                required: true
                content:
                    application/json:
                        schema:
                            type: object
                            required:
                                - 'name'
                                - 'tag'
                            properties:
                                name:
                                    type: string
                                tag:
                                    type: string
            responses:
                '201':
                    description: Null response
                default:
                    description: unexpected error
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Error'
components:
    schemas:
        Error:
            type: object
            required:
                - code
                - message
            properties:
                code:
                    type: integer
                    format: int32
                message:
                    type: string

What happens?

It generates the following code:

/**
 * Generated by orval v6.8.1 🍺
 * Do not edit manually.
 * Swagger Petstore
 * OpenAPI spec version: 1.0.0
 */
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { CreatePetsBody, CreatePetsParams } from '../model';

/**
 * @summary Create a pet
 */
export const createPets = <TData = AxiosResponse<void>>(
    uuid: string,
    createPetsBody: CreatePetsBody,
    params?: CreatePetsParams,
    options?: AxiosRequestConfig
): Promise<TData> => {
    return axios.post(`/pets/${uuid}`, createPetsBody, {
        params,
        ...options,
    });
};

export type CreatePetsResult = AxiosResponse<void>;

What were you expecting to happen?

Necessary for our projects would be this snippet:

/**
 * Generated by orval v6.8.1 🍺
 * Do not edit manually.
 * Swagger Petstore
 * OpenAPI spec version: 1.0.0
 */
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { CreatePetsBody, CreatePetsParams } from '../model';

/**
 * @summary Create a pet
 */
export const createPets = <TData = AxiosResponse<void>>(
    uuid: string,
    createPetsBody: CreatePetsBody,
    xExample: 'ONE' | 'TWO' | 'THREE',
    params?: CreatePetsParams,
    options?: AxiosRequestConfig
): Promise<TData> => {
    return axios.post(`/pets/${uuid}`, createPetsBody, {
        params,
        ...options,
        headers: { 'X-EXAMPLE': xExample, ...options?.headers },
    });
};

export type CreatePetsResult = AxiosResponse<void>;

Any other comments?

I would be happy to help with the pull request as this is holding us back from a successful migration. But it would be good if you could give me a starting point and a little help to get familiar with the code base.

What versions are you using?

Operating System: macOS Monterey Version 12.4 Package Version: 6.8.1 / Git HEAD Browser Version: React Native 0.68.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
anymaniaxcommented, Jul 6, 2022

Will try to do that asap to add it in the next release

2reactions
reichhartdcommented, Jul 6, 2022

Yes, this solution would be absolutely fine for us. In this case, the required header parameter would make us aware that they are needed here. 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP headers - MDN Web Docs - Mozilla
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its ......
Read more >
Understanding REST Headers and Parameters - SoapUI
The REST headers and parameters contain a wealth of information that can help you track down issues when you encounter them. HTTP Headers...
Read more >
HTTP header fields and URI parameters - IBM
Parameters for collection types · Request. URL: /collection; Method: GET; Header: "Range: items=start-stop" · Response. Header: "Content-Range: items start-stop/ ...
Read more >
List of HTTP header fields - Wikipedia
HTTP header fields are a list of strings sent and received by both the client program and server on every HTTP request and...
Read more >
HTTP headers and common query string parameters for JSON
This page describes: All headers used by the JSON API; The query parameters that apply to any JSON API request. See specific methods...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found