Skip to content

Multiple header properties when adding headers in override.requestOptions #2546

@chcederquist

Description

@chcederquist

Bug Report: Multiple header properties when adding headers in override.requestOptions

Environment

  • Orval Version: 7.16.0
  • Node.js Version: 22
  • Package manager: Yarn
  • Client: fetch

Description

When adding headers to override.requestOptions, the generated fetch client adds multiple header keys to the same object, causing the error "An object literal cannot have multiple properties with the same name.ts(1117)"

Configuration

import { defineConfig } from 'orval';

export default defineConfig({
  petstoreClient: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      mode: 'tags-split',
      client: 'fetch',
      target: 'next-app/app/gen/',
      schemas: 'next-app/app/gen/models',
      clean: true,
      baseUrl: 'http://localhost:8787',
      mock: true,
      override: {
        requestOptions: {
          headers: {
            '"X-SOME-HEADER"': 'SOME-VALUE',
          },
        },
      },
    },
  },
  petstoreApi: {
    input: {
      target: './petstore.yaml',
    },
    output: {
      mode: 'split',
      client: 'hono',
      target: 'hono-app/src/petstore.ts',
      override: {
        hono: {
          handlers: 'hono-app/src/handlers',
        },
      },
    },
  },
});

Reproduction Steps

Use the config above (taken from samples/hono/hono-with-fetch-client) with the petstore.yaml and run Orval

Expected Behavior

export const createPets = async (createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit): Promise<createPetsResponse> => {
  
  const res = await fetch(getCreatePetsUrl(),
  {
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'X-SOME-HEADER': 'SOME-VALUE',  ...options?.headers },
    body: JSON.stringify(
      createPetsBodyItem,)
  }
)

Actual behavior

export const createPets = async (createPetsBodyItem: CreatePetsBodyItem[], options?: RequestInit): Promise<createPetsResponse> => {
  
  const res = await fetch(getCreatePetsUrl(),
  {
      headers: { "X-SOME-HEADER": 'SOME-VALUE', },
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(
      createPetsBodyItem,)
  }
)

Workaround

I can't find a workaround to this problem.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions