11
11
from pathlib import Path
12
12
from urllib import request
13
13
import graphlib
14
- from . utils import get_valid_identifier , get_key_by_value , get_dependencies
14
+ from utils import get_valid_identifier , get_key_by_value , get_dependencies
15
15
16
16
sys .path .insert (0 , str (Path .cwd ()))
17
17
@@ -58,7 +58,13 @@ def generate_class(class_name: str, class_schema: Dict[str, Any]) -> str:
58
58
optional_params = []
59
59
60
60
# Ensuring all the property names are valid Python identifiers
61
+ < << << << HEAD
61
62
valid_properties = {}
63
+ == == == =
64
+ valid_property_keys = map (get_valid_identifier , properties .keys ())
65
+ properties = dict (zip (valid_property_keys , properties .values ()))
66
+
67
+ >> >> >> > 5 a69500f83ddf4e842161bbf7cac73e6d3a32621
62
68
for prop , prop_schema in properties .items ():
63
69
valid_prop = get_valid_identifier (prop )
64
70
valid_properties [valid_prop ] = prop_schema
@@ -121,7 +127,11 @@ def get_type_hint(type_schema: Dict[str, Any]) -> str:
121
127
return f"List[{ datatype } ]"
122
128
123
129
if 'type' in type_schema :
130
+ < << << << HEAD
124
131
if isinstance (type_schema ['type' ], list ):
132
+ == == == =
133
+ if not isinstance (type_schema ['type' ], str ) and isinstance (type_schema ['type' ], Iterable ):
134
+ > >> >> >> 5 a69500f83ddf4e842161bbf7cac73e6d3a32621
125
135
types = []
126
136
for t in type_schema ['type' ]:
127
137
datatype = KNOWN_PRIMITIVES .get (t )
@@ -137,6 +147,10 @@ def get_type_hint(type_schema: Dict[str, Any]) -> str:
137
147
return 'Any'
138
148
return datatype
139
149
elif 'anyOf' in type_schema :
150
+ << << << < HEAD
151
+ == == == =
152
+ assert isinstance (type_schema ['anyOf' ], list )
153
+ >> >> >> > 5 a69500f83ddf4e842161bbf7cac73e6d3a32621
140
154
types = [get_type_hint (option ) for option in type_schema ['anyOf' ]]
141
155
return get_type_union (types )
142
156
elif '$ref' in type_schema :
@@ -156,9 +170,6 @@ def generate_schema_wrapper(schema_file: Path, output_file: Path) -> str:
156
170
rootschema_definitions = rootschema .get ("definitions" , {})
157
171
ts = graphlib .TopologicalSorter ()
158
172
159
- # if not output_file.parent.exists():
160
- # output_file.parent.mkdir(parents=True, exist_ok=True)
161
-
162
173
for name , schema in rootschema_definitions .items ():
163
174
dependencies = get_dependencies (schema )
164
175
if dependencies :
0 commit comments