2023-11-09 18:58:51 +03:00
|
|
|
from enum import Enum
|
|
|
|
from typing import Optional
|
2023-11-07 16:03:50 +03:00
|
|
|
from uuid import UUID
|
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
from pydantic import BaseModel, Extra
|
2023-11-07 16:03:50 +03:00
|
|
|
|
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
class ApiBrainDefinitionSchemaProperty(BaseModel, extra=Extra.forbid):
|
2023-11-08 18:07:21 +03:00
|
|
|
type: str
|
|
|
|
description: str
|
2023-11-09 18:58:51 +03:00
|
|
|
enum: Optional[list]
|
2023-11-08 18:07:21 +03:00
|
|
|
name: str
|
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
def dict(self, **kwargs):
|
|
|
|
result = super().dict(**kwargs)
|
|
|
|
if "enum" in result and result["enum"] is None:
|
|
|
|
del result["enum"]
|
|
|
|
return result
|
2023-11-08 18:07:21 +03:00
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
|
|
|
|
class ApiBrainDefinitionSchema(BaseModel, extra=Extra.forbid):
|
|
|
|
properties: list[ApiBrainDefinitionSchemaProperty] = []
|
|
|
|
required: list[str] = []
|
2023-11-08 18:07:21 +03:00
|
|
|
|
|
|
|
|
2023-11-15 14:42:19 +03:00
|
|
|
class ApiBrainDefinitionSecret(BaseModel, extra=Extra.forbid):
|
2023-11-08 18:07:21 +03:00
|
|
|
name: str
|
|
|
|
type: str
|
|
|
|
|
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
class ApiBrainAllowedMethods(str, Enum):
|
|
|
|
GET = "GET"
|
|
|
|
POST = "POST"
|
|
|
|
PUT = "PUT"
|
|
|
|
DELETE = "DELETE"
|
|
|
|
|
|
|
|
|
|
|
|
class ApiBrainDefinition(BaseModel, extra=Extra.forbid):
|
2023-11-07 16:03:50 +03:00
|
|
|
brain_id: UUID
|
2023-11-09 18:58:51 +03:00
|
|
|
method: ApiBrainAllowedMethods
|
2023-11-07 16:03:50 +03:00
|
|
|
url: str
|
2023-11-08 18:07:21 +03:00
|
|
|
params: ApiBrainDefinitionSchema
|
|
|
|
search_params: ApiBrainDefinitionSchema
|
|
|
|
secrets: list[ApiBrainDefinitionSecret]
|