events updated
This commit is contained in:
@@ -18,6 +18,44 @@ class EndpointValidationResponse(BaseModel):
|
||||
validation: dict
|
||||
|
||||
|
||||
class ValidationParser:
|
||||
|
||||
def __init__(self, active_validation):
|
||||
self.annotations = (
|
||||
active_validation.__annotations__.items() if active_validation else None
|
||||
)
|
||||
self.schema = {}
|
||||
self.parse()
|
||||
|
||||
def parse(self):
|
||||
for key, value in self.annotations or {}:
|
||||
field_type, required = "string", False
|
||||
if str(value) == "<class 'str'>" or str(value) == "typing.Optional[str]":
|
||||
field_type = "string"
|
||||
required = not str(value) == "typing.Optional[str]"
|
||||
elif str(value) == "<class 'int'>" or str(value) == "typing.Optional[int]":
|
||||
field_type = "integer"
|
||||
required = not str(value) == "typing.Optional[int]"
|
||||
elif (
|
||||
str(value) == "<class 'bool'>" or str(value) == "typing.Optional[bool]"
|
||||
):
|
||||
field_type = "boolean"
|
||||
required = not str(value) == "typing.Optional[bool]"
|
||||
elif (
|
||||
str(value) == "<class 'float'>"
|
||||
or str(value) == "typing.Optional[float]"
|
||||
):
|
||||
field_type = "float"
|
||||
required = not str(value) == "typing.Optional[bool]"
|
||||
elif (
|
||||
str(value) == "<class 'datetime.datetime'>"
|
||||
or str(value) == "typing.Optional[datetime.datetime]"
|
||||
):
|
||||
field_type = "datetime"
|
||||
required = not str(value) == "typing.Optional[datetime.datetime]"
|
||||
self.schema[key] = {"type": field_type, "required": required}
|
||||
|
||||
|
||||
def retrieve_validation_from_class(selected_event, events):
|
||||
event_function_class = getattr(selected_event, "function_class", None)
|
||||
event_function_code = getattr(selected_event, "function_code", None)
|
||||
@@ -77,9 +115,9 @@ def user_list(request: Request, validation: EndpointValidation):
|
||||
headers = getattr(
|
||||
active_validation, str(valid_token.lang).lower(), active_validation.tr
|
||||
)
|
||||
print("headers", headers)
|
||||
validation_parse = ValidationParser(active_validation=active_validation)
|
||||
return EndpointValidationResponse(
|
||||
language=valid_token.lang,
|
||||
headers=headers,
|
||||
validation=active_validation.model_json_schema(),
|
||||
validation=validation_parse.schema,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user