Skip to content

Commit 48ee99a

Browse files
authored
Merge pull request #156 from Geode-solutions/fix/fast_json_schema
Fix/fast json schema
2 parents dca8bd2 + 4b95370 commit 48ee99a

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ geode-simplex
99
geode-explicit
1010
geode-implicit
1111
geode-common
12-
jsonschema
12+
fastjsonschema
1313
Flask[async]
1414
Flask-Cors
1515
werkzeug

requirements.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ blinker==1.9.0
1414
# via flask
1515
click==8.2.1
1616
# via flask
17+
fastjsonschema==2.21.1
18+
# via -r requirements.in
1719
flask[async]==3.1.1
1820
# via
1921
# -r requirements.in
@@ -60,10 +62,6 @@ itsdangerous==2.2.0
6062
# via flask
6163
jinja2==3.1.6
6264
# via flask
63-
jsonschema==4.24.0
64-
# via -r requirements.in
65-
jsonschema-specifications==2025.4.1
66-
# via jsonschema
6765
markupsafe==3.0.2
6866
# via
6967
# flask
@@ -120,4 +118,4 @@ werkzeug==3.1.3
120118
# via
121119
# -r requirements.in
122120
# flask
123-
# flask-cors
121+
# flask-cors

src/opengeodeweb_back/test_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def test_route_wrong_params(client, route, get_full_data):
1212
response = client.post(route, json=json)
1313
assert response.status_code == 400
1414
error_description = response.json["description"]
15-
assert error_description == f"Validation error: '{key}' is a required property"
15+
assert "data must contain" in error_description
16+
assert f"'{key}'" in error_description
1617

1718
json = get_full_data()
1819
json["dumb_key"] = "dumb_value"
1920
response = client.post(route, json=json)
2021
assert response.status_code == 400
2122
error_description = response.json["description"]
22-
assert (
23-
error_description
24-
== "Validation error: Additional properties are not allowed ('dumb_key' was unexpected)"
25-
)
23+
assert "data must not contain" in error_description
24+
assert "'dumb_key'" in error_description

src/opengeodeweb_back/utils_functions.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
# Third party imports
88
import flask
9-
from jsonschema import validate
10-
from jsonschema.exceptions import ValidationError
9+
import fastjsonschema
1110
import importlib.metadata as metadata
1211

1312
# Local application imports
@@ -82,9 +81,11 @@ def validate_request(request, schema):
8281
json_data = {}
8382

8483
try:
85-
validate(instance=json_data, schema=schema)
86-
except ValidationError as e:
87-
flask.abort(400, f"Validation error: {e.message}")
84+
validate = fastjsonschema.compile(schema)
85+
validate(json_data)
86+
except fastjsonschema.JsonSchemaException as e:
87+
error_msg = str(e)
88+
flask.abort(400, error_msg)
8889

8990

9091
def set_interval(func, sec, args=None):

0 commit comments

Comments
 (0)