17
17
import pytest
18
18
from pydantic import TypeAdapter
19
19
20
- from openapi_python_client .schema .openapi_schema_pydantic import Callback , Example , Header , Link , Parameter , PathItem , Reference , RequestBody , Response , Schema , SecurityScheme
21
-
20
+ from openapi_python_client .schema .openapi_schema_pydantic import (
21
+ Callback ,
22
+ Example ,
23
+ Header ,
24
+ Link ,
25
+ Parameter ,
26
+ PathItem ,
27
+ Reference ,
28
+ RequestBody ,
29
+ Response ,
30
+ Schema ,
31
+ SecurityScheme ,
32
+ )
22
33
23
34
try :
24
35
from openapi_python_client .schema .openapi_schema_pydantic .reference import ReferenceOr
@@ -34,10 +45,11 @@ def get_example(base_type):
34
45
return schema ["examples" ][0 ]
35
46
if "$defs" in schema :
36
47
return schema ["$defs" ][base_type .__name__ ]["examples" ][0 ]
37
- assert False , f"No example found for { base_type .__name__ } "
48
+ raise TypeError (f"No example found for { base_type .__name__ } " )
49
+
38
50
39
51
def deannotate_type (t ):
40
- while get_origin (t ) == Annotated :
52
+ while get_origin (t ) is Annotated :
41
53
t = get_args (t )[0 ]
42
54
return t
43
55
@@ -60,17 +72,18 @@ def deannotate_type(t):
60
72
def test_type (ref_or_type , get_example_fn ):
61
73
base_type = None
62
74
print (deannotate_type (ref_or_type ))
63
- for base_type in get_args (deannotate_type (ref_or_type )):
64
- base_type = deannotate_type (base_type )
65
- if base_type != Reference :
75
+ for maybe_annotated_type in get_args (deannotate_type (ref_or_type )):
76
+ each_type = deannotate_type (maybe_annotated_type )
77
+ if each_type is not Reference :
78
+ base_type = each_type
66
79
break
67
80
assert base_type is not None
68
81
69
82
example = get_example_fn (base_type )
70
83
71
84
parsed = TypeAdapter (ref_or_type ).validate_python (example )
72
- assert type (parsed ) == get_origin (base_type ) or base_type
85
+ assert type (parsed ) is get_origin (base_type ) or base_type
73
86
74
87
example ["$ref" ] = "ref"
75
88
parsed = TypeAdapter (ref_or_type ).validate_python (example )
76
- assert type (parsed ) == Reference
89
+ assert type (parsed ) is Reference
0 commit comments