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

Code generation failing using anyOf schema type given a property in a requestBody with two items - at least one of which is nullable. #5276

Closed
matthew-c-hpe opened this issue Aug 30, 2024 · 1 comment · Fixed by #5281
Assignees
Labels
generator Issues or improvements relater to generation capabilities. type:bug A broken experience WIP
Milestone

Comments

@matthew-c-hpe
Copy link

matthew-c-hpe commented Aug 30, 2024

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Linux executable

Client library/SDK language

Go

Describe the bug

I am trying to auto-generate a client using Kiota but when using anyOf schema type for a property in a responseBody, the generation fails if the property has exactly two elements, at least one of which is nullable.

This bug affects all supported languages at the time of writing (CLI, CSharp, Go, Java, PHP, Python, Ruby, Swift, TypeScript).

https://github.com/matthew-c-hpe/kiota-bug-anyof

Expected behavior

I expect the generation to succeed, since this issue only occurs with two items in the list.
It succeeds with one item and with more than two items.

How to reproduce

Given an item in the properties map:

  • if using anyOf as schema type,
  • if the number of items in that item's list is 2,
  • and if at least one of those items is nullable (nullable: true),
  • and if at least one of those items is NOT an "object" data type (EXCEPT if the other is "array"),
    Then the Kiota autogeneration fails with the following critical error:
crit: Kiota.Builder.KiotaBuilder[0]
      error generating the client: One or more errors occurred. (Sequence contains no matching element)

Sample code can be found below:

https://github.com/matthew-c-hpe/kiota-bug-anyof

Open API description file

https://github.com/matthew-c-hpe/kiota-bug-anyof/blob/main/spec-minimal.yaml

Kiota Version

1.17.0

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

No response

Known Workarounds

Change anyOf to oneOf schema type.
Use 1 nullable item.
Use more than 2 nullable items.

Configuration

Ubuntu 22.04 (WSL2) running on Windows 10).
x64.
Do not know if this bug is specific to this configuration.

Debug output

Click to expand log
dbug: Kiota.Builder.KiotaBuilder[0]
      kiota version 1.17.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.0078402
dbug: Kiota.Builder.KiotaBuilder[0]
      step 2 - parsing the document - took 00:00:00.0943962
dbug: Kiota.Builder.KiotaBuilder[0]
      step 3 - updating generation configuration from kiota extension - took 00:00:00.0001202
dbug: Kiota.Builder.KiotaBuilder[0]
      step 4 - filtering API paths with patterns - took 00:00:00.0048345
info: Kiota.Builder.KiotaBuilder[0]
      Client root URL set to https://foo/api/v1
dbug: Kiota.Builder.KiotaBuilder[0]
      step 5 - checking whether the output should be updated - took 00:00:00.0137960
dbug: Kiota.Builder.KiotaBuilder[0]
      step 6 - create uri space - took 00:00:00.0028304
dbug: Kiota.Builder.KiotaBuilder[0]
      InitializeInheritanceIndex 00:00:00.0032005
crit: Kiota.Builder.KiotaBuilder[0]
      error generating the client: One or more errors occurred. (Sequence contains no matching element)

Other information

I am not familiar enough with C# to know where exactly this error would come from in the Kiota source code, but searching for 'sequence contains no matching element' in the Microsoft .NET documentation points to this method:

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.single?view=net-8.0

Examples of input which fails/succeeds:

Examples: FAIL

1. 2 nullable items, non-object data types
anyOf:
- type: string
  nullable: true
- type: integer
  format: int64
  nullable: true

2. 2 items, 1 of which is nullable, non-object data types
anyOf:
- type: string
  nullable: true
- type: integer
  format: int64

3. 2 items, both arrays
anyOf:
- type: array
  nullable: true
- type: array
  nullable: true

Examples: SUCCESS

1. 1 item
anyOf:
  - type: string
    nullable: true

2. Greater than 2 items
anyOf:
  - type: string
    nullable: true
  - type: integer
    format: int64
    nullable: true
  - type: boolean
    nullable: true


3. 2 items, both object data type
anyOf:
- type: object
  nullable: true
- type: object
  nullable: true

4. 2 items, one object, one array data type
- type: object
  nullable: true
- type: array
  nullable: true
@matthew-c-hpe matthew-c-hpe added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 30, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Aug 30, 2024
@msgraph-bot msgraph-bot bot added the Go label Aug 30, 2024
@baywet baywet added this to the Kiota v1.18 milestone Aug 30, 2024
@baywet baywet self-assigned this Aug 30, 2024
@baywet baywet added generator Issues or improvements relater to generation capabilities. and removed Go status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 30, 2024
@baywet
Copy link
Member

baywet commented Aug 30, 2024

Hi @matthew-c-hpe ,
Thank you for using kiota and for reaching out.
I authored #5281 to fix this issue. The detailed repro was instrumental to tracking the root cause down. Thanks!

@github-project-automation github-project-automation bot moved this from Needs Triage 🔍 to Done ✔️ in Kiota Sep 5, 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 WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants