"""JSON schema and validators for request headers.""" from jsonschema import Draft3Validator HEADER_SCHEMA = { 'type': 'object', 'properties': { 'Correlation-Id': { 'type': 'string', 'required': True, 'blank': False } }, 'additionalProperties': True } RECORD_OBJECT_SCHEMA = { 'type': 'object', 'properties': { 'isrc': { 'type': 'string', 'required': True, 'blank': False, 'minLength': 12, 'maxLength': 12 }, 'tuid': { 'type': 'integer', 'required': True, 'blank': False }, 'upc': { 'type': 'string', 'required': True, 'blank': False, 'minLength': 1, 'maxLength': 20 }, 'partner_id': { 'type': 'integer', 'required': True, 'blank': False }, 'delivery_date': { 'type': 'string', 'format': 'datetime', 'required': True, 'blank': False } }, 'additionalProperties': False } RECORDS_SCHEMA = { 'type': 'object', 'properties': { 'items': { 'type': 'array', 'items': RECORD_OBJECT_SCHEMA, 'required': True } }, 'additionalProperties': False } DELIVERY_STORES_COUNT_SCHEMA = { 'type': 'object', 'properties': { 'upcs': { 'type': 'string', 'pattern': r'^(\d+,?)+$', 'required': True } }, 'additionalProperties': False } OA_USER_HEADER_SCHEMA = { 'type': 'object', 'properties': { 'Orchard-User-Id': { 'type': 'string', 'required': True, 'blank': False, 'pattern': r'^oa:\d+$', } }, 'additionalProperties': True } HEADER_VALIDATOR = Draft3Validator(schema=HEADER_SCHEMA) RECORDS_VALIDATOR = Draft3Validator(schema=RECORDS_SCHEMA) DELIVER_STORES_ARGS_VALIDATOR = Draft3Validator( schema=DELIVERY_STORES_COUNT_SCHEMA) OA_USER_HEADER_VALIDATOR = Draft3Validator( schema=OA_USER_HEADER_SCHEMA)