Skip to content

[BUG] typescript-fetch missing model imports when using oneOf #21587

@srsudar

Description

@srsudar

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 trying to use the typescript-fetch generator to generate libraries for my openapi spec. When I define a 400 response that has oneOf, the resulting TS file does not include the imports for the referenced files, resulting in invalid typescript.

openapi-generator version
$ openapi-generator --version
openapi-generator-cli 7.14.0
  commit : 5eb083e
  built  : -999999999-01-01T00:00:00+18:00
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: Example API
  version: 1.0.0
  license:
    name: UNLICENSED
    url: 'https://example.com/tos'
servers:
  - url: https://example.com
    description: Main API server
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:
                type: object
                oneOf:
                  - $ref: '../generated/openapi/types/json-schema/shared/BadRequestError.json'
                  - $ref: '../generated/openapi/types/json-schema/shared/AppError.json'
Generation Details
openapi-generator generate \
  -i ./openapi/openapi.yaml \
  -g typescript-fetch \
  -o generated/openapi/typescript/client \
  --additional-properties=supportsES6=true,modelPropertyNaming=original,withoutDate=true
Steps to reproduce

Running the command above produces a file, dist/openapi/typescript/client/models/GetIslandPosts400Response.ts, that is missing imports for the referenced models in oneOf.

It produces this snippet:

/* 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>

If I add these imports, it is fixed:

import { GetIslandPosts400ResponseOneOf } from './GetIslandPosts400ResponseOneOf';
import { GetIslandPosts400ResponseOneOf1 } from './GetIslandPosts400ResponseOneOf1';

export type GetIslandPosts400Response = GetIslandPosts400ResponseOneOf | GetIslandPosts400ResponseOneOf1;
Related issues/PRs
  1. Fix typescript-fetch broken files when mixing basic types and refs in oneOf #21057
  2. [BUG] [typescript-fetch] Imports are absent for oneof field with discriminator #21441
Suggest a fix

Importing the models seems like it would be enough. My entire .yaml file passes redocly lint. I don't know if I'm misusing something else, but it looks like this should be valid to me?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions