Skip to content

Commit 0dd9f85

Browse files
committed
Fix errors after updating
1 parent 3a96f99 commit 0dd9f85

File tree

1 file changed

+11
-2
lines changed
  • openapi_python_client/schema/openapi_schema_pydantic

1 file changed

+11
-2
lines changed

openapi_python_client/schema/openapi_schema_pydantic/reference.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import Annotated, TypeVar
1+
from typing import Annotated, Any, Literal, TypeVar
22

33
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag
4+
from pydantic_core import ArgsKwargs
45

56

67
class Reference(BaseModel):
@@ -31,7 +32,15 @@ class Reference(BaseModel):
3132
T = TypeVar('T')
3233

3334

35+
def _reference_discriminator(obj: Any) -> Literal['ref', 'other']:
36+
if isinstance(obj, dict):
37+
return 'ref' if '$ref' in obj else 'other'
38+
if isinstance(obj, ArgsKwargs):
39+
return 'ref' if 'ref' in obj.kwargs else 'other'
40+
return 'ref' if isinstance(obj, Reference) else 'other'
41+
42+
3443
ReferenceOr = Annotated[
3544
Annotated[Reference, Tag('ref')] |
3645
Annotated[T, Tag('other')],
37-
Discriminator(lambda d: 'ref' if '$ref' in d else 'other')]
46+
Discriminator(_reference_discriminator)]

0 commit comments

Comments
 (0)