[BUG][typescript-angular] Model properties with underscore prefix generates invalid file names/imports using kebab-case file naming
Created by: roddy
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
I have an API that follows HAL standards. It includes a _links
property defined as an inline object schema. When the typescript-angular generator is run, it creates a typescript file named foo-response--links.ts
, but references it as foo-response-links
in imports from other files.
I am generating this using the NPM client @openapitools/openapi-generator-cli@1.0.8-4.2.2 which bundles the 4.2.2 generator (I think).
Invoking with: generate --generator-name typescript-angular --input-spec foo.yml --config config.json --skip-validate-spec
Config:
{
"ngVersion": "7.2.0",
"fileNaming": "kebab-case",
"modelPropertyNaming": "original",
"serviceSuffix": "Service",
"sortParamsByRequiredFlag": true,
"prependFormOrBodyParameters": true
}
API example (foo.yml):
openapi: 3.0.0
info:
title: Example API
description: An Example API
version: "1.0"
paths:
/hello:
get:
summary: Example endpoint
operationId: get_hello
responses:
200:
description: Example response
content:
application/json:
schema:
$ref: '#/components/schemas/FooResponse'
components:
schemas:
FooResponse:
type: object
properties:
_links:
required:
- collection
- self
type: object
properties:
collection:
type: string
format: uri
self:
type: string
format: uri
Note that the FooResponse
schema has a property _links
defined as an object.
This generates a foo-response.ts
and a foo-response--links.ts
(note the double hyphen.)
In foo-response.ts
, it tries to import the model from foo-response-links.ts
(note the single hyphen) like so:
import { FooResponseLinks } from './foo-response-links';
export interface FooResponse {
_links?: FooResponseLinks;
}
Note that when using 'camelCase' file naming, this issue is not present and the model files are generated as fooResponse.ts
and fooResponseLinks.ts
and linked appropriately.
openapi-generator version
Confirmed that this is an issue with @openapitools/openapi-generator-cli versions:
- 1.0.8-4.2.2 (current latest)
- 1.0.1-4.1.3
Command line used for generation
generate --generator-name typescript-angular --input-spec foo.yml --config config.json --skip-validate-spec
Suggest a fix
The double hyphen in the file name is very unusual but technically valid. The issue is that the logic that determines the file name to use, and the logic that determines the module name to import from is out of sync.
So the fix is either:
- A. Generate a file name
foo-response-links.ts
without the double hyphen, to match the import. or: - B. Update the import to be
from './foo-response--links'
to match the file name.
(I personally prefer solution A because it's more natural.)