Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
gbark opened this issue Aug 9, 2019 · 1 comment · Fixed by #3605
Closed
5 tasks done

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

gbark opened this issue Aug 9, 2019 · 1 comment · Fixed by #3605

Comments

@gbark
Copy link
Contributor

gbark commented Aug 9, 2019

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

@auto-labeler
Copy link

auto-labeler bot commented Aug 9, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

gbark pushed a commit to gbark/openapi-generator that referenced this issue Aug 9, 2019
macjohnny pushed a commit that referenced this issue Aug 10, 2019
jimschubert added a commit that referenced this issue Aug 11, 2019
* master: (122 commits)
  Fix #3604 by adding undefined as return type to headers and credentials methods in runtime.ts (#3605)
  Prepare 4.1.1-SNAPSHOT (#3603)
  Prepare 4.1.0 release (#3597)
  [java][client][jax-rs] Add a constant for Jackson @JsonProperty (#3560)
  restore openapi3 petstore.yaml (#3590)
  Add a new NodeJS Express server generator (#3567)
  [C#][client][csharp-netcore] Fix csharp netcore defaultheaders (#3562)
  Fix issue deserializing to nullptr (#3572)
  [OCaml] Add file post-processing (#3583)
  [dart2] Fix up test code generation, double deserialization, 'new' keyword deprecation (#3576)
  Run Qt5 client sample test (#3415)
  typescript-fetch: allow configuration of headers and credentials (#3586)
  using partials in ruby api_client (#3564)
  [OCaml] Added optional params support in API operations (#3568)
  [Rust Server] Generate valid Rustdocs for lazy_static items (#3556)
  Fix NPM build for Typescript-fetch (#3403)
  Expand path templates via resttemplate's uriTemplateHandler (#3500)
  Readme updated with a new tutorial and company using OpenAPI Generator (#3566)
  Fix logic of `getNullableType` of csharp server and client. (#3537)
  [Ruby] clean up Ruby dev dependencies (#3551)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant