Skip to content

Commit dadcd72

Browse files
authored
Merge pull request #54 from Andrew-Chen-Wang/andrew-wang/pass-string
Allow passing string to load spec
2 parents 0daf5e6 + 0da904c commit dadcd72

File tree

4 files changed

+57
-57
lines changed

4 files changed

+57
-57
lines changed

Pipfile.lock

Lines changed: 44 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
],
3535
install_requires=[
3636
"prance>=0.20.2",
37-
"openapi-spec-validator>=0.2.9,<0.5.0",
37+
"openapi-spec-validator==0.5.5",
3838
],
3939
)

src/openapi_parser/parser.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Optional
23

34
from .builders import *
45
from .builders.common import extract_typed_props, PropertyMeta
@@ -109,16 +110,21 @@ def _create_parser(strict_enum: bool = True) -> Parser:
109110
schemas_builder)
110111

111112

112-
def parse(uri: str, strict_enum: bool = True) -> Specification:
113-
"""Parse specification document by URL or filepath
113+
def parse(
114+
uri: Optional[str] = None,
115+
spec_string: Optional[str] = None,
116+
strict_enum: bool = True
117+
) -> Specification:
118+
"""Parse specification document by URL/filepath or as a string.
114119
115120
Args:
116121
uri (str): Path or URL to OpenAPI file
122+
spec_string (str): OpenAPI specification as a string to parse
117123
strict_enum (bool): Validate content types and string formats against the
118124
enums defined in openapi-parser. Note that the OpenAPI specification allows
119125
for custom values in these properties.
120126
"""
121-
resolver = OpenAPIResolver(uri)
127+
resolver = OpenAPIResolver(uri, spec_string)
122128
specification = resolver.resolve()
123129

124130
parser = _create_parser(strict_enum=strict_enum)

src/openapi_parser/resolver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Optional
23

34
import prance
45

@@ -12,9 +13,10 @@
1213
class OpenAPIResolver:
1314
_resolver: prance.ResolvingParser
1415

15-
def __init__(self, uri: str) -> None:
16+
def __init__(self, uri: Optional[str], spec_string: Optional[str] = None) -> None:
1617
self._resolver = prance.ResolvingParser(
1718
uri,
19+
spec_string=spec_string,
1820
backend=OPENAPI_SPEC_VALIDATOR,
1921
strict=False,
2022
lazy=True

0 commit comments

Comments
 (0)