-
Notifications
You must be signed in to change notification settings - Fork 305
Parameter Array - InvalidCastException #3354
Copy link
Copy link
Closed
Labels
WIPenhancementNew feature or requestNew feature or requestgeneratorIssues or improvements relater to generation capabilities.Issues or improvements relater to generation capabilities.
Milestone
Description
Hello,
I am facing the following problem.
Kiota v1.6.1
Description
Backend
I have a backend using AspNetCore's MinimalAPI as shown below:
app.MapGet("/api/ratings", ([FromQuery] long[] bookIds, [FromServices] ReviewRepository repo) =>
{
return repo.GetRatings(bookIds);
})
.WithName("GetRatings")
.WithOpenApi();OpenAPI document
{
"openapi": "3.0.1",
"info": {
"title": "BookSample.ReviewAPI",
"version": "1.0"
},
"servers": [
{
"url": "https://localhost:7078"
}
],
"paths": {
"/api/ratings": {
"get": {
"tags": [
"Ratings"
],
"operationId": "GetRatings",
"parameters": [
{
"name": "bookIds",
"in": "query",
"required": true,
"style": "form",
"schema": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
}
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/reviews": {
"get": {
"tags": [
"Reviews"
],
"operationId": "GetReviews",
"parameters": [
{
"name": "bookIds",
"in": "query",
"required": true,
"style": "form",
"schema": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Review"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Review": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"bookId": {
"type": "integer",
"format": "int64"
},
"username": {
"type": "string",
"nullable": true
},
"text": {
"type": "string",
"nullable": true
},
"stars": {
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false
}
}
}
}Client
On the client the C# API-client generated by Kiota throws an InvalidCastException, when calling the endpoint described above.
await _reviewsClient.Api
.Ratings
.GetAsync(x => x.QueryParameters.BookIds = new long?[] { 1, 2, 3, 4 }, cancellationToken);The exception message says: "Unable to cast object of type 'System.Int64' to type 'System.String'."
Workaround
When replacing the long[] with a string[] on the backend and client, it works.
As a workaround I convert the long[] to a string[] manually.
On the backend I parse the strings.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
WIPenhancementNew feature or requestNew feature or requestgeneratorIssues or improvements relater to generation capabilities.Issues or improvements relater to generation capabilities.
Type
Projects
Status
Done ✔️