Skip to content

Commit 676a482

Browse files
committed
Support GET schema endpoint with filtering by id or by name parameters
1 parent 39506c6 commit 676a482

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

esdlvalidator/api/controller/schema.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,38 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13-
@app.ns_schema.route('/')
13+
@app.ns_schema.route('')
1414
class SchemaListController(Resource):
1515
"""Get a list of validation schemas and add new schemas"""
1616

17-
@app.api.doc(description="Get a summary of validation schemas in the database", responses={
18-
200: "Ok"})
17+
@app.api.doc(
18+
description="Get a summary of validation schemas in the database",
19+
params={
20+
"id": "Optional filter by one or more schema IDs (repeatable)",
21+
"name": "Optional filter by one or more schema names (repeatable)"
22+
},
23+
responses={200: "Ok"})
1924
@app.ns_schema.doc(description='Get a list of validation schemas')
2025
@app.api.marshal_with(models.schema_summary)
2126
def get(self):
22-
"""Return a summary of all schemas in the database"""
27+
"""Return a summary of schemas, optionally filtered by ID or name"""
2328

24-
return schemaService.get_all(), 200
29+
# Accept plural query params
30+
ids = request.args.getlist("id")
31+
names = request.args.getlist("name")
32+
33+
all_schemas = schemaService.get_all()
34+
35+
if not ids and not names:
36+
return all_schemas, 200
37+
38+
filtered = []
39+
40+
for schema in all_schemas:
41+
if schema["id"] in ids or schema["name"] in names:
42+
filtered.append(schema)
43+
44+
return filtered, 200
2545

2646
@app.ns_schema.doc(description="Post a new validation schema", responses={
2747
201: "Created",
@@ -35,7 +55,7 @@ def post(self):
3555
return {"location": "/schema/{0}".format(schema_id)}, 201
3656

3757

38-
@app.ns_schema.route('/<string:schema_id_or_name>/')
58+
@app.ns_schema.route('/<string:schema_id_or_name>')
3959
class SchemaController(Resource):
4060
"""GET/UPDATE/DELETE validation schemas"""
4161

esdlvalidator/api/controller/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
parser.add_argument("schemas", type=list, help="List of schema id's, comma separated", location="form", required=True)
1111

1212

13-
@app.ns_validation.route('/')
13+
@app.ns_validation.route('')
1414
class ValidationController(Resource):
1515
"""Validate an ESDL file"""
1616

esdlvalidator/api/controller/validationToMessages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AssetMessage(TypedDict):
2626
messages: list[ValidationResult]
2727

2828

29-
@app.ns_validation_to_msgs.route("/")
29+
@app.ns_validation_to_msgs.route("")
3030
class ValidationToMessagesController(Resource):
3131

3232
@app.ns_validation_to_msgs.doc(

0 commit comments

Comments
 (0)