Skip to content

Commit

Permalink
Pass annotated origin type to build OpenAPI docs (#475)
Browse files Browse the repository at this point in the history
* Pass annotated origin type to build OpenAPI docs

* Make Python 3.8 happy
  • Loading branch information
tyzhnenko committed Feb 1, 2024
1 parent bec8e14 commit b724083
Show file tree
Hide file tree
Showing 2 changed files with 378 additions and 17 deletions.
10 changes: 10 additions & 0 deletions blacksheep/server/openapi/v3.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import collections.abc as collections_abc
import inspect
import sys
import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass, fields, is_dataclass
from datetime import date, datetime
from enum import Enum, IntEnum
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union

if sys.version_info >= (3, 9):
from typing import _AnnotatedAlias as AnnotatedAlias

from typing import _GenericAlias as GenericAlias
from typing import get_type_hints
from uuid import UUID
Expand Down Expand Up @@ -649,6 +654,11 @@ def _get_schema_by_type(
if stored_ref: # pragma: no cover
return stored_ref

if sys.version_info >= (3, 9):
if isinstance(object_type, AnnotatedAlias):
# Replace Annotated object type with the original type
object_type = getattr(object_type, "__origin__")

if self._can_handle_class_type(object_type):
return self._get_schema_for_class(object_type)

Expand Down
Loading

0 comments on commit b724083

Please sign in to comment.