DateTime(format="timestamp") generates invalid OpenAPI schema using min instead of minimum
维护者通常 1 天内回复
评估
调研方向
该 issue 指出 field_converter.py 是生成 timestamp 和 timestamp_ms schema 的来源。复现最小示例,检查两个分支,并验证生成的 schema 使用有效的 OpenAPI 数值约束且通过规范验证。
由索引模型根据 Issue 内容生成。
描述
Description
apispec generates an invalid OpenAPI schema for marshmallow.fields.DateTime(format="timestamp").
The generated schema contains the min property:
changedOn:
type: number
format: float
example: "1676451245.596"
min: "0"
However, min is not a valid OpenAPI Schema Object property. As a result, the generated specification fails validation with openapi-spec-validator:
OpenAPIValidationError:
Property 'min' is not allowed
This was reproduced with:
- apispec 6.10.0
- marshmallow 3.26.2
- openapi-spec-validator 0.9.0
- OpenAPI 3.0.2
Expected behavior
The generated schema should use the standard OpenAPI keyword minimum instead of min, for example:
changedOn:
type: number
format: float
example: "1676451245.596"
minimum: 0
or omit the constraint entirely if no minimum value is intended.
Minimal reproduction
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from marshmallow import Schema, fields
from pprint import pprint
class TestSchema(Schema):
ts = fields.DateTime(format="timestamp")
spec = APISpec(
title="test",
version="1.0",
openapi_version="3.0.2",
plugins=[MarshmallowPlugin()],
)
spec.components.schema("Test", schema=TestSchema)
pprint(spec.to_dict()["components"]["schemas"]["Test"])
Output:
{'additionalProperties': False,
'properties': {'ts': {'example': '1676451245.596',
'format': 'float',
'min': '0',
'type': 'number'}},
'type': 'object'}
The file field_converter.py contains the code that causes this issue:
elif field.format == "timestamp":
ret = {
"type": "number",
"format": "float",
"example": "1676451245.596",
"min": "0",
}
elif field.format == "timestamp_ms":
ret = {
"type": "number",
"format": "float",
"example": "1676451277514.654",
"min": "0",
}
Specification reference
The OpenAPI Schema Object defines the numeric constraint keyword as minimum; min is not a valid keyword.
OpenAPI 3.0.2 Schema Object:
https://spec.openapis.org/oas/v3.0.2#schema-object
- 主要语言
- Python
- 星标
- 1.2k
- 派生
- 210
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
marshmallow-code/apispec 的其他 Issue
-
documentation
难度 2/5 1-3 小时 新手友好度 68/100
marshmallow-code/apispec#750 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 30/100
marshmallow-code/apispec#1033 ·
维护者通常 1 天内回复
-
`apispec` ignores `oneOf` from `marshmallow-oneofschema`可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 38/100
marshmallow-code/apispec#1012 · 6 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
marshmallow-code/apispec#981 · 2 条评论 ·
维护者通常 1 天内回复
-
Date and DateTime with format argument not rendered correctly可能已有人在做 @jbbqqf 于 173 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
marshmallow-code/apispec#938 · 1 个 reaction ·
维护者通常 1 天内回复
查看 marshmallow-code/apispec 的全部 Issue
相似的 Issue
-
[BUG] HTTP lifecycle dispatch treats a NO_PROXY-only environment as corporate egress and skips the resolve-and-pinned session可能已有人在做 @bodapatisaikrishna 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
external
难度 2/5 1-3 小时 新手友好度 65/100
langchain-ai/docs#7652 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
elastic/oblt-aw#2513 · 1 条评论 ·
维护者通常 1 天内回复
-
bug p2
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 75/100
NCAR/CLM-Tutorial#113 · 1 条评论 ·
维护者通常 1 天内回复