Skip to content

Compatibility with marshmallow 4 #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ env:
- MARSHMALLOW_VERSION="==3.0.0"
- MARSHMALLOW_VERSION=""
python:
- '3.6'
- '3.8'
before_install:
- travis_retry pip install codecov
Expand Down
9 changes: 3 additions & 6 deletions flask_apispec/apidoc.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import copy
import functools

import apispec
from apispec.core import VALID_METHODS
from apispec.ext.marshmallow import MarshmallowPlugin

from marshmallow import Schema
from marshmallow.utils import is_instance_or_subclass

from flask_apispec.paths import rule_to_path, rule_to_params
from flask_apispec.utils import resolve_resource, resolve_annotations, merge_recursive

APISPEC_VERSION_INFO = tuple(
[int(part) for part in apispec.__version__.split('.') if part.isdigit()]
from flask_apispec.utils import (
is_instance_or_subclass, resolve_resource, resolve_annotations, merge_recursive
)


class Converter:
def __init__(self, app, spec, document_options=True):
self.app = app
Expand Down
7 changes: 7 additions & 0 deletions flask_apispec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ def _merge_recursive(child, parent):
for key in keys
}
return child if child is not None else parent


def is_instance_or_subclass(val, class_):
try:
return issubclass(val, class_)
except TypeError:
return isinstance(val, class_)
9 changes: 4 additions & 5 deletions flask_apispec/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from flask import Response

import importlib.metadata
from collections.abc import Mapping

import flask
import marshmallow as ma
import werkzeug
from packaging.version import Version
from webargs import flaskparser

from flask_apispec import utils

MARSHMALLOW_VERSION_INFO = tuple(
[int(part) for part in ma.__version__.split('.') if part.isdigit()]
)
MARSHMALLOW_VERSION = Version(importlib.metadata.version("marshmallow"))


class Wrapper:
Expand Down Expand Up @@ -60,7 +59,7 @@ def marshal_result(self, result, status_code):
if schema and annotation.apply is not False:
schema = utils.resolve_schema(schema['schema'], request=flask.request)
dumped = schema.dump(result)
output = dumped.data if MARSHMALLOW_VERSION_INFO[0] < 3 else dumped
output = dumped.data if MARSHMALLOW_VERSION.major < 3 else dumped
else:
output = result

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def read(fname):
license='MIT',
zip_safe=False,
keywords='flask marshmallow webargs apispec',
python_requires=">=3.6",
python_requires=">=3.8",
dependencies=["packaging>=17.0"],
test_suite='tests',
project_urls={
'Bug Reports': 'https://github.com/jmcarp/flask-apispec/issues',
Expand Down