Repository navigation
feat(cli): distinguish YAML parse vs AsyncAPI validation errors, add pluggable parser - #2858
SarthakB11 wants to merge 8 commits into
Conversation
…to OSError/ValueError
…tighten hint copy
…edefinition warning
|
Thank you for the contribution. I do not think we should merge this PR in its current form. The PR tries to address YAML parsing and validation diagnostics, but it also introduces a new public CLI option, a pluggable YAML parser registry, support for arbitrary The most important concern is that The There is also a mismatch between the stated intent and the implementation. The new module says that PyYAML is the default, while I think the useful part of this PR is the idea of improving diagnostics when a YAML schema parses successfully but fails AsyncAPI validation. That should be handled as a smaller, focused change: preserve the existing YAML parser behavior, surface clearer validation errors, add a regression test for the concrete failure case, and avoid introducing a new parser plugin API. For now, I would prefer to close this PR rather than merge it. If we still want to improve the error message for invalid YAML-based AsyncAPI documents, I would be open to a smaller PR limited to that behavior, with deterministic parsing and regression tests. Thanks again for working on this. |
Description
faststream docs servecurrently fails with the same opaque "asyncapi.yamlnot supported. Make sure that your schema is valid and schema version supported by FastStream" message regardless of whether the YAML failed to parse, the document validates against neither AsyncAPI version, orPyYAMLproduced a typed value the schema rejects (the unquoted-scalar quirk #2709 calls out).This PR splits those into three distinct error paths and exposes a parser hook so users can swap the loader without touching FastStream.
Changes
faststream/_internal/cli/utils/yaml_parsers.py(new) —get_yaml_parserregistry exposingauto,pyyaml,ruamel, andmodule:callableresolution. Mirrorsimports.py'simport_from_stringstyle and reuses it for the dotted-path case. RaisesSetupErrorso callers stay decoupled from the CLI.faststream/_internal/cli/docs.py— uses the registry on the YAML branch; capturesValidationErrorper AsyncAPI version and surfaces them after the existing "not supported" line; emits a hint when the validation errors look like a YAML-resolved scalar landing in a string field; catches parser-side exceptions with a clear "Failed to parse" message instead of an unhandled traceback.faststream/_internal/cli/dto.py— adds theyaml_parserfield onRunArgsso the value flows through the reload supervisor.--yaml-parseroption onfaststream docs serve(typer auto-renders this into--helpand the docs site).Note on the unquoted-scalar case
I dug into the specific
! '3.2'example in the issue body. Every standard YAML 1.2 mode (PyYAML default,ruamel.yaml(typ='safe'),ruamel.yaml(typ='rt')) resolves3.2tofloat; onlytyp='base'keeps it as a string, but that mode also strings every other value (booleans, ints) which the rest of the schema needs. So shipping a different default parser does not, on its own, make AsyncAPI Studio-style YAML validate. The hint in the first example tells the user to quote the value or use the JSON file Studio also exports. A schema-level coercion that acceptsint|float|strforprotocolVersionwould be the bigger win and is worth a separate design discussion.Fixes #2709.
Type of change
Checklist
just lintequivalents —ruff check,ruff format,codespell— all clean on touched files)--yaml-parserflag is exposed via typer's auto-generated--help, which feeds the docs site)tests/cli/test_yaml_parsers.pyandtests/cli/test_asyncapi_docs.py— 6 unit, 5 in-process integration viaCliRunner, 1 slow e2e via thefaststream_clisubprocess fixture against a real docs server)just static-analysisequivalent —mypy— clean on the touched non-test files)