Skip to content

[BUG][typescript] Models named after language-specific types generate incorrectly #5139

@amakhrov

Description

@amakhrov

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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

If models in the spec are named as lower cased language-specific types, it bypasses sanity checks and produces undesirable result.
E.g. my model is named map. Then the generated interface is named Map, and the api file silently maps that to any

openapi-generator version

master

OpenAPI declaration file content or url

gist: language-specific.yml

Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
    -i /local/spec.yaml \
    -g typescript-angular \
    -o /local/generated
Steps to reproduce
  • Run command above
  • Check the generated model/map.ts and api/default.service.ts
  • Existing output:
// model/map.ts:
export interface Map { ... }

// api/default.service.ts
public mapGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: '*/*'}): Observable<any>;
  • Expected output
// model/map.ts:
export interface ModelMap { ... }

// api/default.service.ts
public mapGet(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: '*/*'}): Observable<ModelMap>;
Related issues/PRs

It's somewhat similar to #5104 .

Suggest a fix

Half of the problem (generating a correct model name) is addressed in #5138

The proper result type in api file (instead of any) still needs a separate fix.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions