microsoft/kiota

How to pass a free-format query string?

Aberta

#3.800 aberto em 26 de nov. de 2023

 (16 comentários) (2 reações) (0 responsável)C# (326 forks)auto 404
enhancementgeneratorhelp wanted

Métricas do repositório

Stars
 (3.783 estrelas)
Métricas de merge de PR
 (Mesclagem média 3d 22h) (79 fundiu PRs em 30d)

Description

Due to the dynamic nature of JSON:API, which I'm trying to generate a C# client for, we need the query string parameters to be unconstrained. Is there a way to do that with Kiota?

The C# Web API produces the following OAS, which results in an IDictionary<string, string?> query method parameter using NSwag:

"parameters": [
  {
    "name": "query",
    "in": "query",
    "description": "...",
    "schema": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "nullable": true
      },
      "example": null
    }
  }
]

When passing the following value to the NSwag-generated method:

new Dictionary<string, string?>
{
    ["filter"] = "has(assignedTodoItems)",
    ["sort"] = "-lastName",
    ["page[size]"] = "5"
}

it gets translated to:

?filter=has(assignedTodoItems)&sort=-lastName&page[size]=5

Kiota generates the following instead:

[QueryParameter("query")]
public string? Query { get; set; }

It's unclear to me how to pass a query string to the generated code that produces: ?filter[node.parent.parent.parent...]=equals(name,'X') because it always emits ?query=....

The produced OAS is not set in stone, though it would be preferable if it works with both NSwag and Kiota.

Guia do colaborador