22
33from dataclasses import dataclass , field
44from enum import Enum
5- from typing import Dict , List , Optional , Set , Iterable , Generator
5+ from typing import Any , Dict , Generator , Iterable , List , Optional , Set
66
7- from .properties import Property , property_from_dict , ListProperty , RefProperty , EnumProperty
7+ from .properties import EnumProperty , ListProperty , Property , RefProperty , property_from_dict
88from .reference import Reference
9- from .responses import Response , response_from_dict
9+ from .responses import ListRefResponse , RefResponse , Response , response_from_dict
1010
1111
1212class ParameterLocation (str , Enum ):
@@ -30,7 +30,7 @@ class EndpointCollection:
3030 relative_imports : Set [str ] = field (default_factory = set )
3131
3232 @staticmethod
33- def from_dict (d : Dict [str , Dict [str , Dict ]], / ) -> Dict [str , EndpointCollection ]:
33+ def from_dict (d : Dict [str , Dict [str , Dict [ str , Any ] ]], / ) -> Dict [str , EndpointCollection ]:
3434 """ Parse the openapi paths data to get EndpointCollections by tag """
3535 endpoints_by_tag : Dict [str , EndpointCollection ] = {}
3636 for path , path_data in d .items ():
@@ -55,6 +55,10 @@ def from_dict(d: Dict[str, Dict[str, Dict]], /) -> Dict[str, EndpointCollection]
5555
5656 for code , response_dict in method_data ["responses" ].items ():
5757 response = response_from_dict (status_code = int (code ), data = response_dict )
58+ if isinstance (response , (RefResponse , ListRefResponse )):
59+ collection .relative_imports .add (
60+ import_string_from_reference (response .reference , prefix = "..models" )
61+ )
5862 responses .append (response )
5963 form_body_reference = None
6064 if "requestBody" in method_data :
@@ -69,7 +73,7 @@ def from_dict(d: Dict[str, Dict[str, Dict]], /) -> Dict[str, EndpointCollection]
6973 path_parameters = path_parameters ,
7074 responses = responses ,
7175 form_body_reference = form_body_reference ,
72- requires_security = method_data .get ("security" ),
76+ requires_security = bool ( method_data .get ("security" ) ),
7377 )
7478
7579 collection .endpoints .append (endpoint )
@@ -97,7 +101,7 @@ class Endpoint:
97101 form_body_reference : Optional [Reference ]
98102
99103 @staticmethod
100- def parse_request_body (body : Dict , / ) -> Optional [Reference ]:
104+ def parse_request_body (body : Dict [ str , Any ] , / ) -> Optional [Reference ]:
101105 """ Return form_body_ref """
102106 form_body_reference = None
103107 body_content = body ["content" ]
@@ -122,7 +126,7 @@ class Schema:
122126 relative_imports : Set [str ]
123127
124128 @staticmethod
125- def from_dict (d : Dict , / ) -> Schema :
129+ def from_dict (d : Dict [ str , Any ] , / ) -> Schema :
126130 """ A single Schema from its dict representation """
127131 required_set = set (d .get ("required" , []))
128132 required_properties : List [Property ] = []
@@ -148,7 +152,7 @@ def from_dict(d: Dict, /) -> Schema:
148152 return schema
149153
150154 @staticmethod
151- def dict (d : Dict , / ) -> Dict [str , Schema ]:
155+ def dict (d : Dict [ str , Dict [ str , Any ]] , / ) -> Dict [str , Schema ]:
152156 """ Get a list of Schemas from an OpenAPI dict """
153157 result = {}
154158 for data in d .values ():
@@ -164,7 +168,7 @@ class OpenAPI:
164168 title : str
165169 description : str
166170 version : str
167- security_schemes : Dict
171+ # security_schemes: Dict
168172 schemas : Dict [str , Schema ]
169173 endpoint_collections_by_tag : Dict [str , EndpointCollection ]
170174 enums : Dict [str , EnumProperty ]
@@ -173,7 +177,7 @@ class OpenAPI:
173177 def check_enums (schemas : Iterable [Schema ], collections : Iterable [EndpointCollection ]) -> Dict [str , EnumProperty ]:
174178 enums : Dict [str , EnumProperty ] = {}
175179
176- def _iterate_properties () -> Generator [Property ]:
180+ def _iterate_properties () -> Generator [Property , None , None ]:
177181 for schema in schemas :
178182 yield from schema .required_properties
179183 yield from schema .optional_properties
@@ -196,7 +200,7 @@ def _iterate_properties() -> Generator[Property]:
196200 return enums
197201
198202 @staticmethod
199- def from_dict (d : Dict , / ) -> OpenAPI :
203+ def from_dict (d : Dict [ str , Dict [ str , Any ]] , / ) -> OpenAPI :
200204 """ Create an OpenAPI from dict """
201205 schemas = Schema .dict (d ["components" ]["schemas" ])
202206 endpoint_collections_by_tag = EndpointCollection .from_dict (d ["paths" ])
@@ -208,6 +212,6 @@ def from_dict(d: Dict, /) -> OpenAPI:
208212 version = d ["info" ]["version" ],
209213 endpoint_collections_by_tag = endpoint_collections_by_tag ,
210214 schemas = schemas ,
211- security_schemes = d ["components" ]["securitySchemes" ],
215+ # security_schemes=d["components"]["securitySchemes"],
212216 enums = enums ,
213217 )
0 commit comments