convertParametersForCollectionFormat function

Iterable<QueryParam> convertParametersForCollectionFormat(
  1. ParameterToString deserializeDelegate,
  2. String? collectionFormat,
  3. String? name,
  4. dynamic value,
)

Implementation

Iterable<QueryParam> convertParametersForCollectionFormat(
    ParameterToString deserializeDelegate,
    String? collectionFormat,
    String? name,
    dynamic value) {
  var params = <QueryParam>[];

  // preconditions
  if (name == null || name.isEmpty || value == null) return params;

  if (value is! List) {
    params.add(QueryParam(name, deserializeDelegate(value)));
    return params;
  }

  List values = value;

  // get the collection format
  collectionFormat = (collectionFormat == null || collectionFormat.isEmpty)
      ? 'csv'
      : collectionFormat; // default: csv

  if (collectionFormat == 'multi') {
    return values.map((v) => QueryParam(name, deserializeDelegate(v)));
  }

  String delimiter = _delimiters[collectionFormat] ?? ',';

  params.add(QueryParam(
      name, values.map((v) => deserializeDelegate(v)).join(delimiter)));
  return params;
}