Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13201
Closed
Open
Issue created Aug 16, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][typescript-angular] Incorrect import or filename when model starts with a number

Created by: snebjorn

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?
    • Issue is still present in master https://github.com/snebjorn/openapi-gen-bug/tree/master/output-master/import-bug
  • 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 a model have an invalid starting character it'll be prefixed with Model. However this prefixing isn't consistent everywhere.

For example this schema:

"schemas": {
  "foo": {
    "type": "object",
    "properties": {
      "first": {
        "anyOf": [{ "type": "number" }, { "type": "string" }],
        "title": "1st"
      }
    }
  }
}

Generates this model:

// filename: 1st.ts
export interface Model1st { 
}

But it'll be imported like so:

import { Model1st } from './model1st';

NOTE: The filenames doesn't match.

openapi-generator version

6.0.1

OpenAPI declaration file content or url

https://raw.githubusercontent.com/snebjorn/openapi-gen-bug/master/import-bug.json

{
  "openapi": "3.0.0",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/Foos": {
      "get": {
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "$ref": "#/components/schemas/foo"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "foo": {
        "type": "object",
        "properties": {
          "first": {
            "anyOf": [{ "type": "number" }, { "type": "string" }],
            "title": "1st"
          }
        }
      }
    }
  }
}
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://raw.githubusercontent.com/snebjorn/openapi-gen-bug/master/import-bug.json \
   -g typescript-angular \
   -o output-master/import-bug
Steps to reproduce
  1. Clone https://github.com/snebjorn/openapi-gen-bug
  2. Run yarn install
  3. Run yarn gen
  4. Observe import error in https://github.com/snebjorn/openapi-gen-bug/blob/ad3851d72b3a9bfe8bc49604730d013e03813b73/output-6.0.1/import-bug/model/foo.ts#L12
Related issues/PRs

None found.

Suggest a fix

Either the filename should also have the prefix or the import statement shouldn't use the prefix. Care should be taken as the filename format can be changed via the fileNaming parameter.

https://openapi-generator.tech/docs/generators/typescript-angular/

fileNaming Naming convention for the output files: 'camelCase', 'kebab-case'.
Assignee
Assign to
Time tracking