From 47f20ce70f41249518b3a26f9e99e3f9a917a23b Mon Sep 17 00:00:00 2001 From: Daniele Esposti Date: Wed, 28 Aug 2024 20:43:22 +0200 Subject: [PATCH] Fixed generating Marshmallow DateTime formats --- src/apispec/ext/marshmallow/field_converter.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/apispec/ext/marshmallow/field_converter.py b/src/apispec/ext/marshmallow/field_converter.py index 4e17aa2e..3bd16ed7 100644 --- a/src/apispec/ext/marshmallow/field_converter.py +++ b/src/apispec/ext/marshmallow/field_converter.py @@ -574,13 +574,25 @@ def datetime2properties(self, field, **kwargs: typing.Any) -> dict: "example": "1676451277514.654", "min": "0", } + elif field.format is not None: + ret = { + "type": "string", + "format": None, + "pattern": ( + field.metadata["pattern"] + if field.metadata.get("pattern") + else None + ), + } else: ret = { "type": "string", "format": None, - "pattern": field.metadata["pattern"] - if field.metadata.get("pattern") - else None, + "pattern": ( + field.metadata["pattern"] + if field.metadata.get("pattern") + else None + ), } return ret