Skip to content
Open

Dp #200

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 75 additions & 11 deletions example/from_json/movie_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,100 @@ main() {
'additionalProperties': false,
'required': ['movies'],
'properties': {
'movies': {r'$ref': '#/definitions/movie_map'}
'movies': {
'\$ref': '#/definitions/movie_map',
},
},
'definitions': {
'movie': {
'additionalProperties': false,
'required': ['title', 'year_made', 'rating'],
'properties': {
'title': {'type': 'string'},
'year_made': {'type': 'integer'},
'rating': {'type': 'integer'}
}
'year_made': {
'type': 'integer',
'minimum': 2020,
'maximum': 2024,
'title': 'Product',
'customMessage': {
'general_message': {
'widget_id': 'year_made',
'recordset_id': 'movies',
},
'numberValidation_minimum': {
'message':
"Kindly change the value to be greater than 2020 ANY MESSAGE YOU WANT",
},
'numberValidation_maximum': {
'message':
"Kindly change the value to be less than 2024 ANY MESSAGE YOU WANT",
},
'numberValidation_exclusiveMaximum': {},
'numberValidation_exclusiveMinimum': {},
'numberValidation_multipleOf': {},
'typeValidation': {},
'constValidation': {},
'enumValidation': {},
'stringValidation_maxLength': {},
'stringValidation_minLength': {},
'stringValidation_pattern': {},
'itemsValidation_additionalItems': {},
'itemsValidation_maxItems': {},
'itemsValidation_minItems': {},
'itemsValidation_uniqueItems': {},
'itemsValidation_minContains': {},
'itemsValidation_maxContains': {},
'itemsValidation_contains': {},
'validateUnevaluatedItems': {},
'validateAllOf': {},
'validateAnyOf': {},
'validateNot': {},
'objectPropertyValidation': {},
'propertyDependenciesValidation': {},
'schemaDependenciesValidation': {},
'objectValidation_minProperties': {},
'objectValidation_maxProperties': {},
'objectValidation_requiredProperties_root': {},
'objectValidation_requiredProperties_property': {},
'schemaBool_false': {},
'ifThenElseValidation_then': {},
'ifThenElseValidation_else': {},
},
},
'rating': {'type': 'integer'},
},
},
'movie_map': {
'type': 'object',
'additionalProperties': {r'$ref': '#/definitions/movie'},
'default': {}
}
}
'additionalProperties': {
'\$ref': '#/definitions/movie',
},
'default': {},
},
},
};

final movies = {
'movies': {
'the mission': {'title': 'The Mission', 'year_made': 1986, 'rating': 5},
'troll 2': {'title': 'Troll 2', 'year_made': 1990, 'rating': 2}
'the mission': {
'title': 'The Mission',
'year_made': 2010,
'rating': 5,
},
'troll 2': {
'title': 'Troll 2',
'year_made': 2025,
'rating': 2,
},
}
};

JsonSchema.createAsync(movieSchema).then((schema) {
final validator = Validator(schema);
final results = validator.validate(movies, reportMultipleErrors: true);
print('$movies:\n$results');
for (var element in results.errors) {
print(element.message);
print(element.customMessage ?? 'no custom message');
}
});
}
Loading