Add support for deepObject style query parameters
Is your feature request related to a problem? Please describe the problem.
We are currently using Swashbuckle and NSwag to generate the OpenAPI spec and .NET clients (respectively) for a .NET Web API. Several endpoints in the API use query parameters that expect deepObject style serialization.
We’re now looking to generate a TypeScript client and are very interested in using Kiota. However, the lack of deepObject support is currently blocking us from adopting it, as these parameters are critical to our API.
Client library/SDK language
TypeScript, C#
Describe the solution you'd like
The OpenAPI Specification defines deepObject as a valid Parameter Object style for serializing complex objects in query parameters.
Given an OpenAPI parameter like:
{
"name": "color",
"in": "query",
"style": "deepObject",
"explode": true,
"schema": {
"type": "object",
"additionalProperties": {
"type": "string",
"nullable": true
},
"example": {
"red": "100",
"green": "200",
"blue": "150"
}
}
}
We would expect Kiota to generate a TypeScript interface similar to:
export interface ExampleRequestBuilderGetQueryParameters {
color?: Record<string, string | null>;
}
export const ExampleRequestBuilderUriTemplate = "{+baseurl}/example{?color*}";
Which we would use like:
await client.example.get({
queryParameters: {
color: {
red: "100",
green: "200",
blue: "150"
}
}
});
This should result in the query string (shown un-encoded):
https://somesite.com/example?color[red]=100&color[green]=200&color[blue]=150
Currently, Kiota treats color as a string. If an object is passed, it is either excluded from the request or causes a type error in TypeScript with type-checking enabled.
Additional context
Although this example uses TypeScript, we’ve observed the same issue when generating C# clients. We could not find any reference to deepObject in Kiota’s documentation or codebase, even though it’s a defined style in the OpenAPI spec.
Hi @bleish Thank you for using kiota and for reaching out.
This is something we ignored on purpose in the early days of kiota because there's a lot of undefined behaviour when serializing objects as query parameters.
Even if we only take into consideration your "simple" case (do not support object or array properties on the root parameter type), the URI is built using RFC 6570 URI templates, and there does not seem to be a way to expand an object normalizing the properties like expected.
We could project the parameters as separate in the template like so {+baseurl}/example{?color[red],color[blue],color[green]} which would lead people to have to use it this way
await client.example.get({
queryParameters: {
color_red: "100",
color_green: "200",
color_blue: "150"
}
});
But that brings a double encoding issue (since square brackets are not part of the vachar set defined here ), and potentially a collision issue.
For those reasons, we originally decided to leave this out.
Let us know if you have any additional comments or questions.
Thanks for the quick response!
Let me clarify our situation a bit, and hopefully you can help us understand what options are available using Kiota to achieve our goal.
Our .NET Web API has some query parameters defined as Dictionary<string, string>, like this:
[HttpGet("fromDict")]
public Result GetFromDict([FromQuery] Dictionary<string, string> demoQuery)
{
// ...
}
These parameters are designed to allow an arbitrary number of key-value pairs, but only at a single level of depth:
var queryParam = new Dictionary<string, string>
{
["Key1"] = "Value1",
["Key2"] = "Value2",
// ...
};
When calling this endpoint, the only OpenAPI object query parameter styles that deserialize and bind correctly out of the box are form (with explode: true) and deepObject:
# Dictionary - form (explode)
GET {{HostAddress}}/demo/fromDict?key1=value1&key2=value2
# Dictionary - deepObject
GET {{HostAddress}}/demo/fromDict?demoQuery[key1]=value1&demoQuery[key2]=value2
With form, we lose the reference to the parameter name itself—it acts more like a wrapper for arbitrary query parameters. In contrast, deepObject is more explicit about what is being passed, which is why we chose it back in 2017–2018.
After re-testing query parameter serialization styles against the latest .NET 9 Web API, we’ve confirmed that .NET’s behavior is still the same. One option we may have overlooked previously is form with dot notation, which allows form (with explode: false) to work like this:
# Nested Dictionary - form
GET {{HostAddress}}/demo/fromNestedDict?demoQuery.key1.nestedKey1=value1
# Nested Dictionary - form (explode)
GET {{HostAddress}}/demo/fromNestedDict?key1.nestedKey1=value1&key2.nestedKey2=value2
This preserves the parameter name and allows nesting, though in our case, we don’t require deep nesting or complex object structures.
We originally used AutoRest to generate our clients, and it supported deepObject as defined in the spec. When AutoRest moved on and changed direction, we evaluated other options. At the time, Kiota lacked a few features we needed, so we went with NSwag. NSwag doesn’t natively support deepObject, so we had to modify the generated code to manually reformat the parameters to match our API. It wasn’t ideal, but it worked.
That was two years ago. We’re now looking to generate a TypeScript client and decided to revisit Kiota. It’s matured a lot, but this is still a feature that blocks us. Unfortunately, changing our API isn’t really feasible at this time. Updating our OpenAPI spec to use form with dot notation might be an option, but so far we haven’t been able to get any of the .NET-compatible styles working properly with Kiota.
We understand there are complexities in implementing spec-compliant behavior across languages and ecosystems, especially given RFC. But since Kiota is an OpenAPI client generator, we had hoped it would support the spec as written. While the long-running issue about deepObject support is still open, our use case doesn’t require anything beyond what’s already defined—just a flat dictionary-like structure, no nested objects or arrays. That issue does reference RFC 3986, which defines [ and ] as reserved characters, but we recognize that how they’re handled will vary by language.
We also realize we may not see the full scope of the challenges involved in implementing this. Still, if it’s feasible to support deepObject as it currently exists in the OAI spec, that would be the ideal outcome for us. Alternatively, if there’s another way to support our use case using Kiota, we’d love to hear it. We’re really hoping to adopt Kiota moving forward, so any guidance would be greatly appreciated.
For reference, here's a quick demo API that I threw together to test the different object query parameter styles against a .NET web api controller: https://github.com/bleish/DemoApi
Thank you for the additional information.
Unfortunately, this is not a "simple" problem to solve. I'm guessing the reason why you're using a dictionary is because you don't know the keys in advance?
To properly "implement" this, and guarantee interoperability we'd need to:
- amend OpenAPI to have some kind of field which tells us "how" the object representation should happen
- implement that "sub-feature" of the specification in OpenAPI.net
- implement the generation and serialization work in Kiota
You're probably looking at a timeline in years which... does not solve your problem.
I'd suggest that instead you look at the QUERY method, or using POST, with a request body.
Let us know if you have any additional comments or questions.
Thanks for the response.
As I mentioned earlier, altering the API isn’t currently an option for us. To use Kiota, we would need a way to serialize single-depth dictionary query parameters as accepted by .NET Web APIs: either using deepObject or form with explode: true. I’m not sure whether there’s a viable middleware approach to manually serialize these query parameters, but ideally, this would be supported directly by Kiota. Is there an alternative approach using Kiota that could work in this scenario?
Regarding the complexity of solving this, I’m still unclear on why deepObject, as currently defined by OpenAPI, can’t be implemented, even in its simplest form. Is it possible to support a limited implementation, perhaps with caveats for unsupported formats, or by handling only basic cases like Record<string, string>? Since deepObject has been part of the OpenAPI spec for several years and was previously implemented by AutoRest for client generation, could that serve as a reference or blueprint for supporting this in Kiota?
Thank you for the additional information.
Here are the steps that would need figuring out:
- projecting the types
- projecting a valid URI template
- being able to serialize the instance into a payload for the URI template library
Map/associative array scenario
If we restrain the "scenario" to maps/associative arrays/single level objects, RFC6570 does provide support for it.
The expansion process for exploded variables is dependent on both the operator being used and whether the composite value is to be treated as a list of values or as an associative array of (name, value) pairs.
Taking your color example
export interface ExampleRequestBuilderGetQueryParameters {
color?: Record<string, string | null>;
}
export const ExampleRequestBuilderUriTemplate = "{+baseurl}/example{?color*}";
await client.example.get({
queryParameters: {
color: { // here color is a Record<string, string>
red: "100",
green: "200",
blue: "150"
}
}
});
Would result in
https://somesite.com/example?red=100&green=200&blue=150
NOT in
https://somesite.com/example?color[red]=100&color[green]=200&color[blue]=150
Which I'm not sure solves your problem at all? But should be easy to implement assuming there are dictionary/map/record types across languages, and that we update the abstraction libraries first to handle such case.
deep objects
According to
Structures are processed as if they are an associative array with names corresponding to the fields in the structure definition and "." separators used to indicate name hierarchy in substructures.
This
{+baseurl}/example{?colorInfo*}
await client.example.get({
queryParameters: {
colorInfo: { // color info is a Record<string, unknown>
color: {
red: "100",
green: "200",
blue: "150"
}
}
}
});
Could result in
https://somesite.com/example?color.red=100&color.green=200&color.blue=150
This one is more complex since: not all languages can express an equivalent to unknown, we'd need to implement some recursive logic in abstractions that handle deeper levels of properties and "normalizes" them for this to work properly.
This would also require updating the URI template implementation we use to recursively parse that object structure. https://github.com/std-uritemplate/std-uritemplate-csharp/blob/8534aeead47cc746e92e246fea0a5fe3e7c832b3/Std.UriTemplate.cs#L563 across all languages.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.