OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] HTML-escaped values in imports when using "anyOf" enums (OpenAPI 3.0)
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?
- 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 am seeing broken Typescript when generating a client from an OpenAPI 3.0 spec using anyOf with enums.
Older versions of openapi-generator (ex. 7.11.0) work, and setting the OpenAPI spec version to 3.1.0 also works.
openapi-generator version
7.18.0
OpenAPI declaration file content or url
{
"openapi": "3.0.2",
"info": {
"title": "Test",
"version": "main-20250922183409-dabb5d59"
},
"paths": {
"/test": {
"get": {
"summary": "Test API",
"operationId": "test_api",
"parameters": [
{
"description": "Combined Enums",
"required": true,
"schema": {
"title": "Combined",
"anyOf": [
{
"$ref": "#/components/schemas/Enum1"
},
{
"$ref": "#/components/schemas/Enum2"
}
],
"description": "Combined Enums"
},
"example": "value1",
"name": "combined",
"in": "query"
}
],
"responses": {
"204": {
"description": "Successful Response"
}
}
}
}
},
"components": {
"schemas": {
"Enum1": {
"title": "Enum1",
"enum": ["value1", "value2", "value3"],
"type": "string",
"description": "An enumeration."
},
"Enum2": {
"title": "Enum2",
"enum": ["value4", "value5"],
"type": "string",
"description": "An enumeration."
}
}
},
"tags": []
}
Generation Details
openapi-generator generate -i openapi.json -g typescript-fetch -o client
Steps to reproduce
The resulting code tries to import HTML-escaped string values rather than an enum type:
import * as runtime from '../runtime';
import type {
'value1',
'value2',
'value3',
'value4',
'value5',
} from '../models/index';
import {
'value1'FromJSON,
'value1'ToJSON,
'value2'FromJSON,
'value2'ToJSON,
'value3'FromJSON,
'value3'ToJSON,
'value4'FromJSON,
'value4'ToJSON,
'value5'FromJSON,
'value5'ToJSON,
} from '../models/index';
The generated code should look something like this:
import * as runtime from '../runtime';
import type {
Combined,
} from '../models/index';
import {
CombinedFromJSON,
CombinedToJSON,
} from '../models/index';
Related issues/PRs
There are a bunch of issues that seem similar (#22427, #21587, #19155, #18207) but none that fits this behavior exactly.
Suggest a fix
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 by running the supplied OpenAPI 3.0.2 declaration through the typescript-fetch generator command and compare the generated imports with the reported output. Trace the anyOf enum handling that produces the imports, then verify generation uses the Combined type and its conversion functions instead of HTML-escaped enum values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100