[Bug]: Query parameter validation fails to match empty string when listed as a valid enum value
还没有人认领这个 Issue。
评估
调研方向
Start with the OpenAPI.from_dict and MockRequest reproduction, then trace iter_request_errors through query-parameter enum validation. Add a regression test covering status= when the enum includes an empty string, and confirm the request is accepted without a ParameterValidationError.
由索引模型根据 Issue 内容生成。
描述
Actual Behavior
Run the following code:
from openapi_core import OpenAPI
from openapi_core.testing import MockRequest
SPEC = {
"openapi": "3.2.0",
"info": {"title": "Sample", "version": "1.0.0"},
"paths": {
"/api": {
"get": {
"tags": ["Sample"],
"parameters": [
{
"name": "status",
"in": "query",
"schema": {"enum": ["Active", "Inactive", "Pending", ""]},
}
]
}
}
},
"tags": [{"name": "Sample"}],
}
openapi = OpenAPI.from_dict(SPEC)
# Empty query parameter: status=
request = MockRequest(
host_url="http://localhost",
method="get",
path="/api",
args={"status": ""},
)
if hasattr(openapi, "iter_request_errors"):
errors = list(openapi.iter_request_errors(request))
if errors:
print("INVALID")
for e in errors:
print(f" {type(e).__name__}: {e}")
else:
print("VALID")
else:
try:
openapi.validate_request(request)
print("VALID")
except Exception as exc:
print("INVALID")
print(f" {type(exc).__name__}: {exc}")
It prints:
INVALID
ParameterValidationError: Query parameter error: status
Expected Behavior
It should print VALID.
OpenAPI Core Version
0.23.1
See https://github.com/OAI/OpenAPI-Specification/discussions/5411
- 主要语言
- Python
- 星标
- 368
- 派生
- 140
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-openapi/openapi-core 的其他 Issue
-
kind/bug
难度 2/5 1-3 小时 新手友好度 68/100
python-openapi/openapi-core#1188 · 2 条评论 ·
-
kind/bug
难度 3/5 1-2 天 新手友好度 68/100
python-openapi/openapi-core#1225 · 2 条评论 ·
-
kind/bug
难度 3/5 1-2 天 新手友好度 76/100
python-openapi/openapi-core#1212 ·
-
kind/bug kind/bug/confirmed
难度 3/5 1-2 天 新手友好度 58/100
python-openapi/openapi-core#1180 · 3 条评论 ·
-
kind/enhancement
难度 5/5 一周以上 新手友好度 32/100
python-openapi/openapi-core#1142 ·
查看 python-openapi/openapi-core 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 90/100
learningequality/ricecooker#747 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 76/100
run-llama/llama_index#23199 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
KhronosGroup/glTF-Blender-IO#2769 ·