@@ -1089,55 +1089,49 @@ def list_catalogs():
1089
1089
)
1090
1090
1091
1091
1092
- def generate_operator_spec (field_type : FieldType ) -> Sequence [JSON ]:
1093
- array_schema = schema .array ({},
1094
- items = schema .array (field_type .api_type ,
1095
- minItems = 2 ,
1096
- maxItems = 2 ),
1097
- minItems = 1 ,
1098
- maxItems = 16 )
1099
- operator_spec = []
1100
- for operator in field_type .operators :
1101
- if operator == 'is' :
1102
- operator_spec .append (
1103
- schema .object (is_ = schema .array (field_type .api_type ))
1104
- )
1105
- else :
1106
- operator_spec .append (
1107
- schema .object_type (additionalProperties = False ,
1108
- properties = {operator : array_schema })
1109
- )
1110
- return operator_spec
1092
+ def _filter_schema (field_type : FieldType ) -> JSON :
1093
+ relations = field_type .supported_filter_relations
1094
+
1095
+ def filter_schema (relation : str ) -> JSON :
1096
+ return schema .object_type (
1097
+ properties = {relation : schema .array (field_type .api_filter_schema (relation ))},
1098
+ required = [relation ],
1099
+ additionalProperties = False
1100
+ )
1101
+
1102
+ if len (relations ) == 1 :
1103
+ return filter_schema (one (relations ))
1104
+ else :
1105
+ return {'oneOf' : list (map (filter_schema , relations ))}
1106
+
1111
1107
1108
+ types = app .repository_controller .field_types (app .catalog )
1112
1109
1113
1110
filters_param_spec = params .query (
1114
1111
'filters' ,
1115
1112
schema .optional (application_json (schema .object_type (
1116
1113
default = '{}' ,
1117
1114
example = {'cellCount' : {'within' : [[10000 , 1000000000 ]]}},
1118
1115
properties = {
1119
- field : {
1120
- 'oneOf' : generate_operator_spec (field_type )
1121
- }
1122
- for field , field_type
1123
- in app .repository_controller .field_types (app .catalog ).items ()
1116
+ field : _filter_schema (types [field ])
1117
+ for field in app .fields
1124
1118
}
1125
1119
))),
1126
1120
description = format_description ('''
1127
1121
Criteria to filter entities from the search results.
1128
1122
1129
- Each filter consists of a field name, a relational operator, and an
1130
- array of field values. The available operators are "is", "within ",
1131
- "contains", and "intersects". Multiple filters are combined using "and"
1132
- logic. An entity must match all filters to be included in the response.
1133
- How multiple field values within a single filter are combined depends
1134
- on the operator .
1123
+ Each filter consists of a field name, a relation ( relational operator),
1124
+ and an array of field values. The available relations are "is",
1125
+ "within", " contains", and "intersects". Multiple filters are combined
1126
+ using "and" logic. An entity must match all filters to be included in
1127
+ the response. How multiple field values within a single filter are
1128
+ combined depends on the relation .
1135
1129
1136
- For the "is" operator , multiple values are combined using "or"
1130
+ For the "is" relation , multiple values are combined using "or"
1137
1131
logic. For example, `{"fileFormat": {"is": ["fastq", "fastq.gz"]}}`
1138
1132
selects entities where the file format is either "fastq" or
1139
1133
"fastq.gz". For the "within", "intersects", and "contains"
1140
- operators , the field values must come in nested pairs specifying
1134
+ relations , the field values must come in nested pairs specifying
1141
1135
upper and lower bounds, and multiple pairs are combined using "and"
1142
1136
logic. For example, `{"donorCount": {"within": [[1,5], [5,10]]}}`
1143
1137
selects entities whose donor organism count falls within both
0 commit comments