dify/api/core/plugin/entities/endpoint.py
EvanYao826 422ebf59ea refactor: clean unnecessary | None annotations in entities (#35557)
Remove unnecessary '| None' type annotations where the default value
already guarantees a non-None type. This is the second batch of
cleanups following PR #36824.

Patterns changed:
- 'bool | None = False' -> 'bool = False'
- 'bool | None = Field(default=False)' -> 'bool = Field(default=False)'
- 'int | None = Field(default=0)' -> 'int = Field(default=0)'
- 'float | None = Field(default=0.0)' -> 'float = Field(default=0.0)'
- 'str | None = ""' -> 'str = ""'
- 'str | None = Field(default="")' -> 'str = Field(default="")'
- 'list[...] | None = Field(default_factory=list)' -> 'list[...] = Field(default_factory=list)'
2026-06-18 15:23:08 +08:00

55 lines
1.3 KiB
Python

from datetime import datetime
from typing import Any
from pydantic import BaseModel, Field, model_validator
from configs import dify_config
from core.entities.provider_entities import ProviderConfig
from core.plugin.entities.base import BasePluginEntity
class EndpointDeclaration(BaseModel):
"""
declaration of an endpoint
"""
path: str
method: str
hidden: bool = Field(default=False)
class EndpointProviderDeclaration(BaseModel):
"""
declaration of an endpoint group
"""
settings: list[ProviderConfig] = Field(default_factory=list)
endpoints: list[EndpointDeclaration] = Field(default_factory=list[EndpointDeclaration])
class EndpointEntity(BasePluginEntity):
"""
entity of an endpoint
"""
settings: dict[str, Any]
tenant_id: str
plugin_id: str
expired_at: datetime
declaration: EndpointProviderDeclaration = Field(default_factory=EndpointProviderDeclaration)
class EndpointEntityWithInstance(EndpointEntity):
name: str
enabled: bool
url: str
hook_id: str
@model_validator(mode="before")
@classmethod
def render_url_template(cls, values):
if "url" not in values:
url_template = dify_config.ENDPOINT_URL_TEMPLATE
values["url"] = url_template.replace("{hook_id}", values["hook_id"])
return values