Skip to content

[BUG] [typescript-fetch] Self-referencing types for oneOf where property name and type name match #15212

@cogwirrel

Description

@cogwirrel

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

The typescript-fetch generator generates interfaces which reference themselves for oneOf object schemas where the property names of these objects are the same as the type names, since it generates intermediate types with the same name, eg:

/**
 * @type FooOrBar
 * 
 * @export
 */
export type FooOrBar = Bar | Foo;
/**
 * 
 * @export
 * @interface Foo
 */
export interface Foo {
    /**
     * 
     * @type {Foo}
     * @memberof Foo
     */
    foo: Foo;
}
openapi-generator version

6.3.0. Also tried with latest mainline.

OpenAPI declaration file content or url

Full example: https://gist.github.com/cogwirrel/6f6355e04b831bfbbbe57337b3429b9c

Example of just the schema part below

{
  "oneOf": [
    {
      "type": "object",
      "title": "foo",
      "properties": {
        "foo": {
          "$ref": "#/components/schemas/Foo"
        }
      },
      "required": [
        "foo"
      ]
    },
    {
      "type": "object",
      "title": "bar",
      "properties": {
        "bar": {
          "$ref": "#/components/schemas/Bar"
        }
      },
      "required": [
        "bar"
      ]
    }
  ]
}
Generation Details

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g typescript-fetch -i https://gist.githubusercontent.com/cogwirrel/6f6355e04b831bfbbbe57337b3429b9c/raw/38c4af6ae02d8dd0c8bfc7a29c9f9d63069154ad/example-api-oneof-issue.json -o ./oneof-test

Steps to reproduce
  • Checkout latest mainline
  • Build with ./mvnw clean install
  • Run java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g typescript-fetch -i https://gist.githubusercontent.com/cogwirrel/6f6355e04b831bfbbbe57337b3429b9c/raw/38c4af6ae02d8dd0c8bfc7a29c9f9d63069154ad/example-api-oneof-issue.json -o ./oneof-test

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions