Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ docs_index(
srcs = [
"@rules_docs_e2e_git_last_updated//:docs",
"@rules_docs_e2e_smoke//:docs",
"@rules_docs_examples_swagger//:docs",
"@rules_docs_examples_typescript//:index",
],
nav = {
"@rules_docs_e2e_smoke//:docs": "e2e/smoke",
"@rules_docs_e2e_git_last_updated//:docs": "e2e/git_last_updated",
"@rules_docs_examples_swagger//:docs": "examples/swagger",
"@rules_docs_examples_typescript//:index": "examples/typescript",
},
title = "examples",
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ use_repo(multitool, "multitool")
NESTED_MODULES = [
"e2e/git_last_updated",
"e2e/smoke",
"examples/swagger",
"examples/typescript",
]

[
[
bazel_dep(name = "rules_docs_%s" % escaped_folder, version = "0.0.0", dev_dependency = True),
Expand Down
53 changes: 53 additions & 0 deletions examples/swagger/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

load("@rules_docs//docgen:defs.bzl", "docs")
load("@mkdocs//:defs.bzl", "mkdocs_build", "mkdocs_config", "mkdocs_serve")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")

compile_pip_requirements(
name = "requirements",
src = "pyproject.toml",
requirements_txt = "requirements.txt",
)

docs(
name = "other_docs",
entry = "api-reference.md",
data = ["openapi.yaml"],
readme_content = "API Reference",
)

# Main documentation configuration
docs(
name = "docs",
nav = {
"README.md": "Home",
":other_docs": "API Reference (Redoc)",
},
rewrite_path = "examples/swagger",
visibility = ["//visibility:public"],
)

# Generate mkdocs configuration
mkdocs_config(
name = "mkdocs_config",
docs = ":docs",
mkdocs_base = "mkdocs.tpl.yaml",
)

# Build documentation site
mkdocs_build(
name = "mkdocs",
config = ":mkdocs_config",
docs = [":docs"],
site_dir = "site",
visibility = ["//visibility:public"],
)

# Serve documentation locally for development
# Recommended: run with ibazel for auto-reload on changes
mkdocs_serve(
name = "mkdocs.serve",
config = ":mkdocs_config",
docs = [":docs"],
visibility = ["//visibility:public"],
)
24 changes: 24 additions & 0 deletions examples/swagger/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module(name = "rules_docs_examples_swagger")

bazel_dep(name = "rules_docs")

local_path_override(
module_name = "rules_docs",
path = "../..",
)

bazel_dep(name = "rules_python", version = "1.7.0")

# Configure Python and pip dependencies
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "mkdocs_deps",
python_version = "3.11",
requirements_lock = "//:requirements.txt",
)
use_repo(pip, "mkdocs_deps")

# Configure docgen with mkdocs plugins
docgen = use_extension("@rules_docs//docgen:extensions.bzl", "docgen")
docgen.mkdocs(plugins = ["mkdocs-redoc-tag"], pypi_hub = "@mkdocs_deps")
use_repo(docgen, "mkdocs")
505 changes: 505 additions & 0 deletions examples/swagger/MODULE.bazel.lock

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions examples/swagger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Swagger/OpenAPI Example

This directory contains an OpenAPI 3.0 specification file that demonstrates rich API documentation suitable for use with SwaggerUI.
We then run Bazel actions to run the docgen tool and stitch into the parent repository's documentation site.

## Files

- `openapi.yaml` - Complete OpenAPI 3.0 specification for a Task Management API

## Features Demonstrated

The OpenAPI specification includes:

- **Comprehensive API Documentation**: Rich descriptions for all endpoints, parameters, and schemas
- **Multiple Endpoints**: CRUD operations for tasks, projects, and users
- **Request/Response Examples**: Multiple examples for different use cases
- **Detailed Schemas**: Well-documented data models with validation rules
- **Error Responses**: Standardized error response formats
- **Authentication**: Bearer token authentication scheme
- **Pagination**: Pagination support for list endpoints
- **Filtering & Sorting**: Query parameters for filtering and sorting results

## Viewing with SwaggerUI

Run `bazel run mkdocs.serve`

Then open http://localhost:8080

## API Overview

The Task Management API provides:

- **Tasks**: Create, read, update, and delete tasks with status, priority, assignments, and due dates
- **Projects**: Organize tasks into projects
- **Users**: Manage users who can be assigned to tasks

All endpoints require Bearer token authentication and return JSON responses.
1 change: 1 addition & 0 deletions examples/swagger/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<redoc src="./openapi.yaml"></redoc>
6 changes: 6 additions & 0 deletions examples/swagger/mkdocs.tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
site_name: Swagger Example
repo_url: https://github.com/jacobshirley/rules_docs/tree/main/examples/swagger
docs_dir: docs
site_dir: site
plugins:
- redoc-tag
Loading
Loading