microsoft/kiota

How to pass a free-format query string?

Ouverte

#3 800 ouverte le 26 nov. 2023

 (16 commentaires) (2 réactions) (0 personne assignée)C# (326 forks)auto 404
enhancementgeneratorhelp wanted

Métriques du dépôt

Stars
 (3 783 étoiles)
Métriques de merge PR
 (Merge moyen 3j 22h) (79 PRs mergées en 30 j)

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.

Guide contributeur