Skip to content

Commit deaa1e8

Browse files
Wim-De-Clercqp1c2u
authored andcommitted
Use the json module to take care of the integer keys.
This change allows the yaml loading to use the original yaml loaders which are much faster. Issue #145
1 parent fae097a commit deaa1e8

File tree

4 files changed

+18
-44
lines changed

4 files changed

+18
-44
lines changed

openapi_spec_validator/constructors.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

openapi_spec_validator/handlers/file.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
"""OpenAPI spec validator handlers file module."""
22
import io
3+
import json
4+
35
from yaml import load
46

57
from openapi_spec_validator.handlers.base import BaseHandler
68
from openapi_spec_validator.handlers.utils import uri_to_path
7-
from openapi_spec_validator.loaders import ExtendedSafeLoader
9+
10+
try:
11+
from yaml import CSafeLoader as SafeLoader
12+
except ImportError:
13+
from yaml import SafeLoader
814

915

1016
class FileObjectHandler(BaseHandler):
1117
"""OpenAPI spec validator file-like object handler."""
1218

13-
def __init__(self, loader=ExtendedSafeLoader):
19+
def __init__(self, loader=SafeLoader):
1420
self.loader = loader
1521

1622
def __call__(self, f):
17-
return load(f, self.loader)
23+
return json.loads(json.dumps(load(f, self.loader)))
1824

1925

2026
class FileHandler(FileObjectHandler):

openapi_spec_validator/loaders.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

openapi_spec_validator/schemas.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""OpenAIP spec validator schemas module."""
2+
import json
23
import os
3-
44
import urllib.parse
55
import urllib.request
6-
from yaml import load
76

87
import importlib_resources
9-
from openapi_spec_validator.loaders import ExtendedSafeLoader
8+
from yaml import load
9+
10+
try:
11+
from yaml import CSafeLoader as SafeLoader
12+
except ImportError:
13+
from yaml import SafeLoader
1014

1115

1216
def get_openapi_schema(version):
@@ -19,7 +23,7 @@ def get_openapi_schema(version):
1923
return schema, schema_url
2024

2125

22-
def read_yaml_file(path, loader=ExtendedSafeLoader):
26+
def read_yaml_file(path, loader=SafeLoader):
2327
"""Open a file, read it and return its contents."""
2428
with open(path) as fh:
25-
return load(fh, loader)
29+
return json.loads(json.dumps(load(fh, loader)))

0 commit comments

Comments
 (0)