From db740c8888bd4e14a04d373db6811a29c487f7b3 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 | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 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..53e9de4 100644 --- a/asynction/server.py +++ b/asynction/server.py @@ -68,13 +68,15 @@ 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 = yaml.safe_load(serialized) + else: + spec = spec_path + + raw_resolved = resolve_references(spec) return AsyncApiSpec.from_dict(raw_resolved) @@ -126,7 +128,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 +159,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 (