Description
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
Metadata
Assignees
Type
Projects
Status
Done ✔️