microsoft / microsoft/kiota

Invalid C# for anyOf with nullable UUID array

Open
#7,188 1 comment 1 reaction 2 assignees Claimed by @gavinbarron View on GitHub
Csharp type:bug
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

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

When an OpenAPI schema has an anyOf with a UUID array and null:
```yml
validation_files:
anyOf:
- items:
format: uuid
type: string
type: array
- type: 'null'
```

Kiota generates:
```csharp
if(parseNode.GetCollectionOfPrimitiveValues()?.AsList() is List guidValue)
{
result.Guid = guidValue;
}
```

This doesn't compile - List can't be pattern-matched to List.

### Expected behavior

Code compiles.

### How to reproduce

```
mkdir /tmp/kiota-bug && cd /tmp/kiota-bug
kiota generate -l CSharp -d openapi.yaml -o . -n Test -c TestClient
dotnet new classlib && dotnet add package Microsoft.Kiota.Bundle
dotnet build
```

### Open API description file

```yml
openapi: 3.1.0
info:
title: Test
version: 1.0.0
paths:
/test:
get:
operationId: test
responses:
'200':
content:
application/json:
schema:
properties:
files:
anyOf:
- items:
format: uuid
type: string
type: array
- type: 'null'
type: object
```

### Kiota Version

1.29.0+c21ebceb977bc33def3d8a9e5237b798a7b962b6

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

_No response_

### Known Workarounds

_No response_

### Configuration

- OS: MacOS
- Architecture: ARM64

### Debug output

Click to expand log
```

dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.29.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.0040359
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/ - A servers entry (v3) or host + basePath + schemes properties (v2) was not present in the OpenAPI description. The root URL will need to be set manually with the request adapter.
fail: Kiota.Builder.KiotaBuilder[0]
OpenAPI error: #/paths/~1test/get/responses/200/description - The field 'description' in 'response' object is REQUIRED.
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.0441865
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0000530
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0022637
warn: Kiota.Builder.KiotaBuilder[0]
No server url found in the OpenAPI document. The base url will need to be set when using the client.
dbug: Kiota.Builder.KiotaBuilder[0]
step 5 - checking whether the output should be updated - took 00:00:00.0089746
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0015642
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0016758
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0015748
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.0295618
dbug: Kiota.Builder.KiotaBuilder[0]
12ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0125041
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.0160745
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0096806
Generation completed successfully
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: /private/tmp/kiota-bug/apimanifest.json

```

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.