OpenAPITools / OpenAPITools/openapi-generator

[BUG][TypeScript] angular modelSuffix nested model bad import

Open
#20,726 0 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
  • [x ] Have you provided a full/minimal spec to reproduce the issue?
  • [x ] Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

While you generate api with typescript-angular and you will use modelSuffix as additional property, models are generated correctly, but if it is nested model for another model, the import is generated wrongly. Suffix is generated twice at the end of path from.

Example:
modelSuffix=example

GeneratedCode:
import { MunicipalityRestDtoExample } from './municipalityRestDtoExampleExample';

openapi-generator version

openapi-generator-cli version 7.11.0

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "API",
    "description": "",
    "version": "0.0.4-SNAPSHOT"
  },
  "paths": {},
  "components": {
    "schemas": {
      "MunicipalityResponseRestDto": {
        "type": "object",
        "properties": {
          "municipalities": { "type": "array", "items": { "$ref": "#/components/schemas/MunicipalityRestDto" } }
        }
      },
      "MunicipalityRestDto": {
        "type": "object",
        "properties": {
          "name": { "type": "string", "description": "Municipality name." }
        }
      }
    }
  }
}
Generation Details

openapi-generator-cli generate -i path/to/api.json -g typescript-angular --additional-properties=modelSuffix=example -o path/to/output/api

Steps to reproduce
  1. Create JSON file from spec above
  2. Generate api with command in generation details section

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

Start by running the reported openapi-generator-cli command with the supplied JSON and modelSuffix=example, then inspect the generated typescript-angular model imports. Trace how the nested MunicipalityRestDto reference produces the import path and verify that the suffix appears once in the path while the generated type name remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, typescript
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.