microsoft / kiota

OpenAPI based HTTP Client code generator
https://aka.ms/kiota/docs
MIT License
3.02k stars 210 forks source link

Unable to find factory method for Kiota.Builder.CodeDOM.CodeUnionType for `oneOf` and `allOf` schema #3105

Closed zoeyzuo-se closed 1 year ago

zoeyzuo-se commented 1 year ago

Hi I'm using VSCode extension to generate Typescript SDK from an OpenAPI Spec file but having the following error. I believe it's related to the schema contains allOf or oneOf in it. I tried different scenarios that when the schema hierarchy doesn't contain one of them then the generator works fine without any error.

Error message

image

OpenAPI Spec file

openapi: 3.0.0
info:
  title: Mock API
  version: '1.0.0'
  description: Mock API to reproduce issue with kiota generator
paths:
  /mystuff:
    get:
      operationId: mystuff_get
      responses:
        '200':
          description: The request has succeeded.
          headers:
            schema:
              required: true
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    $ref: '#/components/schemas/ParentSchema'
                required:
                  - results
                x-typespec-name: (anonymous model)

components:
  schemas:
    ParentSchema:
      type: object
      properties:
        name:
          type: string
        firstChild:
          allOf:
            - $ref: '#/components/schemas/NormalChild'
        secondChild:
          $ref: '#/components/schemas/ChildCOntainsOneOf'
      required:
        - name
        - firstChild
        - secondChild
    NormalChild:
      type: object
      properties:
        key:
          type: string
      required:
        - key
    ChildCOntainsOneOf:
      discriminator:
        propertyName: schemaType
      oneOf:
        - $ref: '#/components/schemas/RandomSchema_1'
        - $ref: '#/components/schemas/RandomSchema_2'
    RandomSchema_1:
      type: object
      properties:
        schemaType:
          type: string
          enum:
            - absolute
        key:
          type: integer
      required:
        - key
    RandomSchema_2:
      type: object
      properties:
        schemaType:
          type: string
          enum:
            - relative
        key:
          type: integer
        index:
          type: integer
      required:
        - index
        - key
servers:
  - url: https://example.com
    description: Single server endpoint
    variables: {}

Steps to reproduce:

  1. In VSCode extension, run > Kiota OpenAPI Explorer and choose this file
  2. Put in the parameters required
  3. An error will show up in the bottom right corner

Note

The error doesn't show up when generating the SDK in Python.

Any help would be appreciated. :)

baywet commented 1 year ago

Hey @zoeyzuo-se, This is expected, composed types serialization hasn't been implemented yet in TypeScript. But this is being worked on right now #1812 and the hope is that it'll be available with the next minor version of kiota. Closing as duplicated.

zoeyzuo-se commented 1 year ago

Hi @baywet

Thanks for the reply. May I ask is there an ETA for the next minor version?

baywet commented 1 year ago

Early September