OpenAPITools / OpenAPITools/openapi-generator

[BUG] Generator typescript-axios produces invalid output when enum value is '*/*'

Open
#15,375 0 comments 1 reaction 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

Invalid typescript file generated when using generator typescript-axios and enum contains string value of */*. See generation detail sections for specifics.

openapi-generator version
$ openapi-generator-cli version
6.5.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Test
  version: 0.0.1
paths:
  /test:
    delete:
      parameters:
        - in: header
          name: Accept
          schema:
            $ref: '#/components/schemas/MyEnum'
      operationId: delete
      responses:
        '204':
          description: Deleted
components:
  schemas:
    MyEnum:
      type: string
      default: application/json
      enum:
        - '*/*'
        - application/json
        - application/my.document-tree+json
Generation Details

Output file api.ts has the following enum specification

export const MyEnum = {
    : '*_/_*',
    ApplicationJson: 'application/json',
    ApplicationMyDocumentTreejson: 'application/my.document-tree+json'
} as const;

Expected:

export const MyEnum = {
    Asterisk: '*/*',
    ApplicationJson: 'application/json',
    ApplicationMyDocumentTreejson: 'application/my.document-tree+json'
} as const;
Steps to reproduce
# Where test.yml has the contents described above
openapi-generator-cli generate \
  -i ./test.yml \
  -g typescript-axios \
  -o ./output \
  -p modelPropertyNaming=original \
  --remove-operation-id-prefix \
  -p useSingleRequestParameter=true
Related issues/PRs
Suggest a fix

Not sure what the fix should be but here is what seems to be happening for the Key

  1. */* -> *_* when replacing all / characters with _. Reference
  2. *_* -> _ when removing non-word characters with regex \W. Reference
  3. _ Gets converted to empty string. Reference

For the value

  1. Attempt to get enum value. Reference
  2. Attempt to escape enum value text Reference
  3. Replace */ -> *_/ and /* -> /_* Reference

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 enum-name and value handling referenced in DefaultCodegen.java and AbstractTypeScriptClientCodegen.java, especially the cited lines around key sanitization and value escaping. Reproduce with the provided test.yml and typescript-axios command, then verify generated api.ts uses Asterisk: '/' and keeps the other enum entries unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.