Error Response Generated wrongly if error response is array of errors
- 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
The API (Snelstart B2B API) I am implementing returns a list of validation errors on a `400` response - I tried to model this (as their OpenAPI document is missing it) as follows:
```json
"Snelstart.B2B.Api.V2.Models.BadRequestEntry": {
"type": "object",
"properties": {
"errorCode": {
"type": "string"
},
"message": {
"type": "string"
},
"details": {
"type": "string",
"nullable": true
}
},
"description": "BadRequestEntry"
},
"Snelstart.B2B.Api.V2.Models.BadRequestResponse": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Snelstart.B2B.Api.V2.Models.BadRequestEntry"
}
},
```
But this results in the following docs to be generated:
```XML
When receiving a 400 status code
```
As far as I know one cannot throw a list of exceptions - add to that it doesn't even resolve it correctly, it's all empty
### Expected behavior
I expected it to generate a `BadRequestResponse` which contained a list of the errors
### How to reproduce
Define a 400 response with the above schema - generate it - and get lot's of malformed XML errors due it generating wrongly
### Open API description file
Modified version of Snelstart B2B API OpenAPI description as they are missing the 400 body's themselve (and other stuff)
https://gist.github.com/ThaDaVos/a03ff003b38618cba93cffd54d69d4f7
### Kiota Version
1.28.0+57130b1b1db3bc5c060498682f41e20c8ae089f2
### Latest Kiota version known to work for scenario above?(Not required)
_No response_
### Known Workarounds
Currently trying to see if I model it like a object (instead of an array) how it generates, but not a know workaround
### Configuration
- OS: Windows 11
- Architecture: x64
- Not specific
### Debug output
Click to expand log
```
info: Kiota.Builder.KiotaBuilder[0]
Cleaning output directory {BASE_PATH}\Http
dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.28.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.0066920
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.1253294
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0000751
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0030404
info: Kiota.Builder.KiotaBuilder[0]
Client root URL set to https://b2bapi.snelstart.nl/v2
dbug: Kiota.Builder.KiotaBuilder[0]
step 5 - checking whether the output should be updated - took 00:00:00.0252752
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0105642
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0078794
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0100664
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.1680378
dbug: Kiota.Builder.KiotaBuilder[0]
61ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0620116
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.1453844
info: Kiota.Builder.KiotaBuilder[0]
loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0179232
Generation completed successfully
Client base url set to https://b2bapi.snelstart.nl/v2
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: P:\EsPos\EsAccounting\apimanifest.json
```
### Other information
I created a specific issue on the `kiota-dotnet` repo first - but I open this one as I think the issue will happen for other languages too
https://github.com/microsoft/kiota-dotnet/issues/563
Contributor guide
Research direction
Start with the linked OpenAPI description and reproduce generation with Kiota 1.28.0, then inspect the generated C# XML documentation and error-response model. Compare the generated result for the array-based 400 response with the expected BadRequestResponse containing BadRequestEntry items, and check the related kiota-dotnet issue for existing context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100