OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-angular & maybeothers] hasEnums returns true for reference enums leading in empty namespace generation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When a schema definition has a reference to and another enum schema, the mustache template value hasEnums is set to true, despite the schema itself not having an enum.
This causes typescript-angular/modelEnum.mustache, to render an empty namespace field.
openapi-generator version
6.5.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: hasEnums Demo
version: 1.0.0
paths: {}
components:
schemas:
SchemaWithRefToEnum:
type: object
properties:
foo:
type: string
bar:
$ref: '#/components/schemas/Baz'
Baz:
enum:
- Foo
- Bar
type: string
Steps to reproduce
generate the angular client with openapi-generator-cli generate -i [file.yaml] -g typescript-angular -o output-directory.
Then look into "output-directory/model/schemaWithRefToEnum.ts" and you will find the following result:
///...
import { EnumSchema } from './enumSchema';
export interface SchemaWithRefToEnum {
foo?: string;
refToEnum?: EnumSchema;
}
export namespace SchemaWithRefToEnum {
}
The export namespace SchemaWithRefToEnum { section is empty an not needed, since it would only be present, if there was an enum directly referenced. Since it is not, this sections is empty.
Adding a bit of debug information shows the following
// modelGenericEnums.mustache
// hasEnums: true
export namespace SchemaWithRefToEnum {
// foo isEnum false
// bar isEnum false
}
Related issues/PRs
It is worth mention, that this issue is not present on https://editor.swagger.io/. Generating the typescript-angular client from there, results in the expected result --> no empty namespace is included.
Suggest a fix
If an enum is referenced via $ref, the hasEnums should not be true.
Possible places for the error:
- updateOperationParameterEnumInformation method from https://github.com/OpenAPITools/openapi-generator/blob/edfb3e123f0d3ad48992e158da957e87c3b8c3fe/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptReduxQueryClientCodegen.java
- updateOperationParameterForEnum method from https://github.com/OpenAPITools/openapi-generator/blob/fe8fbaf923a8d3bc3a52b6778360ef2483d5c057/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the YAML declaration and the typescript-angular generation command, then inspect model/schemaWithRefToEnum.ts and typescript-angular/modelEnum.mustache. Trace how hasEnums is populated, including the suggested TypeScript codegen methods. Done means a referenced enum no longer causes an empty namespace to be generated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, java, typescript
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100