-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
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 clientSteps 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.