from flask.views import MethodView

import flasgger

try:
    from marshmallow import Schema, fields
    from apispec.ext.marshmallow import openapi
    from apispec import APISpec as BaseAPISpec

    # Note that openapi_converter is initialized with trivial
    #   schema_name_resolver. Resolving circular reference is not
    #   supported for now. See issue #314 .
    # Also see: https://github.com/marshmallow-code/apispec/pull/447
    openapi_converter = openapi.OpenAPIConverter(
        openapi_version='2.0',
        schema_name_resolver=lambda schema: None,
        spec=None)
    schema2jsonschema = openapi_converter.schema2jsonschema
    schema2parameters = openapi_converter.schema2parameters
except ImportError:
    Schema = None
    fields = None
    schema2jsonschema = lambda schema: {}  # noqa
    schema2parameters = lambda schema: []  # noqa
    BaseAPISpec = object


class APISpec(BaseAPISpec):
    """
    Wrapper around APISpec to add `to_flasgger` method
    """
示例#2
0
# coding: utf-8
import inspect

from flask.views import MethodView

import flasgger

try:
    from marshmallow import Schema, fields
    from apispec.ext.marshmallow import openapi
    from apispec import APISpec as BaseAPISpec

    openapi_converter = openapi.OpenAPIConverter(openapi_version='2.0')
    schema2jsonschema = openapi_converter.schema2jsonschema
    schema2parameters = openapi_converter.schema2parameters
except ImportError:
    Schema = None
    fields = None
    schema2jsonschema = lambda schema: {}  # noqa
    schema2parameters = lambda schema: []  # noqa
    BaseAPISpec = object


class APISpec(BaseAPISpec):
    """
    Wrapper around APISpec to add `to_flasgger` method
    """
    def to_flasgger(self, app=None, definitions=None, paths=None):
        """
        Converts APISpec dict to flasgger suitable dict
        also adds definitions and paths (optional)