-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Description
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?
- 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
The changes introduced in OpenAPITools/openapi-generator#18418 result in TS7053 errors in the generated instanceOf* methods on our side.
TS7053: Element implicitly has an any type because expression of type string can't be used to index type typeof Criticality
No index signature with a parameter of type string was found on type typeof Criticality
openapi-generator version
7.6.0 fails, 7.5.0 has no issue
OpenAPI declaration file content or url
openapi: 3.0.0
components:
schemas:
# -- Snipped 300 lines of other schemas --
Criticality:
type: string
enum:
- error
- warning
- malfunctionGeneration Details
We execute the following command and depend on @openapitools/openapi-generator-cli for the generation.
While we use the stringEnums option, removing that doesn't solve the issue so that option seems unrelated.
openapi-generator-cli --openapitools 'path/to/openapitools.json' generate --generator-key some-service
The openapitools.json then looks like this:
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 4,
"generator-cli": {
"version": "7.6.0",
"generators": {
"some-service": {
"additionalProperties": {
"inputSpec": "path/to/some-service.yaml",
"output": "path/to/some-app/src/js/types/openapi/some-service",
"generatorName": "typescript-fetch",
"stringEnums": true
}
}
}
}
}Steps to reproduce
- Create an OpenAPI YAML specification containing a schema as shown above
- Use
openapi-generatorto generate TypeScript types, it does so succesfully - Try to import/use the generated enum, TypeScript will throw a TS7053 error
Alternatively:
Related issues/PRs
None found so far.
Suggest a fix
Either revert the PR or adjust the the TypeScript, the following cast seems to solve the issue but is less than ideal;
if ((Criticality as Record<string, Criticality>)[key] === value) {We have also noticed that setting strict to false in tsconfig.json resolves the issue which makes sense because TS7053 refers to an implicit any. Setting strict to true and noImplicitAny to false also seems to work.