Docs Module API Reference¶
This section documents the internals of the docs
module in Bijux CLI.
bijux_cli.services.docs ¶
Provides the concrete implementation of the API specification writing service.
This module defines the Docs
class, which implements the DocsProtocol
. It is responsible for serializing API specification data into formats like JSON or YAML and writing the resulting documents to the filesystem. It integrates with observability and telemetry services to log its activities.
Docs ¶
Docs(
observability: ObservabilityProtocol,
telemetry: TelemetryProtocol,
root: str | Path | None = None,
)
Bases: DocsProtocol
A service for writing API specification documents to disk.
This class implements the DocsProtocol
to handle the serialization and writing of specifications (e.g., OpenAPI, JSON Schema) to files. It maintains a cache of serializer instances for performance.
Attributes:
-
_serializers
(WeakKeyDictionary
) –A cache of serializer instances, keyed by the telemetry service instance.
-
_observability
(ObservabilityProtocol
) –The logging service.
-
_telemetry
(TelemetryProtocol
) –The telemetry service for event tracking.
-
_root
(Path
) –The root directory where documents will be written.
Initializes the Docs
service.
Parameters:
-
observability
(ObservabilityProtocol
) –The service for logging.
-
telemetry
(TelemetryProtocol
) –The service for event tracking.
-
root
(str | Path | None
, default:None
) –The root directory for writing documents. It defaults to the
BIJUXCLI_DOCS_DIR
environment variable, or "docs" if not set.
Source code in src/bijux_cli/services/docs.py
close ¶
render ¶
render(spec: dict[str, Any], *, fmt: OutputFormat) -> str
Renders a specification dictionary to a string in the given format.
Parameters:
-
spec
(dict[str, Any]
) –The specification dictionary to serialize.
-
fmt
(OutputFormat
) –The desired output format (e.g., JSON, YAML).
Returns:
-
str
(str
) –The serialized specification as a string.
Raises:
-
TypeError
–If the underlying serializer returns a non-string result.
Source code in src/bijux_cli/services/docs.py
write ¶
write(
spec: dict[str, Any],
*,
fmt: OutputFormat = JSON,
name: str = "spec",
) -> str
Writes a specification to a file and returns the path as a string.
This is a convenience wrapper around write_sync
.
Parameters:
-
spec
(dict[str, Any]
) –The specification dictionary to write.
-
fmt
(OutputFormat
, default:JSON
) –The output format. Defaults to
OutputFormat.JSON
. -
name
(str
, default:'spec'
) –The base name for the output file. Defaults to 'spec'.
Returns:
-
str
(str
) –The absolute path to the written file.
Source code in src/bijux_cli/services/docs.py
write_sync ¶
write_sync(
spec: dict[str, Any],
fmt: OutputFormat,
name: str | Path,
) -> Path
Writes the specification to a file synchronously.
This method handles path resolution, serializes the spec
dictionary, and writes the content to the final destination file.
Parameters:
-
spec
(dict[str, Any]
) –The specification dictionary to write.
-
fmt
(OutputFormat
) –The desired output format.
-
name
(str | Path
) –The path or base name for the output file.
Returns:
-
Path
(Path
) –The
Path
object pointing to the written file.
Raises:
-
ServiceError
–If writing to the file fails due to an
OSError
.