Closed Rudomitori closed 1 year ago
Should be fixed in 15.7.10
Thanks for the fix!
I've tested it and found out that now for the same given command and swagger the following code is generated:
tags && Object.keys(tags).forEach(key => { url_ += `Tags[${key}]=` + encodeURIComponent("" + tags[key]) + "&"; });
I see here 2 issues:
Tags
= {"complex=key":"value"}
then ASP.NET Core cannot correctly parse the query params.This is example of a swagger with a specified serialization style:
{
"openapi": "3.0.0",
"info": {
"title": "Bug reproduction",
"description": "Bug reproduction",
"version": "1"
},
"paths": {
"/api/v1/Answers": {
"get": {
"tags": [
"Answers"
],
"operationId": "Answers_GetAnswers",
"parameters": [
{
"name": "Tags",
"in": "query",
"style": "deepObject",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
}
}
}
yep, I misunderstood the spec, thanks! gonna fix soon
Should be fixed in 15.18.2
Alos I'll appreciate if you implement support for "deepObject" parameter serialization style.
That would definitely be good (better spec support is always good), but let me ask you a question. How do you plan to use it? I mean, currently you won't be able to correctly consume this deepObject
by ASP.NET Core Controller, right?
deepObject
serialization style is required when I try write endpoint like this:
[HttpGet]
public async Task<PagedResult<AnswerDto>> GetAnswers([FromQuery] AnswerFilters filters) {
// Do something
};
public class AnswerFilters {
public DateTime? Since { get; set; }
public DateTime? Until { get; set; }
public Dictionary<string, string>? Tags { get; set; }
}
Here Tags
cannot be bound if the query parameter isn't serialized with deepObject
style.
yep, that makes sense. I've created another issue for handling this scenario, I suppose we can consider this issue closed, right?
Yes. Thanks for library improvements!
It will be very handy to support complex parameters in some cases. E.g. if you have ASP.NET Core application with an endpoint that receives
Dictionary<string, string>
from query parameters. Although react-query-swagger has support for JSON-serialized parameters and it can be used for complex parameters but ASP.NET Core doesn't support it out of the box.Now if you try to generate client with the following command and swagger.json:
You get the following TypeScript code in
api-client/AnswersQuery.ts
andapi-client/AnswersClient.ts
:Here's the problem with
encodeURIComponent("" + tags)
becauseencodeURIComponent("" + {"key": "value"})
=>encodeURIComponent("[object Object]")
I think, according to the OpenAPI docs, there should be the following code here:
Alos I'll appreciate if you implement support for "deepObject" parameter serialization style.