From 99a215272de7603ebcfc2a24b85f0ffd89a0cd01 Mon Sep 17 00:00:00 2001 From: Rodrigo Santa Cruz Date: Wed, 12 Apr 2023 14:08:21 -0500 Subject: [PATCH 1/4] Reset swagger attributes in case of inheritance. --- flasgger/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flasgger/utils.py b/flasgger/utils.py index d0f43f9a..aacc5ccc 100644 --- a/flasgger/utils.py +++ b/flasgger/utils.py @@ -171,11 +171,16 @@ def get_specs(rules, ignore_verbs, optional_fields, sanitizer, else: file_path = os.path.join( doc_dir, endpoint.__name__ + '.yml') + func = method.__func__ \ + if hasattr(method, '__func__') else method if os.path.isfile(file_path): - func = method.__func__ \ - if hasattr(method, '__func__') else method setattr(func, 'swag_type', 'yml') setattr(func, 'swag_path', file_path) + else: + # Reset in case of inheritance. + setattr(func, 'swag_type', None) + setattr(func, 'swag_path', None) + doc_summary, doc_description, doc_swag = parse_docstring( method, sanitizer, endpoint=rule.endpoint, verb=verb) From aa3464c62a1233f1503a6fb135d8c5d52a02b19d Mon Sep 17 00:00:00 2001 From: Rodrigo Santa Cruz Date: Mon, 19 Feb 2024 01:17:22 -0500 Subject: [PATCH 2/4] Use rule.endpoint instead of endpoint.__name__ to get the yml filename. This is important for cases where the same function is used for two different views. --- flasgger/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/flasgger/utils.py b/flasgger/utils.py index aacc5ccc..2c47c4cd 100644 --- a/flasgger/utils.py +++ b/flasgger/utils.py @@ -165,12 +165,16 @@ def get_specs(rules, ignore_verbs, optional_fields, sanitizer, swagged = True if doc_dir: + endpoint_name = rule.endpoint + if "." in endpoint_name: + endpoint_name = endpoint_name.split(".")[-1] + if view_class: file_path = os.path.join( - doc_dir, endpoint.__name__, method.__name__ + '.yml') + doc_dir, endpoint_name, method.__name__ + '.yml') else: file_path = os.path.join( - doc_dir, endpoint.__name__ + '.yml') + doc_dir, endpoint_name + '.yml') func = method.__func__ \ if hasattr(method, '__func__') else method if os.path.isfile(file_path): From 261fabe8cfd55cfbd0af6deff3cc0d3c4dc36e17 Mon Sep 17 00:00:00 2001 From: Rodrigo Santa Cruz Date: Mon, 17 Jun 2024 18:27:08 -0500 Subject: [PATCH 3/4] fix: import Markup from markupsafe when needed This is to support Flask 3.0.0 and above --- flasgger/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flasgger/base.py b/flasgger/base.py index 4faca7d8..d62b470b 100644 --- a/flasgger/base.py +++ b/flasgger/base.py @@ -17,7 +17,10 @@ from functools import wraps, partial from collections import defaultdict from flask import Blueprint -from flask import Markup +try: + from flask import Markup +except ImportError: + from markupsafe import Markup from flask import current_app from flask import jsonify, Response from flask import redirect From 3428eecab330c7ab8cedf19b9af45baf398d3980 Mon Sep 17 00:00:00 2001 From: Rodrigo Santa Cruz Date: Mon, 17 Jun 2024 18:38:14 -0500 Subject: [PATCH 4/4] fix: import JSONEncoder from json --- flasgger/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flasgger/base.py b/flasgger/base.py index d62b470b..5390a854 100644 --- a/flasgger/base.py +++ b/flasgger/base.py @@ -28,7 +28,10 @@ from flask import request, url_for from flask import abort from flask.views import MethodView -from flask.json import JSONEncoder +try: + from flask.json import JSONEncoder +except ImportError: + from json import JSONEncoder try: from flask_restful.reqparse import RequestParser except ImportError: