Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3604
Closed
Open
Issue created Aug 09, 2019 by Administrator@rootContributor5 of 5 checklist items completed5/5 checklist items

[BUG][typescript-fetch] HTTPHeaders and RequestCredentials type errors

Created by: gbark

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 4.1.0
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?

Expected: No type errors in TypeScript output.

Actual:

src/api/petstore/src/runtime.ts:186:9 - error TS2322: Type 'HTTPHeaders | undefined' is not assignable to type 'HTTPHeaders'.
  Type 'undefined' is not assignable to type 'HTTPHeaders'.

186         return this.configuration.headers;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/api/petstore/src/runtime.ts:190:9 - error TS2322: Type '"omit" | "same-origin" | "include" | undefined' is not assignable to type 'RequestCredentials'.
  Type 'undefined' is not assignable to type 'RequestCredentials'.

190         return this.configuration.credentials;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Description

A type error regression was introduced with this PR. The return types of get headers() and get credentials() in runtime.ts doesn't reflect that the return value might be undefined.

openapi-generator version

4.1.0

OpenAPI declaration file content or url

https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml

Steps to reproduce
  1. Generate typescript-fetch API client: openapi-generator generate -g typescript-fetch -i ./PATH_TO_PETSTORE.yml -o ./petstore
  2. Typecheck code: tsc ./petstore --noEmit
  3. See error in Typescript compiler output

OR:

Clone this repo and run npm install && npm run typecheck: https://github.com/gbark/openapi-petstore

Suggest a fix

Adding undefined as a return type to get headers() and get credentials() in runtime.ts should do it.

I've created a small PR which fixes it. #3605

Assignee
Assign to
Time tracking