Skip to content

Commit 06829f5

Browse files
authored
Merge pull request #36 from Geode-solutions/json_back
feat(validate_request): add json schema into function BREAKING CHANGE: Arguments changement(array to json schema)
2 parents 444ee71 + ebbe0e8 commit 06829f5

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"."
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ OpenGeode-Inspector
44
OpenGeode-Geosciences
55
OpenGeode-GeosciencesIO
66
Geode-Viewables
7+
jsonschema
8+
flask[async]
9+
werkzeug

requirements.txt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.9
2+
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile --resolver=backtracking requirements.in
5+
# pip-compile
66
#
7+
asgiref==3.7.2
8+
# via flask
9+
attrs==23.1.0
10+
# via
11+
# jsonschema
12+
# referencing
13+
blinker==1.7.0
14+
# via flask
15+
click==8.1.7
16+
# via flask
17+
flask[async]==3.0.0
18+
# via -r requirements.in
719
geode-common==29.0.1
820
# via geode-viewables
921
geode-viewables==2.1.3
1022
# via -r requirements.in
23+
itsdangerous==2.1.2
24+
# via flask
25+
jinja2==3.1.2
26+
# via flask
27+
jsonschema==4.19.2
28+
# via -r requirements.in
29+
jsonschema-specifications==2023.7.1
30+
# via jsonschema
31+
markupsafe==2.1.3
32+
# via
33+
# jinja2
34+
# werkzeug
1135
opengeode-core==14.9.3
1236
# via
1337
# -r requirements.in
@@ -34,3 +58,17 @@ opengeode-io==6.2.1
3458
# -r requirements.in
3559
# geode-viewables
3660
# opengeode-inspector
61+
referencing==0.30.2
62+
# via
63+
# jsonschema
64+
# jsonschema-specifications
65+
rpds-py==0.12.0
66+
# via
67+
# jsonschema
68+
# referencing
69+
typing-extensions==4.8.0
70+
# via asgiref
71+
werkzeug==3.0.1
72+
# via
73+
# -r requirements.in
74+
# flask

src/opengeodeweb_back/geode_functions.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import opengeode as og
1212
import pkg_resources
1313
import werkzeug
14+
from jsonschema import validate
15+
from jsonschema.exceptions import ValidationError
1416

1517
# Local application imports
1618
from .geode_objects import geode_objects_dict
@@ -234,15 +236,16 @@ def extension_from_filename(filename):
234236
return os.path.splitext(filename)[1][1:]
235237

236238

237-
def validate_request(request, variables_array):
239+
def validate_request(request, schema):
238240
json_data = request.get_json(force=True, silent=True)
239241

240242
if json_data is None:
241-
flask.abort(400, f"No json sent")
243+
json_data = {}
242244

243-
for variable in variables_array:
244-
if variable not in json_data.keys():
245-
flask.abort(400, f"No {variable} sent")
245+
try:
246+
validate(instance=json_data, schema=schema)
247+
except ValidationError as e:
248+
flask.abort(400, f"Validation error: {e.message}")
246249

247250

248251
def geographic_coordinate_systems(geode_object: str):

0 commit comments

Comments
 (0)