feat(api): schema restrictions for funnels, saved search and search

This commit is contained in:
Taha Yassine Kraiem 2022-02-01 18:38:26 +01:00
parent 2172a563a7
commit aef9d45c6c

View file

@ -470,7 +470,7 @@ class _SessionSearchEventRaw(__MixedSearchFilter):
value: Union[str, List[str]] = Field(...)
type: Union[EventType, PerformanceEventType] = Field(...)
operator: SearchEventOperator = Field(...)
source: Optional[Union[ErrorSource,List[Union[int, str]]]] = Field(default=ErrorSource.js_exception)
source: Optional[Union[ErrorSource, List[Union[int, str]]]] = Field(default=ErrorSource.js_exception)
sourceOperator: Optional[MathOperator] = Field(None)
@root_validator
@ -479,14 +479,16 @@ class _SessionSearchEventRaw(__MixedSearchFilter):
if values.get("type") == PerformanceEventType.fetch_failed:
return values
assert values.get("source") is not None, "source should not be null for PerformanceEventType"
assert values.get("sourceOperator") is not None \
, "sourceOperator should not be null for PerformanceEventType"
assert isinstance(values["source"], list) and len(values["source"]) > 0, \
"source should not be empty for PerformanceEventType"
assert values.get("sourceOperator") is not None, \
"sourceOperator should not be null for PerformanceEventType"
if values["type"] == PerformanceEventType.time_between_events:
assert len(values.get("value", [])) == 2, \
f"must provide 2 Events as value for {PerformanceEventType.time_between_events}"
assert isinstance(values["value"][0], _SessionSearchEventRaw) \
and isinstance(values["value"][1], _SessionSearchEventRaw) \
, f"event should be of type _SessionSearchEventRaw for {PerformanceEventType.time_between_events}"
and isinstance(values["value"][1], _SessionSearchEventRaw), \
f"event should be of type _SessionSearchEventRaw for {PerformanceEventType.time_between_events}"
else:
for c in values["source"]:
assert isinstance(c, int), f"source value should be of type int for {values.get('type')}"
@ -577,6 +579,12 @@ class FunnelSearchPayloadSchema(FlatSessionsSearchPayloadSchema):
range_value: Optional[str] = Field(None)
sort: Optional[str] = Field(None)
order: Optional[str] = Field(None)
events_order: Optional[SearchEventOrder] = Field(default=SearchEventOrder._then, const=True)
@root_validator(pre=True)
def enforce_default_values(cls, values):
values["eventsOrder"] = SearchEventOrder._then
return values
class Config:
alias_generator = attribute_to_camel_case
@ -686,4 +694,4 @@ class UpdateCustomMetricsSchema(CreateCustomMetricsSchema):
class SavedSearchSchema(FunnelSchema):
pass
filter: FlatSessionsSearchPayloadSchema = Field([])