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
|
2024-02-15 01:01:35 +03:00
|
|
|
enum: Optional[list] = None
|
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
|
2024-02-15 01:01:35 +03:00
|
|
|
description: Optional[str] = None
|
2023-11-08 18:07:21 +03:00
|
|
|
|
|
|
|
|
2023-11-09 18:58:51 +03:00
|
|
|
class ApiBrainAllowedMethods(str, Enum):
|
|
|
|
GET = "GET"
|
|
|
|
POST = "POST"
|
|
|
|
PUT = "PUT"
|
|
|
|
DELETE = "DELETE"
|
|
|
|
|
|
|
|
|
2023-12-06 10:40:18 +03:00
|
|
|
class ApiBrainDefinitionEntity(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]
|
2024-01-26 02:56:46 +03:00
|
|
|
raw: bool = False
|
|
|
|
jq_instructions: Optional[str] = None
|