typeToDart function

String typeToDart(
  1. String? type,
  2. Map<String, dynamic>? schema
)

Swagger type -> Dart type string; returns pair (dartType, importHint)

Implementation

String typeToDart(String? type, Map<String, dynamic>? schema) {
  if (type == 'integer' || type == 'number') return 'num';
  if (type == 'boolean') return 'bool';
  if (type == 'string') return 'String';
  if (type == 'array') {
    final items = schema?['items'];
    if (items is Map<String, dynamic>) {
      if (items[r'$ref'] is String) {
        return 'List<${refToName(items[r"$ref"] as String)}>';
      } else if (items['type'] is String) {
        return 'List<${typeToDart(items['type'] as String, items)}>';
      }
    }
    return 'List<dynamic>';
  }
  if (type == 'object') {

    if (schema?['properties'] is Map) return 'Map<String, dynamic>';
    return 'Map<String, dynamic>';
  }
  return 'dynamic';
}