DateTime(format="timestamp") generates invalid OpenAPI schema using min instead of minimum

未关闭 适合新手
#1,064 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Sanjays2402 已经在做这个了。

开始于 2026年8月1日。

  • #1067 来自 @Sanjays2402 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
openapi, python
领域
api

调研方向

该 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

marshmallow-code/apispec 的其他 Issue

查看 marshmallow-code/apispec 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。