File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 99
1010def resolve_and_validate_openapi_spec (file_contents : str ) -> dict | None :
1111 parser = prance .ResolvingParser (
12- spec_string = json . dumps ( file_contents ) ,
12+ spec_string = file_contents ,
1313 resolve_types = RESOLVE_INTERNAL ,
1414 backend = "openapi-spec-validator" ,
1515 lazy = True ,
@@ -23,19 +23,21 @@ def resolve_and_validate_openapi_spec(file_contents: str) -> dict | None:
2323
2424
2525def parse_resolve_and_validate_openapi_spec (file_path : str , get_file_contents : Callable [[], str ]) -> dict | None :
26+ # First check it's a valid JSON/YAML file before passing it over to Prance
2627 if file_path .endswith (".json" ):
2728 try :
28- file_contents = json .loads (get_file_contents ())
29+ json .loads (get_file_contents ())
2930 except : # noqa: E722
3031 return None
3132
3233 elif file_path .endswith ((".yaml" , ".yml" )):
3334 try :
34- file_contents = yaml .safe_load (get_file_contents ())
35+ yaml .safe_load (get_file_contents ())
3536 except : # noqa: E722
3637 return None
3738
3839 else :
3940 return None
40-
41- return resolve_and_validate_openapi_spec (file_contents )
41+
42+ # If it was a valid JSON/YAML file, we can give it to Prance to load
43+ return resolve_and_validate_openapi_spec (get_file_contents ())
You can’t perform that action at this time.
0 commit comments