Skip to content

Commit 4c22bf3

Browse files
hannes-ucscachave11-ucsc
authored andcommitted
[2/2] Spec for filters argument should be driven by field types (#2254)
1 parent bcc78d6 commit 4c22bf3

File tree

13 files changed

+7363
-17887
lines changed

13 files changed

+7363
-17887
lines changed

lambdas/service/app.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,55 +1089,49 @@ def list_catalogs():
10891089
)
10901090

10911091

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+
11111107

1108+
types = app.repository_controller.field_types(app.catalog)
11121109

11131110
filters_param_spec = params.query(
11141111
'filters',
11151112
schema.optional(application_json(schema.object_type(
11161113
default='{}',
11171114
example={'cellCount': {'within': [[10000, 1000000000]]}},
11181115
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
11241118
}
11251119
))),
11261120
description=format_description('''
11271121
Criteria to filter entities from the search results.
11281122
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.
11351129
1136-
For the "is" operator, multiple values are combined using "or"
1130+
For the "is" relation, multiple values are combined using "or"
11371131
logic. For example, `{"fileFormat": {"is": ["fastq", "fastq.gz"]}}`
11381132
selects entities where the file format is either "fastq" or
11391133
"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
11411135
upper and lower bounds, and multiple pairs are combined using "and"
11421136
logic. For example, `{"donorCount": {"within": [[1,5], [5,10]]}}`
11431137
selects entities whose donor organism count falls within both

lambdas/service/openapi.json

Lines changed: 6981 additions & 17709 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)