From 8af64530ed5dc5812d0dd7157cfadb28e0861b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20Huy?= Date: Wed, 10 Jan 2024 10:52:07 +0700 Subject: [PATCH] Fix schema name that has end with space for redoc ui and elements ui (#856) * Fix resolver function with schema has spaces in name * Minor cleanup and changelog update --------- Co-authored-by: Steven Loria --- AUTHORS.rst | 1 + CHANGELOG.rst | 2 ++ src/apispec/ext/marshmallow/__init__.py | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 539d3e9f..c3082a80 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -79,3 +79,4 @@ Contributors (chronological) - Renato Damas `@codectl `_ - Tayler Sokalski `@tsokalski `_ - Sebastien Lovergne `@TheBigRoomXXL `_ +- Luna Lovegood `@duchuyvp `_ 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 2595581d..46021005 100644 --- a/src/apispec/ext/marshmallow/__init__.py +++ b/src/apispec/ext/marshmallow/__init__.py @@ -89,8 +89,8 @@ 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() class MarshmallowPlugin(BasePlugin):