microsoft/kiota

How to pass a free-format query string?

Offen

#3.800 geöffnet am 26.11.2023

 (16 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)C# (326 Forks)auto 404
enhancementgeneratorhelp wanted

Repository-Metriken

Stars
 (3.783 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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.

Contributor Guide