mirror of
https://github.com/langgenius/dify.git
synced 2025-12-20 14:42:37 +00:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
27 lines
814 B
Python
27 lines
814 B
Python
"""Helpers for registering Pydantic models with Flask-RESTX namespaces."""
|
|
|
|
from flask_restx import Namespace
|
|
from pydantic import BaseModel
|
|
|
|
DEFAULT_REF_TEMPLATE_SWAGGER_2_0 = "#/definitions/{model}"
|
|
|
|
|
|
def register_schema_model(namespace: Namespace, model: type[BaseModel]) -> None:
|
|
"""Register a single BaseModel with a namespace for Swagger documentation."""
|
|
|
|
namespace.schema_model(model.__name__, model.model_json_schema(ref_template=DEFAULT_REF_TEMPLATE_SWAGGER_2_0))
|
|
|
|
|
|
def register_schema_models(namespace: Namespace, *models: type[BaseModel]) -> None:
|
|
"""Register multiple BaseModels with a namespace."""
|
|
|
|
for model in models:
|
|
register_schema_model(namespace, model)
|
|
|
|
|
|
__all__ = [
|
|
"DEFAULT_REF_TEMPLATE_SWAGGER_2_0",
|
|
"register_schema_model",
|
|
"register_schema_models",
|
|
]
|