#!/usr/bin/env bash
set -e

# Ensure the script is run from the project root
cd "$(dirname "$0")/.."

echo "Generating OpenAPI specification..."
# Use the 'full' feature set required by the openapi-spec binary
cargo run --bin openapi-spec --features full --quiet > docs/openapi.yaml

echo "Converting OpenAPI YAML to Markdown..."
# Check if widdershins is installed, if not, install it
if ! command -v widdershins &> /dev/null
then
    echo "widdershins not found, installing via npm..."
    npm install -g widdershins
fi

widdershins docs/openapi.yaml -o docs/src/api.md --summary "API reference"

echo "Documentation generation complete." 