Skip to content

Commit

Permalink
Add AsyncAPI schema serving with cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
voro6yov committed Mar 27, 2024
1 parent b001e98 commit fe8fcdf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ format: .pdm

.PHONY: lint ## Lint python source files
lint: .pdm
pdm run ruff $(sources)
pdm run ruff check $(sources)
pdm run ruff format --check $(sources)

.PHONY: codespell ## Use Codespell to do spellchecking
Expand Down
108 changes: 10 additions & 98 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "message-flow"
version = "0.3.3"
version = "0.3.4"
description = "Asynchronous Communication Framework"
authors = [
{name = "Valentin Vorobyev", email = "[email protected]"},
Expand Down
5 changes: 4 additions & 1 deletion src/message_flow/cli/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CLIApp:
},
)

def __init__(self, app_path: str, log_level: LoggingLevel) -> None:
def __init__(self, app_path: str, log_level: LoggingLevel = LoggingLevel.INFO) -> None:
self.app_path = app_path

self.instance.set_logging_level(self.LOGGING_LEVELS[log_level])
Expand Down Expand Up @@ -77,6 +77,9 @@ def instance(self) -> MessageFlow:
def dispatch(self) -> None:
self.instance.dispatch()

def make_async_api_schema(self) -> str:
return self.instance.make_async_api_schema()

def _import(self) -> MessageFlow:
spec = spec_from_file_location(
"mode",
Expand Down
26 changes: 25 additions & 1 deletion src/message_flow/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typer

from .async_api_schema import serve_schema
from .cli_app import CLIApp
from .logging_level import LoggingLevel

Expand Down Expand Up @@ -29,8 +30,31 @@ def dispatch(
),
):
"""
Shoot the portal gun
Starts message dispatching
"""
cli_app = CLIApp(app, log_level)

cli_app.dispatch()


@cli.command()
def docs(
app: str = typer.Argument(
...,
help="[python_module:MessageFlow] - path to your application",
),
host: str = typer.Option(
"localhost",
help="documentation hosting address",
),
port: int = typer.Option(
8000,
help="documentation hosting port",
),
):
"""
Starts Async API schema serving
"""
cli_app = CLIApp(app)

serve_schema(schema=cli_app.make_async_api_schema(), host=host, port=port)

0 comments on commit fe8fcdf

Please sign in to comment.