OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] Generator creates empty interface from anyOf instead of union type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When using the typescript-axios generator, if an OpenAPI schema property has an anyOf with a title attribute, the generator creates a separate empty interface based on that title instead of generating a proper union type.
OpenAPI Specification
{
"openapi": "3.1.0",
"info": {
"title": "Demo",
"version": "0.1.0"
},
"paths": {
"/users": {
"get": {
"summary": "Read Root",
"operationId": "read_root_users_get",
"parameters": [
{
"name": "expand",
"in": "query",
"required": false,
"schema": {
"type": "boolean",
"default": false,
"title": "Expand"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserResponse"
},
"title": "Response Read Root Users Get"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Trip": {
"properties": {
"id": {
"type": "string",
"title": "Id"
},
"destination": {
"type": "string",
"title": "Destination"
},
"date": {
"type": "string",
"title": "Date"
}
},
"type": "object",
"required": [
"id",
"destination",
"date"
],
"title": "Trip"
},
"UserResponse": {
"properties": {
"id": {
"type": "string",
"title": "Id"
},
"booked_trips": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"items": {
"$ref": "#/components/schemas/Trip"
},
"type": "array"
}
],
"title": "Booked Trips"
}
},
"type": "object",
"required": [
"id",
"booked_trips"
],
"title": "UserResponse"
}
}
}
}
Generator Command
docker run --rm \
-v "${PWD}:/local" \
openapitools/openapi-generator-cli generate \
-i /local/openapi.json \
-g typescript-axios \
-o /local/output
Actual Output
export interface Trip {
'id': string;
'destination': string;
'date': string;
}
export interface UserResponse {
'id': string;
'booked_trips': UserResponseBookedTrips;
}
export interface UserResponseBookedTrips {
}
Expected Output
The generator should generate a proper union type:
user-response.ts:
import type { Trip } from './trip';
export interface UserResponse {
'id': string;
'booked_trips': Array<string> | Array<Trip>;
}
Environment
- OpenAPI Generator version: 7.18.0-SNAPSHOT
- Generator: typescript-axios
- OpenAPI version: 3.1.0
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
Reproduce the issue with the provided openapi.json and the typescript-axios generator command, then inspect the generated user-response.ts output. Compare the generated booked_trips type with the expected Array | Array union and verify that the empty UserResponseBookedTrips interface is no longer produced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100