• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

juancastillo0 / json_form / 11788932365

12 Nov 2024 01:21AM UTC coverage: 80.651% (+6.3%) from 74.365%
11788932365

push

github

juancastillo0
Add more README docs

1659 of 2057 relevant lines covered (80.65%)

1.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.33
/lib/src/models/array_schema.dart
1
import 'package:json_form/src/models/models.dart';
2

3
class SchemaArray extends Schema {
4
  SchemaArray({
1✔
5
    required super.id,
6
    required super.defs,
7
    required super.oneOf,
8
    required Object? itemsBaseSchema,
9
    super.title,
10
    super.description,
11
    this.arrayProperties = const ArrayProperties(),
12
    super.requiredProperty,
13
    required super.nullable,
14
    super.parent,
15
    super.dependentsAddedBy,
16
  }) : super(type: JsonSchemaType.array) {
1✔
17
    this.itemsBaseSchema = itemsBaseSchema is Schema
2✔
18
        ? itemsBaseSchema.copyWith(id: kNoIdKey, parent: this)
×
19
        : Schema.fromJson(
1✔
20
            itemsBaseSchema! as Map<String, Object?>,
21
            parent: this,
22
          );
23
  }
24

25
  factory SchemaArray.fromJson(
1✔
26
    String id,
27
    Map<String, Object?> json, {
28
    Schema? parent,
29
  }) {
30
    final schemaArray = SchemaArray(
1✔
31
      id: id,
32
      oneOf: json['oneOf'] as List?,
1✔
33
      defs: ((json['\$defs'] ?? json['definitions']) as Map?)?.cast(),
2✔
34
      title: json['title'] as String?,
1✔
35
      description: json['description'] as String?,
1✔
36
      arrayProperties: ArrayProperties.fromJson(json),
1✔
37
      itemsBaseSchema: json['items'],
1✔
38
      parent: parent,
39
      nullable: JsonSchemaType.isNullable(json['type']),
2✔
40
    );
41
    schemaArray.dependentsAddedBy.addAll(parent?.dependentsAddedBy ?? const []);
3✔
42

43
    return schemaArray;
44
  }
45

46
  @override
×
47
  SchemaArray copyWith({
48
    required String id,
49
    Schema? parent,
50
    List<String>? dependentsAddedBy,
51
  }) {
52
    final newSchema = SchemaArray(
×
53
      id: id,
54
      defs: defs,
×
55
      title: title,
×
56
      description: description,
×
57
      arrayProperties: arrayProperties,
×
58
      itemsBaseSchema: itemsBaseSchema,
×
59
      requiredProperty: requiredProperty,
×
60
      nullable: nullable,
×
61
      parent: parent ?? this.parent,
×
62
      dependentsAddedBy: dependentsAddedBy ?? this.dependentsAddedBy,
×
63
      oneOf: oneOf,
×
64
    );
65
    newSchema.setUiSchema(uiSchema.toJson(), fromOptions: false);
×
66

67
    return newSchema;
68
  }
69

70
  // it allow us
71
  late final Schema itemsBaseSchema;
72

73
  final ArrayProperties arrayProperties;
74

75
  bool isArrayMultipleFile() {
1✔
76
    final s = itemsBaseSchema;
1✔
77
    return s is SchemaProperty && s.format == PropertyFormat.dataUrl;
3✔
78
  }
79

80
  SchemaProperty toSchemaPropertyMultipleFiles() {
×
81
    return SchemaProperty(
×
82
      id: id,
×
83
      title: title,
×
84
      type: JsonSchemaType.string,
85
      format: PropertyFormat.dataUrl,
86
      requiredProperty: requiredProperty,
×
87
      nullable: nullable,
×
88
      description: description,
×
89
      parent: parent,
×
90
      dependentsAddedBy: dependentsAddedBy,
×
91
      isMultipleFile: true,
92
      oneOf: oneOf,
×
93
    );
94
  }
95

96
  @override
1✔
97
  void setUiSchema(
98
    Map<String, Object?> data, {
99
    required bool fromOptions,
100
  }) {
101
    super.setUiSchema(data, fromOptions: fromOptions);
1✔
102
    final items = data['items'] as Map<String, Object?>?;
1✔
103
    if (items != null) {
104
      itemsBaseSchema.setUiSchema(items, fromOptions: false);
2✔
105
      uiSchema.children['items'] = itemsBaseSchema.uiSchema;
5✔
106
    }
107
  }
108
}
109

110
enum ArrayPropertiesError {
111
  minItems,
112
  maxItems,
113
  uniqueItems,
114
  // TODO: contains, prefixItems
115
}
116

117
class ArrayProperties {
118
  final int? minItems;
119
  final int? maxItems;
120
  final bool? uniqueItems;
121

122
  const ArrayProperties({
2✔
123
    this.minItems,
124
    this.maxItems,
125
    this.uniqueItems,
126
  });
127

128
  factory ArrayProperties.fromJson(Map<String, Object?> json) {
1✔
129
    return ArrayProperties(
1✔
130
      minItems: json['minItems'] as int?,
1✔
131
      maxItems: json['maxItems'] as int?,
1✔
132
      uniqueItems: json['uniqueItems'] as bool?,
1✔
133
    );
134
  }
135

136
  List<ArrayPropertiesError> errors(List<Object?> value) {
1✔
137
    final errors = <ArrayPropertiesError>[];
1✔
138
    if (minItems != null && value.length < minItems!)
4✔
139
      errors.add(ArrayPropertiesError.minItems);
1✔
140
    if (maxItems != null && value.length > maxItems!)
4✔
141
      errors.add(ArrayPropertiesError.maxItems);
×
142
    if (uniqueItems != null && value.toSet().length != value.length)
5✔
143
      errors.add(ArrayPropertiesError.uniqueItems);
1✔
144
    return errors;
145
  }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc