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 Client #5771

Open
damianh opened this issue Nov 13, 2024 · 2 comments
Open

Kiota Client #5771

damianh opened this issue Nov 13, 2024 · 2 comments
Labels
Csharp Pull requests that update .net code Needs: Discussion 📢 type:bug A broken experience

Comments

@damianh
Copy link

damianh commented Nov 13, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Windows executable

Client library/SDK language

Csharp

Describe the bug

I've using Kiota (version 1.19.1+d294e04ba7f756896878a7015df1648f9dc0bcde) to generate HubSpot clients from their OpenAPI catalog which contains ~85 separate specs. 4 of which failed with a stack overflow exception:

 at Kiota.Builder.Extensions.OpenApiSchemaExtensions.GetDiscriminatorPropertyName(Microsoft.OpenApi.Models.OpenApiSchema)
   at System.Linq.Enumerable+SelectListIterator`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable.TryGetFirst[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Func`2<System.__Canon,Boolean>, Boolean ByRef)
   at System.Linq.Enumerable.FirstOrDefault[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Func`2<System.__Canon,Boolean>)
   at Kiota.Builder.Extensions.OpenApiSchemaExtensions.GetDiscriminatorPropertyName(Microsoft.OpenApi.Models.OpenApiSchema)
   at System.Linq.Enumerable+SelectListIterator`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable.TryGetFirst[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Func`2<System.__Canon,Boolean>, Boolean ByRef)
   at System.Linq.Enumerable.FirstOrDefault[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable`1<System.__Canon>, System.Func`2<System.__Canon,Boolean>)
   ... repeats

Expected behavior

Should generate a c# client.

How to reproduce

kiota generate --openapi https://api.hubspot.com/public/api/spec/v1/specs/Automation/Automation%20V4/versions/144908 --language csharp
kiota generate --openapi https://api.hubspot.com/public/api/spec/v1/specs/CRM/Exports/versions/95922 --language csharp
kiota generate --openapi https://api.hubspot.com/public/api/spec/v1/specs/Conversations/Conversations%20Inbox%20&%20Messages/versions/54902 --language csharp

Open API description file

https://api.hubspot.com/public/api/spec/v1/specs/Automation/Automation%20V4/versions/144908
https://api.hubspot.com/public/api/spec/v1/specs/CRM/Exports/versions/95922
https://api.hubspot.com/public/api/spec/v1/specs/Conversations/Conversations%20Inbox%20&%20Messages/versions/54902

Kiota Version

1.19.1+d294e04ba7f756896878a7015df1648f9dc0bcde

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

No response

Known Workarounds

None

Configuration

  • OS: Windows 11 x64.

Debug output

--debug flag didn't work.

Image

Other information

No response

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

Thanks for raising this @damianh

--debug flag didn't work.

This looks to be related to the PR created at #5780. Any chance you can obtain a trace using --ll debug instead?

@andrueastman
Copy link
Member

With the description from https://api.hubspot.com/public/api/spec/v1/specs/Automation/Automation%20V4/versions/144908

The stackoverflow seems to be caused by the method at

internal static string GetDiscriminatorPropertyName(this OpenApiSchema schema)

The description defines the schema below with two oneOfs.

      "ApiFlowCreateRequest" : {
        "properties" : { },
        "oneOf" : [ {
          "$ref" : "#/components/schemas/ApiContactFlowCreateRequest"
        }, {
          "$ref" : "#/components/schemas/ApiPlatformFlowCreateRequest"
        } ]
      },

However the referenced oneOfs end up referencing the same schema in the AllOf as

"ApiContactFlowCreateRequest" : {
        "properties" : { },
        "allOf" : [ {
          "$ref" : "#/components/schemas/ApiFlowCreateRequest"
        }, {
          "required" : [ "actions", "blockedDates", "canEnrollFromSalesforce", "customProperties", "flowType", "isEnabled", "objectTypeId", "suppressionListIds", "timeWindows", "type" ],
          "type" : "object",
          "properties" : {
            "type" : {
              "type" : "string",
              "default" : "CONTACT_FLOW",
              "enum" : [ "WORKFLOW", "ACTION_SET", "UNKNOWN" ]
            },
.....

So as the code recursively looks for the discriminator name from the base, the oneOfs end up referencing the base again in the allOf to end up in an infinite loop.

One thing I'm not sure if this is valid OpenApi or should Kiota detect the oneOfs in such a scenario as possible derived types(rather than trying to create a union type) given that what we ideally expect is an empty schema with a discriminator property name? cc @baywet

@andrueastman andrueastman moved this from Needs Triage 🔍 to Todo 📃 in Kiota Nov 15, 2024
@andrueastman andrueastman added Needs: Discussion 📢 and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Nov 15, 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 Needs: Discussion 📢 type:bug A broken experience
Projects
Status: Todo 📃
Development

No branches or pull requests

2 participants