OpenAPITools / OpenAPITools/openapi-generator
[REQ][Dart] Support deepObject style query parameter serialization
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.
We need to use deepObject style query parameters serialization for a legacy API.
https://swagger.io/docs/specification/serialization/
deepObject – simple non-nested objects are serialized as paramName[prop1]=value1¶mName[prop2]=value2&.... The behavior for nested objects and arrays is undefined.
Example:
/v3/hashtags:
get:
tags:
- Hashtag
operationId: getHashtags
parameters:
- name: suggest_option
in: query
description: Suggest option
style: deepObject
explode: true
schema:
type: object
properties:
q:
type: string
description: Keyword for suggest
input_text:
type: string
description: Entire comment
But generated dart client results URI with strange query parameter serialization:
https://.../v3/hashtags?suggest_option=GetHashtagsSuggestOptionParameter%5Bq%3Da%2C+inputText%3Daaa%5D
openapi-generator-cli 6.1.0
openapi-generator generate -i ./openapi.yaml -g dart -o ./client
Describe the solution you'd like
If I modified api_helper.dart like this, it produced URI with query parameters as we expected:
https://.../v3/hashtags?suggest_option%5Bq%5D=a&suggest_option%5Binput_text%5D=aaa
Iterable<QueryParam> _queryParams(
String collectionFormat,
String name,
dynamic value,
) {
// Assertions to run in debug mode only.
assert(name.isNotEmpty, 'Parameter cannot be an empty string.');
final params = <QueryParam>[];
if (value is List) {
if (collectionFormat == 'multi') {
return value.map(
(dynamic v) => QueryParam(name, parameterToString(v)),
);
}
// Default collection format is 'csv'.
if (collectionFormat.isEmpty) {
collectionFormat = 'csv'; // ignore: parameter_assignments
}
final delimiter = _delimiters[collectionFormat] ?? ',';
params.add(QueryParam(
name,
value.map<dynamic>(parameterToString).join(delimiter),
));
} else if (value is num ||
value is String ||
value is bool ||
value is Enum) {
params.add(QueryParam(name, parameterToString(value)));
} else if (value != null) {
return value
.toJson()
.entries
.where((e) => e.value != null)
.map(
(e) => QueryParam('${name}[${e.key}]', parameterToString(e.value)),
)
.toList()
.cast<QueryParam>();
}
return params;
}
But I am new to both Open API generator and Dart, so I don't know if this is a good way...
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 the generated Dart client's api_helper.dart and reproduce the supplied OpenAPI schema and query URL. Compare the current deepObject serialization with the expected bracketed query parameters; done means generated Dart clients serialize simple deepObject properties as separate name[property] parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100