Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][typescript-fetch] Nested oneOf generates type object instead of union type #20155

Open
5 of 6 tasks
foxable opened this issue Nov 21, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@foxable
Copy link

foxable commented Nov 21, 2024

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

When defining nested schemas using oneOf, the nested property will be of type object instead the corresponding union type.

openapi-generator version

This is a regression introduced in openapi-generator 7.5.0, which is still present in 7.10.0.

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test API
  version: "0.1"
paths:
  /contacts:
    get:
      operationId: getContact
      responses:
        "200":
          content:
            '*/*':
              schema:
                oneOf:
                  - $ref: "#/components/schemas/InstitutionContact"
                  - $ref: "#/components/schemas/PersonContact"
          description: OK
      tags:
        - Contact
components:
  schemas:
    Contact:
      type: object
      discriminator:
        propertyName: type
      properties:
        '@type':
          type: string
      required:
        - type
    InstitutionContact:
      type: object
      allOf:
        - $ref: "#/components/schemas/Contact"
        - type: object
          properties:
            address:
              type: object
              oneOf:
                - $ref: "#/components/schemas/DomesticAddress"
                - $ref: "#/components/schemas/PostboxAddress"
      required:
        - address
    PersonContact:
      type: object
      allOf:
        - $ref: "#/components/schemas/Contact"
        - type: object
          properties:
            address:
              type: object
              oneOf:
                - $ref: "#/components/schemas/DomesticAddress"
                - $ref: "#/components/schemas/PostboxAddress"
      required:
        - address
    Address:
      type: object
      discriminator:
        propertyName: type
      properties:
        type:
          type: string
      required:
        - type
    DomesticAddress:
      type: object
      allOf:
        - $ref: "#/components/schemas/Address"
        - type: object
          properties:
            street:
              type: string
      required:
        - street
    PostboxAddress:
      type: object
      allOf:
        - $ref: "#/components/schemas/Address"
        - type: object
          properties:
            postbox:
              type: string
      required:
        - postbox
Generation Details

I'm using the openapi-generator Gradle plugin with the following options:

'supportsES6': 'true',
'withInterfaces': 'true',
'useSingleRequestParameter': 'false',
'legacyDiscriminatorBehavior': 'false',

Up until openapi-generator 7.4.0, this generated the following types:

export type GetContact200Response = { type: 'InstitutionContact' } & InstitutionContact | { type: 'PersonContact' } & PersonContact;

export interface InstitutionContact extends Contact {
  address: InstitutionContactAllOfAddress;
}

export type InstitutionContactAllOfAddress = { type: 'DomesticAddress' } & DomesticAddress | { type: 'PostboxAddress' } & PostboxAddress;

Since openapi-generator 7.5.0, the following type is generated for InstitutionContact:

export interface InstitutionContact extends Contact {
  address: object;
}
Steps to reproduce

Execute the openapi-generator via Gradle using the specified declaration file and options, using typescript-fetch with version 7.5.0 or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant