-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow pre loaded AsyncAPISpec in from_spec #160
Changes from 6 commits
daf3cf0
616d983
593a0b6
2350ab6
e012e03
cacffc9
db740c8
13bc049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||||||||||
from typing import Any | ||||||||||||||
from typing import Optional | ||||||||||||||
from typing import Sequence | ||||||||||||||
from typing import Union | ||||||||||||||
from urllib.parse import urlparse | ||||||||||||||
|
||||||||||||||
import jsonschema | ||||||||||||||
|
@@ -113,7 +114,7 @@ def init_app(self, app: Optional[Flask], **kwargs) -> None: | |||||||||||||
@classmethod | ||||||||||||||
def from_spec( | ||||||||||||||
cls, | ||||||||||||||
spec_path: Path, | ||||||||||||||
spec_path: Union[Path, JSONMapping], | ||||||||||||||
validation: bool = True, | ||||||||||||||
server_name: Optional[str] = None, | ||||||||||||||
docs: bool = True, | ||||||||||||||
|
@@ -124,7 +125,8 @@ def from_spec( | |||||||||||||
"""Create a Flask-SocketIO server from an AsyncAPI spec. | ||||||||||||||
This is the single entrypoint to the Asynction server API. | ||||||||||||||
|
||||||||||||||
:param spec_path: The path where the AsyncAPI YAML specification is located. | ||||||||||||||
:param spec_path: The path where the AsyncAPI YAML specification is located, | ||||||||||||||
or a pre loaded JSONMapping object. | ||||||||||||||
:param validation: When set to ``False``, message payloads, channel | ||||||||||||||
bindings and ack callbacks are NOT validated. | ||||||||||||||
Defaults to ``True``. | ||||||||||||||
|
@@ -155,7 +157,12 @@ def from_spec( | |||||||||||||
) | ||||||||||||||
|
||||||||||||||
""" | ||||||||||||||
spec = load_spec(spec_path=spec_path) | ||||||||||||||
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) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be neater if we could move this logic within the existing def load_spec(raw_spec: Union[Path, JSONMapping]) -> AsyncApiSpec:
if isinstance(spec, Path):
with open(spec_path) as f:
serialized = f.read()
raw_spec = yaml.safe_load(serialized)
raw_resolved = resolve_references(raw_spec)
return AsyncApiSpec.from_dict(raw_resolved) Note that here, in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above line in the
Suggested change
|
||||||||||||||
|
||||||||||||||
server_security: Sequence[SecurityRequirement] = [] | ||||||||||||||
if ( | ||||||||||||||
server_name is not None | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.