1010logger = logging .getLogger (__name__ )
1111
1212
13- @app .ns_schema .route ('/ ' )
13+ @app .ns_schema .route ('' )
1414class 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>' )
3959class SchemaController (Resource ):
4060 """GET/UPDATE/DELETE validation schemas"""
4161
0 commit comments