Error Response Generated wrongly if error response is array of errors
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:
"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:
<exception cref="List<global::[PROJECT_NAMESPACE].Http.Models.SnelStart.B2B.Api.V2.Models.BadRequestEntry>">When receiving a 400 status code</exception>
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
Seems my search wasn't extensive enough - but found another from 2023: https://github.com/microsoft/kiota/issues/3827
Maybe instead of saying this a limitation - maybe work to a solution? I can think of a few:
- Implement the generic
ApiException<TModel>as mentioned at https://github.com/microsoft/kiota/issues/4349 - Instead of flattening the Schema (removal of
BadRequestResponse) - generate aBadRequestResponsewhich itself contains anItemsproperty (just as the OpenAPI specifies) and make that aList<BadRequestEntry>- this wayBadRequestResponsecan extendApiExceptionand be throwable but still allow access to the errors