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

Đang mở Phù hợp với người mới
#1,064 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Sanjays2402 đang làm issue này rồi.

Từ ngày 1/8/2026.

  • #1067 của @Sanjays2402 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
openapi, python
Lĩnh vực
api

Hướng nghiên cứu

Issue xác định field_converter.py là nguồn tạo schema cho timestamp và timestamp_ms. Tái hiện ví dụ tối thiểu, kiểm tra cả hai nhánh và xác minh rằng schema được tạo sử dụng ràng buộc số hợp lệ của OpenAPI và vượt qua bước xác thực đặc tả.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
1.2k
Fork
210
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của marshmallow-code/apispec

Tất cả issue của marshmallow-code/apispec

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.