python-osw-validation 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_osw_validation/__init__.py +10 -3
- python_osw_validation/extracted_data_validator.py +2 -1
- python_osw_validation/helpers.py +16 -3
- python_osw_validation/schema/opensidewalks.lines.schema-0.3.json +2 -6
- python_osw_validation/schema/opensidewalks.points.schema-0.3.json +2 -8
- python_osw_validation/schema/opensidewalks.polygons.schema-0.3.json +2 -6
- python_osw_validation/schema/opensidewalks.schema-0.3.json +6509 -6134
- python_osw_validation/version.py +1 -1
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.4.dist-info}/METADATA +1 -1
- python_osw_validation-0.3.4.dist-info/RECORD +17 -0
- python_osw_validation-0.3.2.dist-info/RECORD +0 -17
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.4.dist-info}/WHEEL +0 -0
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.4.dist-info}/licenses/LICENSE +0 -0
- {python_osw_validation-0.3.2.dist-info → python_osw_validation-0.3.4.dist-info}/top_level.txt +0 -0
|
@@ -9,7 +9,12 @@ import jsonschema_rs
|
|
|
9
9
|
from .zipfile_handler import ZipFileHandler
|
|
10
10
|
from .extracted_data_validator import ExtractedDataValidator, OSW_DATASET_FILES
|
|
11
11
|
from .version import __version__
|
|
12
|
-
from .helpers import
|
|
12
|
+
from .helpers import (
|
|
13
|
+
_add_additional_properties_hint,
|
|
14
|
+
_feature_index_from_error,
|
|
15
|
+
_pretty_message,
|
|
16
|
+
_rank_for,
|
|
17
|
+
)
|
|
13
18
|
|
|
14
19
|
SCHEMA_PATH = os.path.join(os.path.dirname(__file__), 'schema')
|
|
15
20
|
DEFAULT_DATASET_SCHEMAS = {
|
|
@@ -211,9 +216,10 @@ class OSWValidation:
|
|
|
211
216
|
# Validate the folder structure
|
|
212
217
|
validator = ExtractedDataValidator(self.extracted_dir)
|
|
213
218
|
if not validator.is_valid():
|
|
219
|
+
upload_name = os.path.basename(self.zipfile_path) if self.zipfile_path else self.extracted_dir
|
|
214
220
|
self.log_errors(
|
|
215
221
|
message=validator.error,
|
|
216
|
-
filename=
|
|
222
|
+
filename=upload_name,
|
|
217
223
|
feature_index=None
|
|
218
224
|
)
|
|
219
225
|
return ValidationResult(False, self.errors, self.issues)
|
|
@@ -526,7 +532,8 @@ class OSWValidation:
|
|
|
526
532
|
for err in validator.iter_errors(geojson_data):
|
|
527
533
|
# legacy list (for backward compatibility)
|
|
528
534
|
if legacy_count < max_errors:
|
|
529
|
-
|
|
535
|
+
raw_msg = _add_additional_properties_hint(getattr(err, "message", "") or "")
|
|
536
|
+
self.errors.append(f"Validation error: {raw_msg}")
|
|
530
537
|
legacy_count += 1
|
|
531
538
|
else:
|
|
532
539
|
# We've reached the legacy cap; stop work to match original performance
|
|
@@ -104,8 +104,9 @@ class ExtractedDataValidator:
|
|
|
104
104
|
)
|
|
105
105
|
if unsupported_files:
|
|
106
106
|
allowed_fmt = ", ".join(allowed_keys)
|
|
107
|
+
allowed_names = f"*.{{{allowed_fmt}}}.geojson"
|
|
107
108
|
self.error = (f"Unsupported .geojson files present: {', '.join(unsupported_files)}. "
|
|
108
|
-
f"Allowed file
|
|
109
|
+
f"Allowed file names are {allowed_names}")
|
|
109
110
|
return False
|
|
110
111
|
|
|
111
112
|
required_files = [key for key, value in OSW_DATASET_FILES.items() if value['required']]
|
python_osw_validation/helpers.py
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
import re
|
|
3
3
|
|
|
4
|
+
_ADDITIONAL_PROPERTIES_RE = re.compile(
|
|
5
|
+
r"Additional properties are not allowed \('(?P<tag>[^']+)' was unexpected\)"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _add_additional_properties_hint(msg: str) -> str:
|
|
10
|
+
match = _ADDITIONAL_PROPERTIES_RE.search(msg)
|
|
11
|
+
if not match:
|
|
12
|
+
return msg
|
|
13
|
+
tag = match.group("tag")
|
|
14
|
+
return f"{msg}. If you want to carry this tag, change it to ext:{tag}"
|
|
15
|
+
|
|
4
16
|
def _feature_index_from_error(err) -> Optional[int]:
|
|
5
17
|
"""
|
|
6
18
|
Return the index after 'features' in the instance path, else None.
|
|
@@ -46,7 +58,7 @@ def _pretty_message(err, schema) -> str:
|
|
|
46
58
|
kind = _err_kind(err)
|
|
47
59
|
|
|
48
60
|
if kind == "Enum":
|
|
49
|
-
return _clean_enum_message(err)
|
|
61
|
+
return _add_additional_properties_hint(_clean_enum_message(err))
|
|
50
62
|
|
|
51
63
|
if kind == "AnyOf":
|
|
52
64
|
# Follow schema_path to the anyOf node; union of 'required' keys in branches.
|
|
@@ -73,12 +85,13 @@ def _pretty_message(err, schema) -> str:
|
|
|
73
85
|
|
|
74
86
|
if required:
|
|
75
87
|
props = ", ".join(sorted(required))
|
|
76
|
-
return f"must include one of: {props}"
|
|
88
|
+
return _add_additional_properties_hint(f"must include one of: {props}")
|
|
77
89
|
except Exception:
|
|
78
90
|
pass
|
|
79
91
|
|
|
80
92
|
# Default: first line from library message
|
|
81
|
-
|
|
93
|
+
default_msg = (getattr(err, "message", "") or "").split("\n")[0]
|
|
94
|
+
return _add_additional_properties_hint(default_msg)
|
|
82
95
|
|
|
83
96
|
|
|
84
97
|
def _rank_for(err) -> tuple:
|
|
@@ -185,9 +185,7 @@
|
|
|
185
185
|
"enum": [
|
|
186
186
|
"deciduous",
|
|
187
187
|
"evergreen",
|
|
188
|
-
"mixed"
|
|
189
|
-
"semi_deciduous",
|
|
190
|
-
"semi_evergreen"
|
|
188
|
+
"mixed"
|
|
191
189
|
],
|
|
192
190
|
"type": "string"
|
|
193
191
|
},
|
|
@@ -282,9 +280,7 @@
|
|
|
282
280
|
"enum": [
|
|
283
281
|
"deciduous",
|
|
284
282
|
"evergreen",
|
|
285
|
-
"mixed"
|
|
286
|
-
"semi_deciduous",
|
|
287
|
-
"semi_evergreen"
|
|
283
|
+
"mixed"
|
|
288
284
|
],
|
|
289
285
|
"type": "string"
|
|
290
286
|
},
|
|
@@ -204,10 +204,7 @@
|
|
|
204
204
|
"description": "A field that describes the phenology of leaves, for instance evergreen or deciduous.",
|
|
205
205
|
"enum": [
|
|
206
206
|
"deciduous",
|
|
207
|
-
"evergreen"
|
|
208
|
-
"mixed",
|
|
209
|
-
"semi_deciduous",
|
|
210
|
-
"semi_evergreen"
|
|
207
|
+
"evergreen"
|
|
211
208
|
],
|
|
212
209
|
"type": "string"
|
|
213
210
|
},
|
|
@@ -409,10 +406,7 @@
|
|
|
409
406
|
"description": "A field that describes the phenology of leaves, for instance evergreen or deciduous.",
|
|
410
407
|
"enum": [
|
|
411
408
|
"deciduous",
|
|
412
|
-
"evergreen"
|
|
413
|
-
"mixed",
|
|
414
|
-
"semi_deciduous",
|
|
415
|
-
"semi_evergreen"
|
|
409
|
+
"evergreen"
|
|
416
410
|
],
|
|
417
411
|
"type": "string"
|
|
418
412
|
},
|
|
@@ -289,9 +289,7 @@
|
|
|
289
289
|
"enum": [
|
|
290
290
|
"deciduous",
|
|
291
291
|
"evergreen",
|
|
292
|
-
"mixed"
|
|
293
|
-
"semi_deciduous",
|
|
294
|
-
"semi_evergreen"
|
|
292
|
+
"mixed"
|
|
295
293
|
],
|
|
296
294
|
"type": "string"
|
|
297
295
|
},
|
|
@@ -481,9 +479,7 @@
|
|
|
481
479
|
"enum": [
|
|
482
480
|
"deciduous",
|
|
483
481
|
"evergreen",
|
|
484
|
-
"mixed"
|
|
485
|
-
"semi_deciduous",
|
|
486
|
-
"semi_evergreen"
|
|
482
|
+
"mixed"
|
|
487
483
|
],
|
|
488
484
|
"type": "string"
|
|
489
485
|
},
|