OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-angular] Invalid string enum mapping for `Null` value

Open
#10,983 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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

I have the following enum definition:

EdmExpressionKind:
  enum:
    - 0
    - 1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    - 10
    - 11
    - 12
    - 13
    - 14
    - 15
    - 16
    - 17
    - 18
    - 19
    - 20
    - 21
    - 22
    - 23
    - 24
    - 25
  type: integer
  format: int32
  x-enum-varnames:
    - None
    - BinaryConstant
    - BooleanConstant
    - DateTimeOffsetConstant
    - DecimalConstant
    - FloatingConstant
    - GuidConstant
    - IntegerConstant
    - StringConstant
    - DurationConstant
    - Null
    - Record
    - Collection
    - Path
    - If
    - Cast
    - IsType
    - FunctionApplication
    - LabeledExpressionReference
    - Labeled
    - PropertyPath
    - NavigationPropertyPath
    - DateConstant
    - TimeOfDayConstant
    - EnumMember
    - AnnotationPath

typescript-angular generator produces the following model:

export enum EdmExpressionKind {
    None = 0,
    BinaryConstant = 1,
    BooleanConstant = 2,
    DateTimeOffsetConstant = 3,
    DecimalConstant = 4,
    FloatingConstant = 5,
    GuidConstant = 6,
    IntegerConstant = 7,
    StringConstant = 8,
    DurationConstant = 9,
     = 10,
    Record = 11,
    Collection = 12,
    Path = 13,
    If = 14,
    Cast = 15,
    IsType = 16,
    FunctionApplication = 17,
    LabeledExpressionReference = 18,
    Labeled = 19,
    PropertyPath = 20,
    NavigationPropertyPath = 21,
    DateConstant = 22,
    TimeOfDayConstant = 23,
    EnumMember = 24,
    AnnotationPath = 25
};

So it fails to properly map Null = 10 value and produces invalid typescript file

openapi-generator version

5.3.0

OpenAPI declaration file content fragment
components:
  schemas:
    EdmExpressionKind:
      enum:
        - 0
        - 1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
        - 8
        - 9
        - 10
        - 11
        - 12
        - 13
        - 14
        - 15
        - 16
        - 17
        - 18
        - 19
        - 20
        - 21
        - 22
        - 23
        - 24
        - 25
      type: integer
      format: int32
      x-enum-varnames:
        - None
        - BinaryConstant
        - BooleanConstant
        - DateTimeOffsetConstant
        - DecimalConstant
        - FloatingConstant
        - GuidConstant
        - IntegerConstant
        - StringConstant
        - DurationConstant
        - Null
        - Record
        - Collection
        - Path
        - If
        - Cast
        - IsType
        - FunctionApplication
        - LabeledExpressionReference
        - Labeled
        - PropertyPath
        - NavigationPropertyPath
        - DateConstant
        - TimeOfDayConstant
        - EnumMember
        - AnnotationPath
      x-import-mapping: Microsoft.OData.Edm.EdmExpressionKind
Generation Details

@openapitools/openapi-generator-cli generate -i swagger.yaml -g typescript-angular -o output --type-mappings AnyType=any --additional-properties stringEnums=true

Steps to reproduce
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typescript-angular generator using the provided OpenAPI enum and generation command, then trace how x-enum-varnames are converted into the shown TypeScript enum. Reproduce the empty member for Null and verify that generation produces valid TypeScript with Null = 10 preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.