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

Fix 404 on openapi spec #148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions fastapi_crudrouter/core/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

from fastapi import APIRouter, HTTPException
from fastapi.types import DecoratedCallable
from pydantic import BaseModel

from ._types import T, DEPENDENCIES
from ._types import DEPENDENCIES, T
from ._utils import pagination_factory, schema_factory

NOT_FOUND = HTTPException(404, "Item not found")

class NotFoundModel(BaseModel):
detail: str

NOT_FOUND = HTTPException(404, "Item not found")

class CRUDGenerator(Generic[T], APIRouter, ABC):
schema: Type[T]
Expand Down Expand Up @@ -126,7 +130,10 @@ def _add_api_route(
) -> None:
dependencies = [] if isinstance(dependencies, bool) else dependencies
responses: Any = (
{err.status_code: {"detail": err.detail} for err in error_responses}
{
err.status_code: {"model": NotFoundModel}
for err in error_responses
}
if error_responses
else None
)
Expand Down