From 97be7120fb75763fa8d2af3f30798fd53c848a35 Mon Sep 17 00:00:00 2001 From: Alex Zywicki Date: Wed, 19 Jan 2022 13:01:40 -0600 Subject: [PATCH] Handle review items --- asynction/mock_server.py | 2 +- asynction/server.py | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/asynction/mock_server.py b/asynction/mock_server.py index 2a65d7e..0e69e58 100644 --- a/asynction/mock_server.py +++ b/asynction/mock_server.py @@ -162,7 +162,7 @@ def from_spec( * ``custom_formats_sample_size`` :param spec_path: The path where the AsyncAPI YAML specification is located, - or a pre loaded JSONMapping object. + or a dictionary object of the AsyncAPI data structure :param validation: When set to ``False``, message payloads, channel bindings and ack callbacks are NOT validated. Defaults to ``True``. diff --git a/asynction/server.py b/asynction/server.py index d7197f6..47b012d 100644 --- a/asynction/server.py +++ b/asynction/server.py @@ -68,13 +68,13 @@ def resolve_references(raw_spec: JSONMapping) -> JSONMapping: return deep_resolve(raw_spec, resolver) -def load_spec(spec_path: Path) -> AsyncApiSpec: - with open(spec_path) as f: - serialized = f.read() - raw = yaml.safe_load(serialized) - - raw_resolved = resolve_references(raw_spec=raw) +def load_spec(spec_path: Union[Path, JSONMapping]) -> AsyncApiSpec: + if isinstance(spec_path, Path): + with open(spec_path) as f: + serialized = f.read() + spec_path = yaml.safe_load(serialized) + raw_resolved = resolve_references(spec_path) return AsyncApiSpec.from_dict(raw_resolved) @@ -126,7 +126,7 @@ def from_spec( This is the single entrypoint to the Asynction server API. :param spec_path: The path where the AsyncAPI YAML specification is located, - or a pre loaded JSONMapping object. + or a dictionary object of the AsyncAPI data structure :param validation: When set to ``False``, message payloads, channel bindings and ack callbacks are NOT validated. Defaults to ``True``. @@ -157,11 +157,7 @@ def from_spec( ) """ - if isinstance(spec_path, Path): - spec = load_spec(spec_path=spec_path) - else: - raw_resolved = resolve_references(raw_spec=spec_path) - spec = AsyncApiSpec.from_dict(raw_resolved) + spec = load_spec(spec_path=spec_path) server_security: Sequence[SecurityRequirement] = [] if (