question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][TYPESCRIPT/ANGULAR] Using wrong keyword in generated AngularService (localVarHeaders instead of headers)

See original GitHub issue

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?
Description

Since the use of Version 5.2.1 (last Version used before was 5.0.0) we encounter a issue with the generation of Angular Service code. According to this https://github.com/OpenAPITools/openapi-generator/pull/10091 variables have been renamed for the generation of the Angular - Services.

Unfortunately on Line https://github.com/OpenAPITools/openapi-generator/commit/664aa2d946236ce327cf56256947baeb68f828e4#diff-7de15eed36eb15ed45aef205826063248eaddf2b11511db6a4bb2679c2aca851R361 there seemed to went something wrong. The property “headers” which is part of the HTTPClient Options has also been renamed instead of the value. This should stay headers.

This will cause a compilation error in angular and won’t work as header information is not submitted.

So the code should be:

{
    ...
    headers: localVarHeaders,
   ...
}

But unfortunately the code generated is:

{
      ...
      localVarHeaders: localVarHeaders,
      ...
}
openapi-generator version

I am using the "@openapitools/openapi-generator-cli": "2.3.10" with version-manager 5.2.1. Reverting to Version 5.0.0 in the version-manager works.

OpenAPI declaration file content or url

You may use the example schema to regenerate the issue: https://petstore.swagger.io/v2/swagger.json.

Generation Details

Can be generated with the following line:

openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g typescript-angular -o src/app/swagger --type-mappings=object=any --skip-validate-spec

Steps to reproduce
  1. Create an Angular App
  2. Install openapi-cli. https://www.npmjs.com/package/@openapitools/openapi-generator-cli
  3. Set version in openapitools.json to 5.2.1 Here is my example:
{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "5.2.1"
  }
}
  1. Generate Services for angular as described above openapi-generator-cli generate -i https://petstore.swagger.io/v2/swagger.json -g typescript-angular -o src/app/swagger --type-mappings=object=any --skip-validate-spec

  2. Use petService via Dependency Injection in app.component.ts

  3. Try compiling. npm run start The pet.service.ts will cause a compilation error because localVarHeaders is not a known key for the httpClient options.

Related issues/PRs

No related issue found yet.

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/commit/664aa2d946236ce327cf56256947baeb68f828e4#diff-7de15eed36eb15ed45aef205826063248eaddf2b11511db6a4bb2679c2aca851R361 So the code should be:

{
    ...
    headers: localVarHeaders,
   ...
}

But unfortunately the code generated is:

{
      ...
      localVarHeaders: localVarHeaders,
      ...
}

Thanks for any comment on this issue. Best regards Schmitda

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
macjohnnycommented, Aug 20, 2021

It should be part of the next upcoming release, so 5.3.0

https://github.com/OpenAPITools/openapi-generator/milestones

1reaction
LPCmediacommented, Aug 19, 2021

looks like its published. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found