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 #5808

Open
vipentti opened this issue Nov 21, 2024 · 0 comments
Labels
Csharp Pull requests that update .net code status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience

Comments

@vipentti
Copy link

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

We came across this when we were using Kiota to generate our C# client-code against a contract which was work in progress.

In the contract we are using we have several oneOf hierarchies and in one case there was a hierarchy where there was 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.

I have a repository with the generated clients and example schemas which reproduce the issue available at https://github.com/vipentti/kiota-type-object-one-of-issue

Expected behavior

Kiota generates code for both schemas similarly (with or without type: object) because if the type: object is present with multiple oneOf refs, code is generated as expected.

    # ... 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) is generated but ExampleWithSingleOneOfWithoutTypeObject is not
    # 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 clients and example schemas which reproduce the issue available at https://github.com/vipentti/kiota-type-object-one-of-issue

Open API description file

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

Kiota Version

1.20.0+81bdb1bf13383a749f794d47926d09733d2d7be1

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

No response

Known Workarounds

Removing the type: object if there is only one oneOf seems to work, unfortunately that may not be possible if the schema is also generated by some tool and/or provided by 3rd parties.

Configuration

  • OS: Window 10
  • Architecture: x64

Debug output

Click to expand log ```

info: Kiota.Builder.KiotaBuilder[0]
Cleaning output directory <repo_path>\kiota-type-object-one-of-issue.\Generated\Simple\CSharp
dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.20.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.0050763
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.0679186
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0000607
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0029692
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.0074799
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0023193
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0021671
warn: Kiota.Builder.KiotaBuilder[0]
Discriminator Component1 is not inherited from ExampleWithSingleOneOfWithTypeObject.
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0034938
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.0405963
dbug: Kiota.Builder.KiotaBuilder[0]
14ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0147122
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.0188196
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0083907
Generation completed successfully
Client base url set to https://mytodos.doesnotexist
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: <repo_path>\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 "<repo_path>\kiota-type-object-one-of-issue.\DiscriminatorProblemSampleSimple.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 "<repo_path>\kiota-type-object-one-of-issue.\DiscriminatorProblemSampleSimple.yaml"

</details>


### Other information

_No response_
@vipentti vipentti added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 21, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Nov 21, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Nov 21, 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 status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience
Projects
Status: Needs Triage 🔍
Development

No branches or pull requests

1 participant