OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-angular] Import mappings with same path do not work properly when generating services
Nobody has claimed this yet.
- 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
- Clone https://github.com/rmeyergh/openapi-generator-typescript-angular-bug
- Run generate.sh
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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