OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-angular] Import mappings with same path do not work properly when generating services

Open
#22,533 3 comments 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?
  • 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 defining import mappings with the same path (e.g. --import-mappings=Foo=@foo/bar,Bar=@foo/bar), only one import statement will be generated even if multiple are needed.

Works with models but not with services.

openapi-generator version

7.17.0

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Sample API
  version: 0

paths:
  /users/{foo}/{bar}:
    parameters:
      - schema:
          type: Foo
        name: foo
        in: path
      - schema:
          type: Bar
        name: bar
        in: path
    get:
      responses:
        "200":
          description: "get"
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string
Generation Details

openapi-generator generate -g typescript-angular -i openapi.yaml -o generated --import-mappings=Foo=@foo/bar,Bar=@foo/bar

Steps to reproduce
  1. Clone https://github.com/rmeyergh/openapi-generator-typescript-angular-bug
  2. Run generate.sh
  3. Take a look at generated/api/default.service.ts
Suggest a fix

I don't really have a fix but it look suspicious that in the default mustache template for models {{ #tsImports }} is used while in the api.service.mustache it says {{ #imports }}.

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

Clone the linked reproduction repository and run generate.sh, then inspect generated/api/default.service.ts. Compare the service template's imports in api.service.mustache with the model template's tsImports handling; done means both Foo and Bar imports are generated when they map to the same path.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.