[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
- Clone https://github.com/snebjorn/openapi-gen-bug
- Run
yarn install
- Run
yarn gen
- 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'. |
---|