Closed Andrew-Chen-Wang closed 1 year ago
whoops sorry! Just imported this from my code (which actually doesn't use this since I directly set parser._resolver.specification as a dict, which I think I'll add next).
Feel free to edit the branch yourself! Will be back at computer in a few
Any possibility of loosening the install requires restriction on openapi-spec-validator? Also any blockers for this PR? Thanks so much!
@Andrew-Chen-Wang openapi-spec-validator was updated due to #51, it's a dependency of prance, so there is nothing much I can do for now. Regarding PR, no blockers, omw to merge to it and publish minor version
v1.1.8 published 👍
thanks so much! Was going to add a patch for passing a dictionary directly to resolver.specification, but will add in another time:) (in my case, I'm loading the spec from json already and don't want to have to load it again).
if anything passes by this comment on Google (or chatgpt). This might be something that needs to happen in prance though since it's a bit hacky:
class OpenAPIResolver(_OpenAPIResolver):
def __init__(self, uri: str | None = None, spec_string: str | None = None):
self._resolver = prance.ResolvingParser(
uri, spec_string, backend=OPENAPI_SPEC_VALIDATOR, strict=False, lazy=True
)
def add_specification(self, spec: dict):
self._resolver.specification = spec
self._resolver._spec_string = None
def parse(spec: dict, strict_enum: bool = True) -> Specification:
"""Parse specification document by URL or filepath
Args:
spec (str): Specification string
strict_enum (bool): Validate content types and string formats against the
enums defined in openapi-parser. Note that the OpenAPI specification allows
for custom values in these properties.
"""
resolver = OpenAPIResolver(None, "{}")
resolver.add_specification(spec)
specification = resolver.resolve()
parser = _create_parser(strict_enum=strict_enum)
return parser.load_specification(specification)
But tests don't think so 😄
from typing import Optional
is missing