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

Stack overflow exception generating a client #5771

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

Stack overflow exception generating a client #5771

damianh opened this issue Nov 13, 2024 · 3 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'm 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
@damianh damianh changed the title Kiota Client Stack overflow exception generating a client Nov 21, 2024
@damianh
Copy link
Author

damianh commented Nov 21, 2024

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?

dbug: Kiota.Builder.KiotaBuilder[0]
      kiota version 1.19.1
dbug: Kiota.Builder.KiotaBuilder[0]
      cache file C:\Users\damian\AppData\Local\Temp\kiota\cache\generation\10B428847C2EF34D3D888CC60E23691E9BCFB7DEE7C73F0385B65D8D3FC0590E\144908 is up to date and clearCache is False, using it
info: Kiota.Builder.KiotaBuilder[0]
      loaded description from remote source
dbug: Kiota.Builder.KiotaBuilder[0]
      step 1 - reading the stream - took 00:00:00.0077677
warn: Kiota.Builder.KiotaBuilder[0]
      OpenAPI warning: #/ - The schema ApiFlow is a polymorphic type but does not define a discriminator. This will result in a serialization errors.
dbug: Kiota.Builder.KiotaBuilder[0]
      step 2 - parsing the document - took 00:00:00.1070247
dbug: Kiota.Builder.KiotaBuilder[0]
      step 3 - updating generation configuration from kiota extension - took 00:00:00.0000564
dbug: Kiota.Builder.KiotaBuilder[0]
      step 4 - filtering API paths with patterns - took 00:00:00.0027410
info: Kiota.Builder.KiotaBuilder[0]
      Client root URL set to https://api.hubapi.com
dbug: Kiota.Builder.KiotaBuilder[0]
      step 5 - checking whether the output should be updated - took 00:00:00.0124735
dbug: Kiota.Builder.KiotaBuilder[0]
      step 6 - create uri space - took 00:00:00.0025629
dbug: Kiota.Builder.KiotaBuilder[0]
      InitializeInheritanceIndex 00:00:00.0020791

That's as much output I was able to capture from a trace before the SOE occurs.

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