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

Typescript fetch node client generator discriminator issue #48

Open
Sholto opened this issue Apr 5, 2024 · 0 comments
Open

Typescript fetch node client generator discriminator issue #48

Sholto opened this issue Apr 5, 2024 · 0 comments

Comments

@Sholto
Copy link

Sholto commented Apr 5, 2024

When an object is extended and that objected has a discriminator, the field that acts as the discriminator is removed from the object.

To illustrate:

components:
  schemas:
    ObjectWithDiscriminator:
      oneOf:
        - $ref: '#/components/schemas/SubObject1'
        - $ref: '#/components/schemas/SubObject2'
      discriminator:
        propertyName: thisProperty
        mapping:
          true: '#/components/schemas/SubObject1'
          false: '#/components/schemas/SubObject2'

    SubObject1:
      type: object
      required:
        - thisProperty
        - otherProperty1
      properties:
        thisProperty:
          type: boolean
        otherProperty1:
          type: string

    SubObject2:
      allOf:
        - $ref: '#/components/schemas/IndependentObject'

    IndependentObject:
      type: object
      required:
        - thisProperty
      properties:
        thisProperty:
          type: boolean
        otherProperty2:
          type: string

Yields:

    interface SubObject2 extends Api.IndependentObject {
        /**
         * Value for discriminator in Api.SubObject2
         */
        thisProperty: false;
    }

    interface IndependentObject {
        otherProperty2?: string;
    }

As you can see, IndependentObject is now missing a declaration for thisProperty. It should look like:

Yields:

    interface SubObject2 extends Api.IndependentObject {
        /**
         * Value for discriminator in Api.SubObject2
         */
        thisProperty: false;
    }

    interface IndependentObject {
        thisProperty: boolean;
        otherProperty2?: string;
    }

Note: Generation appears to work in typescript-fetch-client-generator2.

@Sholto Sholto changed the title Typescript fetch node client generator error Typescript fetch node client generator discriminator issue Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant