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

Problem generating model(s) when schema has type: object with oneOf with single ref referring to component using allOf #5921

Closed
vipentti opened this issue Dec 19, 2024 · 1 comment · Fixed by #5930
Assignees
Labels
Csharp Pull requests that update .net code type:bug A broken experience WIP
Milestone

Comments

@vipentti
Copy link
Contributor

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

This is similar issue as #5808 where the contract we received has oneOf hierarchies where there is only a single ref under oneOf but the schema had type: object set. If the type: object is set, the contract does not generate the expected models.

Expected behavior

Kiota generates code for both schemas, with or without type: object.

    # ... rest of the schema ...
    # Does not work (Component1) is not generated at all or mentioned in the
    # generated ExampleWithSingleOneOfWithTypeObject type.
    ExampleWithSingleOneOfWithTypeObject:
      # Removing this works
      type: object
      oneOf:
        - $ref: "#/components/schemas/Component1"
      discriminator:
        propertyName: objectType

    # Does work (Component2) e.g. Component2 is used in place of ExampleWithSingleOneOfWithoutTypeObject
    ExampleWithSingleOneOfWithoutTypeObject:
      oneOf:
        - $ref: "#/components/schemas/Component2"
      discriminator:
        propertyName: objectType
    # ... rest of the schema ...

How to reproduce

I have a repository with the generated client and example schema which reproduce the issue available:

Open API description file

https://github.com/vipentti/kiota-type-object-one-of-issue/blob/main/DiscriminatorProblemSampleHierarchy.yaml

Kiota Version

1.21.0+ec3a3fff9fc6e2fb7de190d37969fa2e93aefdf5

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

  • OS: Windows 11
  • Architecture: x64

Debug output

Click to expand log
info: Kiota.Builder.KiotaBuilder[0]
      Cleaning output directory _root_\kiota-type-object-one-of-issue\.\Generated\Hierarchy\CSharp
dbug: Kiota.Builder.KiotaBuilder[0]
      kiota version 1.21.0
info: Kiota.Builder.KiotaBuilder[0]
      loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
      step 1 - reading the stream - took 00:00:00.0052293
dbug: Kiota.Builder.KiotaBuilder[0]
      step 2 - parsing the document - took 00:00:00.0687352
dbug: Kiota.Builder.KiotaBuilder[0]
      step 3 - updating generation configuration from kiota extension - took 00:00:00.0000606
dbug: Kiota.Builder.KiotaBuilder[0]
      step 4 - filtering API paths with patterns - took 00:00:00.0032164
info: Kiota.Builder.KiotaBuilder[0]
      Client root URL set to https://mytodos.doesnotexist
dbug: Kiota.Builder.KiotaBuilder[0]
      step 5 - checking whether the output should be updated - took 00:00:00.0077425
dbug: Kiota.Builder.KiotaBuilder[0]
      step 6 - create uri space - took 00:00:00.0023395
dbug: Kiota.Builder.KiotaBuilder[0]
      InitializeInheritanceIndex 00:00:00.0023997
dbug: Kiota.Builder.KiotaBuilder[0]
      CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
      MapTypeDefinitions 00:00:00.0034072
info: Kiota.Builder.KiotaBuilder[0]
      Removing unused model Component1 as it is not referenced by the client API surface
dbug: Kiota.Builder.KiotaBuilder[0]
      TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
      CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
      step 7 - create source model - took 00:00:00.0470989
dbug: Kiota.Builder.KiotaBuilder[0]
      14ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
      step 8 - refine by language - took 00:00:00.0149214
dbug: Kiota.Builder.KiotaBuilder[0]
      step 9 - writing files - took 00:00:00.0197369
info: Kiota.Builder.KiotaBuilder[0]
      loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
      step 10 - writing lock file - took 00:00:00.0085050
Generation completed successfully
Client base url set to https://mytodos.doesnotexist
dbug: Kiota.Builder.KiotaBuilder[0]
      Api manifest path: _root_\kiota-type-object-one-of-issue\apimanifest.json

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -d "_root_\kiota-type-object-one-of-issue\.\DiscriminatorProblemSampleHierarchy.yaml" -l CSharp

Hint: use the --include-path and --exclude-path options with glob patterns to filter the paths generated.
Example: kiota generate --include-path "**/foo" -d "_root_\kiota-type-object-one-of-issue\.\DiscriminatorProblemSampleHierarchy.yaml"

Other information

Continuation of issue #5808 which was fixed by #5827.

@vipentti vipentti added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Dec 19, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Dec 19, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Dec 19, 2024
@baywet
Copy link
Member

baywet commented Dec 23, 2024

Hi @vipentti
Thank you for using kiota and for reaching out.

I'd like to mention that we're operating with a reduced team at the moment, expect delays in responses, thank you for your patience!

I can see that you've already submitted a PR, thanks! I'll head over there and provide feedback.

Let us know if you have any additional comments or questions.

@baywet baywet removed the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Dec 23, 2024
@baywet baywet moved this from Needs Triage 🔍 to In Progress 🚧 in Kiota Dec 23, 2024
@baywet baywet added this to the Kiota v1.22 milestone Dec 23, 2024
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code type:bug A broken experience WIP
Projects
Status: Done ✔️
Development

Successfully merging a pull request may close this issue.

2 participants