mapProperties method

Map<String, dynamic> mapProperties(
  1. Map json
)

Implementation

Map<String, dynamic> mapProperties(Map<dynamic, dynamic> json) {
  final _mapped = <String, dynamic>{};
  json.forEach((key, value) {
    if (value is List) {
      _mapped.putIfAbsent(
        key,
        () {
          final _element = value.isNotEmpty ? value.first : null;
          return {
            'type': 'array',
            'items': _element is Map<dynamic, dynamic>
                ? {
                    'type': 'object',
                    'properties': mapProperties(_element),
                  }
                : SwaggerUtils().toPrimativeType(_element),
          };
        },
      );
    } else if (value is Map<dynamic, dynamic>) {
      _mapped.putIfAbsent(
          key,
          () => {
                'type': 'object',
                'properties': mapProperties(value),
              });
    } else {
      _mapped.putIfAbsent(key, () => SwaggerUtils().toPrimativeType(value));
    }
  });
  return _mapped;
}