OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-fetch] header is not included in "get" methods

Open
#10,399 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

when the client is generated with typescript-fetch in the "get" methods, the headers included in the definition are not being added.

openapi-generator version

5.2.1

OpenAPI declaration file content or URL

https://petstore.swagger.io/v2/swagger.json

Generation Details
findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, options: any = {}): FetchArgs {
  // verify required parameter 'status' is not null or undefined
  if (status === null || status === undefined) {
      throw new RequiredError('status','Required parameter status was null or undefined when calling findPetsByStatus.');
  }
  const localVarPath = `/pet/findByStatus`;
  const localVarUrlObj = url.parse(localVarPath, true);
  const localVarRequestOptions = Object.assign({ method: 'GET' }, options);
  const localVarHeaderParameter = {} as any;
  const localVarQueryParameter = {} as any;

  // authentication petstore_auth required
  // oauth required
  if (configuration && configuration.accessToken) {
const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
? configuration.accessToken("petstore_auth", ["write:pets", "read:pets"])
: configuration.accessToken;
      localVarHeaderParameter["Authorization"] = "Bearer " + localVarAccessTokenValue;
  }

  if (status) {
      localVarQueryParameter['status'] = status;
  }

  localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter, options.query);
  // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943
  delete localVarUrlObj.search;
  localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers);

  return {
      url: url.format(localVarUrlObj),
      options: localVarRequestOptions,
  };
}

This method should include:

['application/json', 'application/xml'];
Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Generate a typescript-fetch client from the linked Petstore OpenAPI declaration and inspect the generated findPetsByStatus GET method shown in the issue. Compare its request headers with the operation definition; done means the generated method includes the declared ['application/json', 'application/xml'] header values.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.