Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ Contributors (chronological)
- Xingang Zhang `@0x0400 <https://github.com/0x0400>`_
- Lewis Haley `@LewisHaley <https://github.com/LewisHaley>`_
- Felix Claessen `@Flix6x <https://github.com/Flix6x>`_
- Karthik Ramadugu `@karthiksai109 <https://github.com/karthiksai109>`_
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
---------

unreleased
**********

Bug fixes:

- ``MarshmallowPlugin``: Handle `DateTime` fields with the `"iso8601"` and `"rfc822"`
formats (:issue:`970`). Thanks :user:`matejsp` for reporting and `karthiksai109`
for the PR (:pr:`1013`).

6.9.0 (2025-11-30)
******************

Expand Down
4 changes: 2 additions & 2 deletions src/apispec/ext/marshmallow/field_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ def datetime2properties(self, field, **kwargs: typing.Any) -> dict:
"""
ret = {}
if isinstance(field, marshmallow.fields.DateTime):
if field.format == "iso" or field.format is None:
if field.format in ("iso", "iso8601") or field.format is None:
# Will return { "type": "string", "format": "date-time" }
# as specified inside DEFAULT_FIELD_MAPPING
pass
elif field.format == "rfc":
elif field.format in ("rfc", "rfc822"):
ret = {
"type": "string",
"format": None,
Expand Down
22 changes: 22 additions & 0 deletions tests/test_ext_marshmallow_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,15 @@ def test_datetime2property_iso(spec_fixture):
}


def test_datetime2property_iso8601(spec_fixture):
field = fields.DateTime(format="iso8601")
res = spec_fixture.openapi.field2property(field)
assert res == {
"type": "string",
"format": "date-time",
}


def test_datetime2property_rfc(spec_fixture):
field = fields.DateTime(format="rfc")
res = spec_fixture.openapi.field2property(field)
Expand All @@ -563,6 +572,19 @@ def test_datetime2property_rfc(spec_fixture):
}


def test_datetime2property_rfc822(spec_fixture):
field = fields.DateTime(format="rfc822")
res = spec_fixture.openapi.field2property(field)
assert res == {
"type": "string",
"format": None,
"example": "Wed, 02 Oct 2002 13:00:00 GMT",
"pattern": r"((Mon|Tue|Wed|Thu|Fri|Sat|Sun), ){0,1}\d{2} "
+ r"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} "
+ r"(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|(Z|A|M|N)|(\+|-)\d{4})",
}


def test_datetime2property_timestamp(spec_fixture):
field = fields.DateTime(format="timestamp")
res = spec_fixture.openapi.field2property(field)
Expand Down