all2md.parsers.openapi
OpenAPI/Swagger to AST converter.
This module provides conversion from OpenAPI/Swagger specification documents to AST representation. Supports OpenAPI 3.x and Swagger 2.0 formats.
- class all2md.parsers.openapi.OpenApiParser
Bases:
BaseParserConvert OpenAPI/Swagger specifications to AST representation.
This parser handles OpenAPI 3.x and Swagger 2.0 specification formats, converting them into structured markdown-ready AST.
- Parameters:
options (OpenApiParserOptions or None) – Parser configuration options
progress_callback (ProgressCallback or None) – Optional callback for progress updates
Examples
- Parse OpenAPI spec:
>>> parser = OpenApiParser() >>> doc = parser.parse("openapi.yaml")
- With custom options:
>>> options = OpenApiParserOptions(group_by_tag=False) >>> parser = OpenApiParser(options) >>> doc = parser.parse("swagger.json")
Initialize the OpenAPI parser with options and progress callback.
- __init__(options: OpenApiParserOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)
Initialize the OpenAPI parser with options and progress callback.
- parse(input_data: str | Path | IO[bytes] | bytes) Document
Parse OpenAPI/Swagger specification into an AST.
- Parameters:
input_data (str, Path, IO[bytes], or bytes) – The input OpenAPI specification to parse
- Returns:
AST Document node representing the parsed API specification
- Return type:
- Raises:
ParsingError – If parsing fails due to invalid format or structure
- extract_metadata(document: Any) DocumentMetadata
Extract metadata from OpenAPI specification.
- Parameters:
document (dict) – Parsed OpenAPI specification
- Returns:
Extracted metadata
- Return type: