Skip to content

Commit

Permalink
[FIX] Sequences wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
acwazz committed Aug 5, 2022
1 parent 1feb21a commit c324099
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fastapi_responseschema/__init__.py
Expand Up @@ -3,7 +3,7 @@
from .helpers import wrap_app_responses, wrap_error_responses


__version__ = '1.2.1'
__version__ = '1.2.2'


__all__ = [
Expand Down
12 changes: 11 additions & 1 deletion fastapi_responseschema/routing.py
@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
import inspect
from typing import (
Callable,
Optional,
Expand All @@ -12,6 +13,7 @@
Set
)
from functools import wraps
import fastapi
from fastapi import params, Response
from fastapi.encoders import DictIntStrAny, SetIntStr
from fastapi.routing import APIRoute
Expand Down Expand Up @@ -152,7 +154,15 @@ def __init__(
callbacks: Optional[List["APIRoute"]] = None,
**kwargs: Any
) -> None:
if response_model and not issubclass(response_model, AbstractResponseSchema): # If a `response_model` is set, then wrap the `response_model` with a response schema
try:
is_response_schema = issubclass(response_model, AbstractResponseSchema)
except TypeError:
if not inspect.isclass(response_model) and not response_model is None:
raise fastapi.exceptions.FastAPIError(
f"Invalid args for response field! Hint: check that {response_model} is a valid pydantic field type"
)
is_response_schema = False
if response_model and not is_response_schema: # If a `response_model` is set, then wrap the `response_model` with a response schema
WrapperModel = self.get_wrapper_model(is_error=self.is_error_state(status_code=status_code), response_model=response_model)
endpoint_wrapper = self._create_endpoint_handler_decorator(
path=path,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-responseschema"
version = "1.2.1"
version = "1.2.2"
description = "Generic and common response schemas for FastAPI"
authors = ["Emanuele Addis <ustarjem.acwazz@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fastapi_responseschema.py
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == '1.2.1'
assert __version__ == '1.2.2'

0 comments on commit c324099

Please sign in to comment.