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

kiota go generator loses properties in schema that contains a oneOf #2720

Open
mikekistler opened this issue Jun 1, 2023 · 6 comments
Open
Assignees
Labels
generator Issues or improvements relater to generation capabilities. type:bug A broken experience
Milestone

Comments

@mikekistler
Copy link
Member

Given a schema that contains properties and a oneOf, the properties of the schema are not present in the generated struct for the schema. An example:

    Widget:
      type: object
      properties:
        kind:
          type: string
        id:
          type: string
        weight:
          type: integer
          format: int32
      required:
        - id
        - kind
        - weight
      oneOf:
        - $ref: '#/components/schemas/Gadget'
        - $ref: '#/components/schemas/WingDing'

The Widget struct generated by Kiota looks like this:

// Widget composed type wrapper for classes Gadget, WingDing
type Widget struct {
    // Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
    additionalData map[string]any
    // Composed type representation for type Gadget
    gadget Gadgetable
    // Serialization hint for the current wrapper.
    SerializationHint *string
    // Composed type representation for type WingDing
    wingDing WingDingable
}

Note that the struct does not contain an id or weight property.

@baywet
Copy link
Member

baywet commented Jun 7, 2023

Thanks for reporting this @mikekistler
This is probably not limited to one of but also impacts arrays, all of and any of.
And it's not limited to go.
We should probably determine what we expect to happen in that case?
Should the properties be considered like another one of entry?

@baywet baywet self-assigned this Jun 7, 2023
@baywet baywet added enhancement New feature or request needs more information generator Issues or improvements relater to generation capabilities. Needs: Author Feedback and removed Needs: Triage 🔍 labels Jun 7, 2023
@baywet baywet added this to the Backlog milestone Jun 7, 2023
@baywet baywet added this to Kiota Jun 7, 2023
@github-project-automation github-project-automation bot moved this to Todo in Kiota Jun 7, 2023
@microsoft-github-policy-service
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@mikekistler
Copy link
Member Author

@baywet not stale.

@baywet
Copy link
Member

baywet commented Nov 3, 2023

@mikekistler Thank you for your patience on this one, can you try to repo on 1.8.1 and let us know whether this is still happening please?

@mikekistler
Copy link
Member Author

It is still happening, though the exact behavior has changed somewhat. With 1.8.1 the Widget schema to converted to the following Go struct:

// Widget composed type wrapper for classes Gadget, WingDing
type Widget struct {
    // Composed type representation for type Gadget
    gadget Gadgetable
    // Composed type representation for type WingDing
    wingDing WingDingable
}

The id and weight fields are still missing.

@baywet
Copy link
Member

baywet commented May 17, 2024

Note: I recently tested this one again and this is still a problem. The root properties are still missing. This is an area we should switch to pattern matching to exhaust all the scenarios like we did for all of in #4381 and #4668.
What's interesting here is this is equivalent to a allof (schema with properties at root + schema with the two one of), maybe there's something to do in a pre-conversion instead?
@darrelmiller for language that do not support union types what would you want to have projected here? Duplicate the properties in the one of members? (could be messy if those schemas are referenced multiple places)

@baywet baywet added type:bug A broken experience and removed enhancement New feature or request Needs: Attention 👋 labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. type:bug A broken experience
Projects
Status: New📃
Development

No branches or pull requests

4 participants