You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can instead write a JSON Schema to validate the data. We'll need the jsonschema and rfc3987 packages, and we can then do:
fromjsonschemaimportFormatCheckerfromjsonschema.validatorsimportDraft4Validatorasvalidator# Initialize the schema once, in the item pipeline's `__init__` methodwithopen('path/to/schema.json') asf:
schema=json.load(f)
self.validator=validator(schema, format_checker=FormatChecker())
# Then, to validate:validator.validate(item)
The JSON Schema can use:
An enum for data_type
"format": "uri" for url
"pattern": "^[^/]$" for file_name (no path separators)
"minLength": 1 for required strings
"minimum": 1 for number
appropriate "type" for all
The text was updated successfully, but these errors were encountered:
Right now there's a simple
validate
method to check for required fields: https://github.com/open-contracting/kingfisher-collect/blob/master/kingfisher_scrapy/items.pyWe can instead write a JSON Schema to validate the data. We'll need the
jsonschema
andrfc3987
packages, and we can then do:The JSON Schema can use:
data_type
"format": "uri"
forurl
"pattern": "^[^/]$"
forfile_name
(no path separators)"minLength": 1
for required strings"minimum": 1
fornumber
"type"
for allThe text was updated successfully, but these errors were encountered: