refactor: extract Pydantic schemas into schemas/ subpackages
Extract inline Pydantic models from 9 API routers into dedicated schema modules under schemas/: - schemas/tool/tool_type.py — ToolTypeCreate, ToolTypeUpdate, etc. - schemas/tool/tool_instance.py — CreateInstanceRequest, StartInstanceRequest - schemas/config/config_profile.py — ConfigProfileCreate, ConfigProfileUpdate, ConfigProfileResponse, DefaultProfilesUpdate, ValidateGitUrlRequest, etc. - schemas/system/health.py — DatabaseHealth, DiskHealth, HealthResponse, etc. - schemas/user/user.py — UserProfileResponse, UserProfileUpdate - schemas/user/user_config.py — UserConfigResponse, UserConfigUpdate - schemas/project/project.py — ProjectCreate, ProjectUpdate, etc. - schemas/project/ssh_key.py — SSHKeyCreate, SSHKeyResponse, etc. - schemas/project/git_repository.py — GitRepositoryCreate, etc. API routers now import from src.schemas.* instead of defining inline. Net change: -548 lines across 16 files. Quality gates: py_compile passed, ruff passed on all 18 files.
This commit is contained in:
@@ -1 +1,27 @@
|
||||
"""Config module."""
|
||||
"""Config schemas module."""
|
||||
|
||||
from src.schemas.config.config_profile import (
|
||||
ConfigProfileCreate,
|
||||
ConfigProfileIncludeUpdate,
|
||||
ConfigProfileResponse,
|
||||
ConfigProfileUpdate,
|
||||
DefaultProfilesUpdate,
|
||||
GitMountItem,
|
||||
GitMountMapping,
|
||||
MountItem,
|
||||
ValidateGitUrlRequest,
|
||||
ValidateGitUrlResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"ConfigProfileCreate",
|
||||
"ConfigProfileIncludeUpdate",
|
||||
"ConfigProfileResponse",
|
||||
"ConfigProfileUpdate",
|
||||
"DefaultProfilesUpdate",
|
||||
"GitMountItem",
|
||||
"GitMountMapping",
|
||||
"MountItem",
|
||||
"ValidateGitUrlRequest",
|
||||
"ValidateGitUrlResponse",
|
||||
]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Config profile request/response schemas."""
|
||||
|
||||
import uuid
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator, model_validator
|
||||
|
||||
@@ -13,8 +12,8 @@ def _validate_uuid(v: str | None) -> str | None:
|
||||
return v
|
||||
try:
|
||||
uuid.UUID(v)
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid UUID: {v}")
|
||||
except ValueError as exc:
|
||||
raise ValueError(f"Invalid UUID: {v}") from exc
|
||||
return v
|
||||
|
||||
|
||||
@@ -236,8 +235,8 @@ class ConfigProfileIncludeUpdate(BaseModel):
|
||||
for item in v:
|
||||
try:
|
||||
uuid.UUID(item)
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid UUID in includes: {item}")
|
||||
except ValueError as exc:
|
||||
raise ValueError(f"Invalid UUID in includes: {item}") from exc
|
||||
return v
|
||||
|
||||
|
||||
|
||||
@@ -1 +1,41 @@
|
||||
"""Project module."""
|
||||
"""Project schemas module."""
|
||||
|
||||
from src.schemas.project.git_repository import (
|
||||
GitRepositoryCreate,
|
||||
GitRepositoryResponse,
|
||||
UpdateSSHKeyRequest,
|
||||
URLParseRequest,
|
||||
URLParseResponse,
|
||||
)
|
||||
from src.schemas.project.project import (
|
||||
ProjectCreate,
|
||||
ProjectResponse,
|
||||
ProjectUpdate,
|
||||
SetDefaultSSHKeyRequest,
|
||||
)
|
||||
from src.schemas.project.ssh_key import (
|
||||
SSHKeyCreate,
|
||||
SSHKeyResponse,
|
||||
SignPayloadRequest,
|
||||
SignatureResponse,
|
||||
VerifySignatureRequest,
|
||||
VerifySignatureResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"GitRepositoryCreate",
|
||||
"GitRepositoryResponse",
|
||||
"ProjectCreate",
|
||||
"ProjectResponse",
|
||||
"ProjectUpdate",
|
||||
"SSHKeyCreate",
|
||||
"SSHKeyResponse",
|
||||
"SetDefaultSSHKeyRequest",
|
||||
"SignPayloadRequest",
|
||||
"SignatureResponse",
|
||||
"URLParseRequest",
|
||||
"URLParseResponse",
|
||||
"UpdateSSHKeyRequest",
|
||||
"VerifySignatureRequest",
|
||||
"VerifySignatureResponse",
|
||||
]
|
||||
|
||||
@@ -1 +1,17 @@
|
||||
"""System module."""
|
||||
"""System schemas module."""
|
||||
|
||||
from src.schemas.system.health import (
|
||||
DatabaseHealth,
|
||||
DatabaseHealthResponse,
|
||||
DiskHealth,
|
||||
HealthChecks,
|
||||
HealthResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"DatabaseHealth",
|
||||
"DatabaseHealthResponse",
|
||||
"DiskHealth",
|
||||
"HealthChecks",
|
||||
"HealthResponse",
|
||||
]
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
"""Tool module."""
|
||||
"""Tool schemas module."""
|
||||
|
||||
from src.schemas.tool.tool_instance import CreateInstanceRequest, StartInstanceRequest
|
||||
from src.schemas.tool.tool_type import (
|
||||
ToolTypeCreate,
|
||||
ToolTypeResponse,
|
||||
ToolTypeUpdate,
|
||||
ToolTypeValidateRequest,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"CreateInstanceRequest",
|
||||
"StartInstanceRequest",
|
||||
"ToolTypeCreate",
|
||||
"ToolTypeResponse",
|
||||
"ToolTypeUpdate",
|
||||
"ToolTypeValidateRequest",
|
||||
]
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel, field_validator, model_validator
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, field_validator, model_validator
|
||||
|
||||
from src.api.tool_types_validation import (
|
||||
check_port_exposed,
|
||||
@@ -196,3 +198,33 @@ class ToolTypeUpdate(BaseModel):
|
||||
if not v.strip().startswith("FROM"):
|
||||
raise ValueError("Dockerfile must start with a FROM instruction")
|
||||
return v
|
||||
|
||||
|
||||
class ToolTypeResponse(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: uuid.UUID
|
||||
name: str
|
||||
display_name: str
|
||||
description: str | None
|
||||
category: str
|
||||
interface_type: str
|
||||
requires_port: bool
|
||||
default_port: int
|
||||
definition_type: str
|
||||
manifest_id: uuid.UUID | None
|
||||
compose_template: str | None
|
||||
dockerfile_template: str | None
|
||||
build_context: dict | None
|
||||
readiness_probe: dict | None
|
||||
startup_command: str | None
|
||||
required_variables: list[str]
|
||||
created_by_id: uuid.UUID | None
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class ToolTypeValidateRequest(BaseModel):
|
||||
definition_type: str
|
||||
compose_template: str | None = None
|
||||
dockerfile_template: str | None = None
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
"""User module."""
|
||||
"""User schemas module."""
|
||||
|
||||
from src.schemas.user.user import UserProfileResponse, UserProfileUpdate
|
||||
from src.schemas.user.user_config import UserConfigResponse, UserConfigUpdate
|
||||
|
||||
__all__ = [
|
||||
"UserConfigResponse",
|
||||
"UserConfigUpdate",
|
||||
"UserProfileResponse",
|
||||
"UserProfileUpdate",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user