openapi-typescript version
7.8.0
Node.js version
18.20.4
OS + version
macOS 15.5
Description
I have an API endpoint like the following. Note the oneOf in the error response--this can return a Bad Request error from Node Express, or a custom application error.
paths:
/api/v1/islands/cms/posts:
get:
tags:
- Islands
operationId: GetIslandPosts
summary: Get all posts
security: []
parameters:
- in: query
name: limit
required: false
schema:
type: number
minimum: 1
maximum: 30
default: 20
- in: query
name: nextCursor
required: false
schema:
type: string
responses:
'200':
description: List of posts
content:
application/json:
schema:
$ref: '../generated/openapi/types/json-schema/islands/GetIslandPostsResponse.json'
'400':
description: Bad request
content:
application/json:
schema:
oneOf:
- $ref: '../generated/openapi/types/json-schema/shared/BadRequestError.json'
- $ref: '../generated/openapi/types/json-schema/shared/AppError.json'
This generates invalid typescript in dist/openapi/typescript/client/models/GetIslandPosts400Response.ts because it generates the following union but does not import the members of the union:
/* tslint:disable */
/* eslint-disable */
/**
* Example API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* @type GetIslandPosts400Response
*
* @export
*/
export type GetIslandPosts400Response = GetIslandPosts400ResponseOneOf | GetIslandPosts400ResponseOneOf1;
export function GetIslandPosts400ResponseFromJSON(json: any): GetIslandPosts400Response {
return GetIslandPosts400ResponseFromJSONTyped(json, false);
}
<snip>
This in particular:
export type GetIslandPosts400Response = GetIslandPosts400ResponseOneOf | GetIslandPosts400ResponseOneOf1;
This would be correct if it included the imports, which exist. This is valid and compiles, eg:
import { GetIslandPosts400ResponseOneOf } from './GetIslandPosts400ResponseOneOf';
import { GetIslandPosts400ResponseOneOf1 } from './GetIslandPosts400ResponseOneOf1';
export type GetIslandPosts400Response = GetIslandPosts400ResponseOneOf | GetIslandPosts400ResponseOneOf1;
Am I misusing this library somehow?
Reproduction
I am generating the output libraries like so:
openapi-generator generate \
-i ./openapi/openapi.yaml \
-g typescript-fetch \
-o generated/openapi/typescript/client \
--additional-properties=supportsES6=true,modelPropertyNaming=original,withoutDate=true
Expected result
I would expect the output files to import all the types they use and result in valid typescript.
Am I misusing something?
Required
Extra
openapi-typescript version
7.8.0
Node.js version
18.20.4
OS + version
macOS 15.5
Description
I have an API endpoint like the following. Note the
oneOfin the error response--this can return a Bad Request error from Node Express, or a custom application error.This generates invalid typescript in
dist/openapi/typescript/client/models/GetIslandPosts400Response.tsbecause it generates the following union but does not import the members of the union:This in particular:
This would be correct if it included the imports, which exist. This is valid and compiles, eg:
Am I misusing this library somehow?
Reproduction
I am generating the output libraries like so:
Expected result
I would expect the output files to import all the types they use and result in valid typescript.
Am I misusing something?
Required
npx @redocly/cli@latest lint)Extra