-
Notifications
You must be signed in to change notification settings - Fork 310
Description
Description
Starting with v0.6.0 faststream supports AsyncAPI 3.0.
The AsyncAPI 3.0 documentation states:
In order to preserve the ability to round-trip between YAML and JSON formats, YAML version 1.2 is recommended along with some additional constraints:
- Tags MUST be limited to those allowed by the JSON Schema ruleset
- Keys used in YAML maps MUST be limited to a scalar string, as defined by the YAML Failsafe schema ruleset
Note: AsyncAPI use js-yaml as parser, *js-yaml playground
According to spec, yaml of the following type:
protocolVersion: ! "3.2"should be converted to {protocolVersion: "3.2"}, i.e. to a string, but PyYAML converts it to an float:
import yaml
y = "protocolVersion: ! '3.2'"
print(yaml.safe_load(y)) # {'protocolVersion': 3.2}
print(type(yaml.safe_load(y)["protocolVersion"])) # <class 'float'>faststream/faststream/_internal/cli/utils/logs.py
Lines 97 to 106 in 6050ba3
| def _get_yaml_config(file: Path) -> dict[str, Any] | Any: | |
| """Parse yaml config file to dict.""" | |
| try: | |
| import yaml | |
| except ImportError as e: | |
| typer.echo(INSTALL_YAML, err=True) | |
| raise typer.Exit(1) from e | |
| with file.open("r", encoding="utf-8") as config_file: | |
| return yaml.safe_load(config_file) |
(Also, PyYAML does not fully support YAML v1.2.* and does not pass the official yaml-test-suite).
Valid AsyncAPI config: https://studio.asyncapi.com/?share=851921b7-91cd-414c-9438-e94876953c0d
but faststream cannot load it
❯ faststream docs serve asyncapi.yaml
`asyncapi.yaml` not supported. Make sure that your schema is valid and schema version supported by FastStreamProposal: make it plug-able so that the user can use any parser through the interface.
(Also we need improve error message; right now it's unclear. It needs to clearly show whether it's a parsing error or a pydantic validation error.)