Skip to content
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

Class-based endpoints produce an error on schema generation #15

Closed
mbarrientos opened this issue Mar 20, 2019 · 1 comment
Closed

Class-based endpoints produce an error on schema generation #15

mbarrientos opened this issue Mar 20, 2019 · 1 comment

Comments

@mbarrientos
Copy link

When using class-based endpoints, if no methods are explicitly passed to add_route, this will raise an error when generating the schema. (using starlette==0.11.4, starlette-api==0.6.2)

from starlette.requests import Request
from starlette.responses import Response
from starlette_api.applications import Starlette
from starlette_api.endpoints import HTTPEndpoint

app = Starlette(
    title="Test",
    version="1.0",
    description="Test",
    schema="/schema/",
    docs="/docs/",
    redoc="/redoc/",
)

class FooEndpoint(HTTPEndpoint):
    async def get(self, request: Request):
        return Response()

    async def post(self, request: Request):
        return Response()

app.add_route("/", FooEndpoint, name="foo")

Traceback:

INFO: ('127.0.0.1', 53618) - "GET /schema/ HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
    result = await asgi(self.receive, self.send)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/uvicorn/middleware/debug.py", line 83, in __call__
    raise exc from None
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/uvicorn/middleware/debug.py", line 80, in __call__
    await asgi(receive, self.send)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette/middleware/errors.py", line 125, in asgi
    raise exc from None
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette/middleware/errors.py", line 103, in asgi
    await asgi(receive, _send)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette/exceptions.py", line 74, in app
    raise exc from None
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette/exceptions.py", line 63, in app
    await instance(receive, sender)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/routing.py", line 174, in awaitable
    response = await run_in_threadpool(injected_func)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette/concurrency.py", line 24, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 223, in schema
    return OpenAPIResponse(self.schema)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 219, in schema
    return self.schema_generator.get_schema(self.routes)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 175, in get_schema
    self.spec.add_path(path=path, operations={e.method: self.get_endpoint_schema(e) for e in endpoints})
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 175, in <dictcomp>
    self.spec.add_path(path=path, operations={e.method: self.get_endpoint_schema(e) for e in endpoints})
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 156, in get_endpoint_schema
    self.get_endpoint_parameters_schema(endpoint, schema)
  File "/Users/test/.virtualenvs/play/lib/python3.7/site-packages/starlette_api/schemas.py", line 114, in get_endpoint_parameters_schema
    for field in itertools.chain(endpoint.query_fields.values(), endpoint.path_fields.values())
AttributeError: 'NoneType' object has no attribute 'values'
@perdy perdy closed this as completed in 0429f27 Mar 20, 2019
@perdy
Copy link
Member

perdy commented Mar 20, 2019

Should be fixed with changes committed on 0429f27.

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants