Reputation: 23
I try to check my JSON fields and their types. So, I use voluptuous and its methods.
An example is here.
check = Schema({
Required('Id'): All(str, Length(min=1)),
Required('CalculationId'): All(str, Length(min=1)),
Required('Routes'): All([
{Required('Id'): All(str, Length(min=1)),
Required('Origin'): {
Required('Longitude'): float,
Required('Latitude'): float},
Required('Destination'): {
Required('Longitude'): float,
Required('Latitude'): float}}], Length(min=1)),
Required('CreateDate'): str,
Required('CreateUserName'): str,
Required('CreateUserEmail'): str})
Can I make all fields required in a shorter and more convenient way? I would like to do not use this "Required" mark at the beginning of each line =)
Upvotes: 0
Views: 310
Reputation: 571
Can I make all fields required in a shorter and more convenient way? I would like to do not use this "Required" mark at the beginning of each line
Send required=True
param to Schema() after the json.
Example:
Genre = Schema(
{
'id': int,
'label': str,
},
required=True)
Upvotes: 1