mirror of
https://github.com/langgenius/dify.git
synced 2026-06-16 22:11:09 +08:00
feat(api): expose OpenApiErrorCode enum as standalone swagger definition
This commit is contained in:
parent
5b75aae20d
commit
9e0e23a339
@ -1,7 +1,7 @@
|
||||
from flask import Blueprint
|
||||
from flask_restx import Namespace
|
||||
|
||||
from controllers.openapi._errors import ErrorBody, OpenApiErrorFormatter
|
||||
from controllers.openapi._errors import ErrorBody, OpenApiErrorCode, OpenApiErrorFormatter
|
||||
from libs.device_flow_security import attach_anti_framing
|
||||
from libs.external_api import ExternalApi
|
||||
|
||||
@ -20,7 +20,7 @@ openapi_ns = Namespace("openapi", description="User-scoped operations", path="/"
|
||||
|
||||
# Register response/query models BEFORE importing controller modules so that
|
||||
# @openapi_ns.response / @openapi_ns.expect decorators can resolve model names.
|
||||
from controllers.common.schema import register_response_schema_models, register_schema_models
|
||||
from controllers.common.schema import register_enum_models, register_response_schema_models, register_schema_models
|
||||
from controllers.openapi._models import (
|
||||
AccountPayload,
|
||||
AccountResponse,
|
||||
@ -127,6 +127,9 @@ register_response_schema_models(
|
||||
ServerVersionResponse,
|
||||
HealthResponse,
|
||||
)
|
||||
# Standalone definition for contract codegen; ErrorBody.code stays an open
|
||||
# string on the wire so old clients keep parsing future codes.
|
||||
register_enum_models(openapi_ns, OpenApiErrorCode)
|
||||
|
||||
from . import (
|
||||
_meta,
|
||||
|
||||
@ -335,3 +335,15 @@ class TestErrorMatrix:
|
||||
assert wire["status"] == status
|
||||
assert wire["code"] in {c.value for c in OpenApiErrorCode}
|
||||
ErrorBody.model_validate(wire)
|
||||
|
||||
|
||||
class TestErrorCodeEnumRegistration:
|
||||
def test_enum_registered_with_all_values(self):
|
||||
from controllers.openapi import openapi_ns
|
||||
from controllers.openapi._errors import OpenApiErrorCode
|
||||
|
||||
model = openapi_ns.models.get("OpenApiErrorCode")
|
||||
assert model is not None
|
||||
schema = model.__schema__
|
||||
assert schema["type"] == "string"
|
||||
assert set(schema["enum"]) == {member.value for member in OpenApiErrorCode}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user