From 1ea911a902e7f2c48325e6072a791f34c7abe0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20Huy?= <93045745+duchuyvp@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:07:50 +0700 Subject: [PATCH 1/2] Fix resolver function with schema has spaces in name --- AUTHORS.rst | 1 + src/apispec/ext/marshmallow/__init__.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 17bea2b9..39c485ee 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -78,3 +78,4 @@ Contributors (chronological) - Mounier Florian `@paradoxxxzero `_ - Renato Damas `@codectl `_ - Tayler Sokalski `@tsokalski `_ +- Luna Lovegood `@duchuyvp `_ \ No newline at end of file diff --git a/src/apispec/ext/marshmallow/__init__.py b/src/apispec/ext/marshmallow/__init__.py index 2595581d..6e118099 100644 --- a/src/apispec/ext/marshmallow/__init__.py +++ b/src/apispec/ext/marshmallow/__init__.py @@ -89,8 +89,9 @@ def resolver(schema: type[Schema]) -> str: schema_cls = resolve_schema_cls(schema) name = schema_cls.__name__ if name.endswith("Schema"): - return name[:-6] or name - return name + name_ = name[:-6] or name + return name_.strip() + return name.strip() class MarshmallowPlugin(BasePlugin): From 27d255a480e13944d9145aa65a6d26d5e6f0586b Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 9 Jan 2024 22:51:26 -0500 Subject: [PATCH 2/2] Minor cleanup and changelog update --- CHANGELOG.rst | 2 ++ src/apispec/ext/marshmallow/__init__.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c7b07a21..944fc399 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,8 @@ Features: - ``MarshmallowPlugin``: Support different datetime formats for ``marshmallow.fields.DateTime`` fields (:issue:`814`). Thanks :user:`TheBigRoomXXL` for the suggestion and PR. +- ``MarshmallowPlugin``: Handle resolving names of schemas with spaces in the name (:pr:`856`). + Thanks :user:`duchuyvp` for the PR. Other changes: diff --git a/src/apispec/ext/marshmallow/__init__.py b/src/apispec/ext/marshmallow/__init__.py index 6e118099..46021005 100644 --- a/src/apispec/ext/marshmallow/__init__.py +++ b/src/apispec/ext/marshmallow/__init__.py @@ -89,8 +89,7 @@ def resolver(schema: type[Schema]) -> str: schema_cls = resolve_schema_cls(schema) name = schema_cls.__name__ if name.endswith("Schema"): - name_ = name[:-6] or name - return name_.strip() + name = name[:-6] or name return name.strip()