Skip to content

Commit

Permalink
Merge pull request #460 from sbrunner/yaml
Browse files Browse the repository at this point in the history
Support schema file in yaml
  • Loading branch information
sbrunner authored May 5, 2023
2 parents eab029a + 4aa8612 commit 70a1b38
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jsonschema_gentypes/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Any, Dict, List, Optional, Union, cast

import requests
import yaml
from referencing import Registry, Resource

from jsonschema_gentypes import (
Expand Down Expand Up @@ -59,13 +60,18 @@ def _open_uri(
)
else:
with open(uri, encoding="utf-8") as open_file:
file_content = open_file.read()
try:
schema = yaml.load(file_content, Loader=yaml.SafeLoader)
except Exception: # pylint: disable=broad-except
schema = json.loads(file_content)
return _openapi_schema(
cast(
Union[
jsonschema_draft_06.JSONSchemaItemD6,
jsonschema_draft_2020_12_applicator.JSONSchemaItemD2020,
],
json.load(open_file),
schema,
)
)

Expand Down

0 comments on commit 70a1b38

Please sign in to comment.