OpenAPITools / OpenAPITools/openapi-generator
[REQ] [csharp] [generichost] Support query parameters with style: deepObject and explode: true
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
The OpenAPI spec allows you to define parameters that can be rendered as color[R]=100&color[G]=200&color[B]=150.
This can be written in the OpenApi yaml file as follows:
parameters:
- name: color
in: query
style: deepObject
explode: true
schema:
title: ColorParameter
type: object
properties:
key:
type: string
value:
type: string
This is related to the issue in #19893
Describe the solution you'd like
To implement this, we need to modify several files.
Dealing with explode
First, we need to fix the signature of parameters with 'explode: true'.
The spec states that when this is true:
Parameter values of type array or object generate separate parameters for each value of the array or key-value pair of the map.
For a query parameter with name: color, this would look like
/foo&color=blue&color=black&color=orange
Since the parameter can be used 0 or more times, we need to change the parameter to a collection type (like List<T>).
This can be done by modifying Operation.Signature.mustache to add a {{#isExplode}} ... {{/isExplode}} section.
Next, we have to modify the following to add all the values in the List<T> parameter to NameValueCollection
https://github.com/OpenAPITools/openapi-generator/blob/008c1a42ef39100b38a86fc67344ea44d4f32a8f/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache#L408-L443
Support deepObject style
This along with explode:true allows us to specify query parameters as someParam[field1]=value1&someParam[field2]=value2&someParam[field3]=value3
Since the parameter defines a schema with type: object and properties, the generator generates a model to represent this type. For deepObject styles, it only makes sense to define two properties: the field or column and the value. I think what we can do here is then generate a model that has
// from parameter.name
public string Name {get; set;}
// from parameter.schema.properties[0]
public string Column {get; set;} // or Field
// from parameter.schema.properties[1]
public string Value {get; set;}
Then we can generate the query parameter as Name[Column]=Value
Building on top of the changes we made previously,
Describe alternatives you've considered
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with csharp/libraries/generichost/OperationSignature.mustache and the query-parameter handling in csharp/libraries/generichost/api.mustache around lines 408-443. Compare the current generated signatures and NameValueCollection handling with the OpenAPI deepObject and explode rules, and review related issue #19893. Done means generated Generic Host clients represent these parameters and produce the documented query forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100