Skip to content

docstring parsing doesn't work if you have inheritance in class based view #93

Description

@well2life

I'm trying to use inheritance in my class based view:

from aiohttp import web
from aiohttp_swagger3 import SwaggerDocs, SwaggerUiSettings


class BaseApi(web.View):
    async def get(self):
        return web.json_response(data={'called_method': 'GET'})

    async def post(self):
        return web.json_response(data={'called_method': 'POST'})

    async def put(self):
        return web.json_response(data={'called_method': 'PUT'})

    async def patch(self):
        return web.json_response(data={'called_method': 'PATCH'})


class SomeApi(BaseApi):
    def some_stuff(self):
        pass

    async def get(self):
        """
        ---
        summary: Some GET method
        responses:
          '200':
            description: OK.
        """
        self.some_stuff()
        return await super().get()


app = web.Application()

swagger = SwaggerDocs(
        app,
        swagger_ui_settings=SwaggerUiSettings(path="/api/v1.0.0/docs/"),
        title="Proto",
        version="1.0.0",
    )

swagger.add_routes([
        web.view('/api/some_api', SomeApi, name="some_api"),
    ])

web.run_app(app, host="127.0.0.1")

But I receive next exception:

File "lib/site-packages/aiohttp_swagger3/swagger_route.py", line 36, in _get_fn_parameters
    if func.__closure__ is None:
AttributeError: type object 'SomeApi' has no attribute '__closure__'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions