gen(
app: str = typer.Argument(
...,
help="[python_module:FastStream] - path to your application",
),
yaml: bool = typer.Option(
False,
"--yaml",
is_flag=True,
help="generate `asyncapi.yaml` schema",
),
out: Optional[str] = typer.Option(
None, help="output filename"
),
) -> None
Generate project AsyncAPI schema
Source code in faststream/cli/docs/app.py
| @docs_app.command(name="gen")
def gen(
app: str = typer.Argument(
...,
help="[python_module:FastStream] - path to your application",
),
yaml: bool = typer.Option(
False,
"--yaml",
is_flag=True,
help="generate `asyncapi.yaml` schema",
),
out: Optional[str] = typer.Option(
None,
help="output filename",
),
) -> None:
"""Generate project AsyncAPI schema"""
_, app_obj = import_from_string(app)
raw_schema = get_app_schema(app_obj)
if yaml:
try:
schema = raw_schema.to_yaml()
except ImportError as e: # pragma: no cover
typer.echo(INSTALL_YAML, err=True)
raise typer.Exit(1) from e
name = out or "asyncapi.yaml"
with open(name, "w") as f:
f.write(schema)
else:
schema = raw_schema.to_jsonable()
name = out or "asyncapi.json"
with open(name, "w") as f:
json.dump(schema, f, indent=2)
typer.echo(f"Your project AsyncAPI scheme was placed to `{name}`")
|