Source code for betty.extension.http_api_doc

"""Integrate Betty with `ReDoc <https://redocly.com/redoc/>`_."""

from __future__ import annotations

from pathlib import Path

from typing_extensions import override

from betty.app.extension import Extension, UserFacingExtension
from betty.extension.webpack import Webpack, WebpackEntryPointProvider
from betty.locale import Str, Localizable
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from collections.abc import Sequence


[docs] class HttpApiDoc(UserFacingExtension, WebpackEntryPointProvider): """ Provide user-friendly HTTP API documentation. """
[docs] @override @classmethod def name(cls) -> str: return "betty.extension.HttpApiDoc"
[docs] @override @classmethod def depends_on(cls) -> set[type[Extension]]: return {Webpack}
[docs] @override @classmethod def assets_directory_path(cls) -> Path: return Path(__file__).parent / "assets"
[docs] @override @classmethod def webpack_entry_point_directory_path(cls) -> Path: return Path(__file__).parent / "webpack"
[docs] @override def webpack_entry_point_cache_keys(self) -> Sequence[str]: return ()
[docs] @override @classmethod def label(cls) -> Localizable: return Str._("HTTP API Documentation")
[docs] @override @classmethod def description(cls) -> Localizable: return Str._( 'Display the HTTP API documentation in a user-friendly way using <a href="https://github.com/Redocly/redoc">ReDoc</a>.' )