OpenAPITools / OpenAPITools/openapi-generator

CORS error triggers an undefined TypeError when using typescript-fetch

Open
#12,959 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
openapi-generator version

I'm using 6.0.0.jar

Command line used for generation
          npx @openapitools/openapi-generator-cli generate \
              -i ./openapi/my.sdk.yaml \
              --additional-properties npmVersion=1.0.${{ github.run_number }}rc${{ github.event.number }} \
              -g typescript-fetch \
              --config ./openapi/openapi-typescript-config.json \
              -o ts-fetch-client

Steps to reproduce

Your API that you are using takes a vacation and doesn't respond to OPTIONS requests. It returns 404 instead.
When this happens, this line generates a TypeError due to response being: undefined
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L108

Related issues/PRs

I couldn't find one

Suggest a fix/enhancement

I have a PR

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

Start with modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache at line 108, then reproduce using the provided generator command against an API that returns 404 for OPTIONS requests. Done means the generated typescript-fetch client no longer throws an undefined TypeError in this CORS failure case; verify with the relevant runtime tests if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.