OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generator typescript-axios produces invalid output when enum value is '*/*'
Nobody has claimed this yet.
- 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
*/*->*_*when replacing all/characters with_. Reference*_*->_when removing non-word characters with regex\W. Reference_Gets converted to empty string. Reference
For the value
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
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