Skip to content

Commit 0191f41

Browse files
Merge pull request #28 from FireTail-io/hotfix/bad-json-dumps
Remove bad json dumps from resolve_and_validate_openapi_spec
2 parents 8d1c401 + 0eef1b1 commit 0191f41

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/openapi/validation.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def 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

2525
def 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())

0 commit comments

Comments
 (0)