1919from abc import ABCMeta , abstractmethod
2020from typing import ClassVar , Dict , Optional
2121
22+ from pydantic import BaseModel , Field
23+
2224from django .conf import settings
2325from django .core .exceptions import ImproperlyConfigured
2426from django .utils .module_loading import import_string
@@ -33,6 +35,22 @@ def get_provider_cls():
3335 return import_string (SVC_PROVIDER_CLS )
3436
3537
38+ def get_plan_schema_cls ():
39+ # 尝试从设置中获取类路径
40+ plan_schema_cls = getattr (settings , 'PAAS_SERVICE_PLAN_SCHEMA_CLS' , None )
41+
42+ # 若存在有效类路径则导入,否则返回默认类
43+ return import_string (plan_schema_cls ) if plan_schema_cls else EmptyPlanSchema
44+
45+
46+ def get_plan_schema () -> dict :
47+ return get_plan_schema_cls ().schema ()
48+
49+
50+ class EmptyPlanSchema (BaseModel ):
51+ ...
52+
53+
3654class BaseVendorException (Exception ):
3755 """Base class for vendor exception"""
3856
@@ -80,3 +98,12 @@ def delete(self, instanceData: InstanceData):
8098
8199 def patch (self , instanceData : InstanceData , params : Dict ) -> InstanceData :
82100 raise NotImplementedError
101+
102+
103+ # Plan Schema
104+ class BasePlanSchema (BaseModel ):
105+ ...
106+
107+
108+ class DummySchema (BasePlanSchema ):
109+ foo : str = Field (..., description = "这是一个示例字段" )
0 commit comments