Plan: OpenAPI / Swagger Documentation
- Status
- Context
- Scope
- Design
- Steps
- Step 1: Add
ToSchemaderives to all domain types - Step 2: Annotate canopy-persons (13 routes)
- Step 3: Annotate canopy-applications (8 routes)
- Step 4: Annotate canopy-rules (7 routes)
- Step 5: Annotate canopy-eligibility (4 routes)
- Step 6: Annotate canopy-snap (10 routes)
- Step 7: Annotate canopy-appeals (19 routes)
- Step 8: Annotate canopy-enrollment (6 routes)
- Step 9: Annotate canopy-renewals (7 routes)
- Step 10: Annotate canopy-notices (6 routes)
- Step 11: Annotate canopy-reporting (6 routes)
- Step 12: Annotate canopy-security (7 routes)
- Step 13: Wire
OpenApidoc into each service’s main.rs - Step 14: Tests and validation
- Step 1: Add
- Files Touched
- Verification
- Documentation Updates
Status
| Step | Description | Status |
|---|---|---|
1 |
Add |
Done (2026-04-05) |
2 |
Add |
Done (2026-04-05) |
3 |
Add |
Done (2026-04-05) |
4 |
Add |
Done (2026-04-05) |
5 |
Add |
Done (2026-04-05) |
6 |
Add |
Done (2026-04-05) |
7 |
Add |
Done (2026-04-05) |
8 |
Add |
Done (2026-04-05) |
9 |
Add |
Done (2026-04-05) |
10 |
Add |
Done (2026-04-05) |
11 |
Add |
Done (2026-04-05) |
12 |
Add |
Done (2026-04-05) |
13 |
Wire |
Done (2026-04-05) |
14 |
Tests and validation |
Done (2026-04-05) |
Epic: &38
Issues: TBD
Branch: chore/openapi-swagger
Labels: type::chore, priority::medium, program::infrastructure, service::shared-crates
Context
Every service in Canopy already depends on utoipa and utoipa-swagger-ui (workspace dependencies).
The shared canopy-api crate already:
-
Accepts an
Option<utoipa::openapi::OpenApi>inApiServer::router() -
Mounts
SwaggerUi::new("/swagger-ui")when a doc is provided -
Registers a Bearer JWT security scheme via
SecurityAddon
But every service passes None for api_doc.
Zero endpoints have #[utoipa::path] annotations.
Zero domain types derive ToSchema.
The result: no service exposes API documentation. Developers, integrators, and the documentation-completeness plan (Step 2) all depend on having machine-readable API specs. The Swagger UI also provides an interactive test harness for each endpoint, which is valuable during UAT.
This is entirely mechanical work — adding derive macros and annotations — with no behavioral change to any endpoint.
Scope
In scope:
-
ToSchemaderives on all request/response structs and enums used in API handlers (~60 types) -
#[utoipa::path]annotations on all 87 domain routes across 11 JSON API services -
[derive(OpenApi)]with[openapi(paths(…), components(schemas(…)))]in each service’s API module -
Passing the generated
OpenApidoc toApiServer::router()in each service’smain.rs -
Bearer JWT security requirement on all authenticated endpoints
-
Tag grouping per service (e.g., "Persons", "Households", "Income", "Assets")
Out of scope:
-
canopy-web (HTML BFF, not a JSON API — Swagger is not meaningful)
-
canopy-portal (no domain routes yet)
-
Stub services (canopy-tanf, canopy-medicaid, canopy-caps, canopy-wic, canopy-exchange — only have healthz)
-
Custom response examples (added in documentation-completeness plan Step 2)
-
cargo xtask api-docscommand (documentation-completeness plan Step 2)
Design
Annotation Pattern
Each handler gets a #[utoipa::path] attribute directly above the function.
Pattern for a typical CRUD endpoint:
#[utoipa::path(
post,
path = "/v1/persons",
tag = "Persons",
request_body = CreatePerson,
responses(
(status = 201, description = "Person created", body = Person),
(status = 400, description = "Invalid request"),
(status = 401, description = "Unauthorized"),
),
security(("bearer" = []))
)]
async fn create_person(...) -> ... { ... }
ToSchema Derives
All structs that appear in request_body or responses(body = …) need #[derive(utoipa::ToSchema)].
Most already derive Serialize and/or Deserialize, so adding ToSchema is a single derive addition.
For types using sqlx::Type enums (like canopy-reference enums), use #[schema(value_type = String)] to tell utoipa to treat them as strings in the schema.
For serde_json::Value fields (like report_data), use #[schema(value_type = Object)].
For Decimal fields, use #[schema(value_type = String)] since they serialize as strings.
OpenApi Document Assembly
Each service’s API module gets a #[derive(OpenApi)] struct:
use utoipa::OpenApi;
#[derive(OpenApi)]
#[openapi(
info(
title = "canopy-persons",
version = "1.0.0",
description = "Persons and household management"
),
paths(
create_person,
list_persons,
get_person,
update_person,
delete_person,
// ... all routes
),
components(schemas(
Person,
CreatePerson,
UpdatePerson,
// ... all types
)),
modifiers(&canopy_api::SecurityAddon),
tags(
(name = "Persons", description = "Person CRUD"),
(name = "Households", description = "Household management"),
)
)]
pub struct ApiDoc;
Steps
Step 1: Add ToSchema derives to all domain types
Files: All domain.rs and store/models.rs files across services, crates/canopy-reference/src/lib.rs, crates/canopy-common/src/error.rs
Add #[derive(utoipa::ToSchema)] to every struct and enum that appears in API request or response bodies.
Services and their type files:
-
services/canopy-persons/src/store/models.rs— Person, CreatePerson, UpdatePerson, Household, CreateHousehold, HouseholdMember, AddMember, Income, CreateIncome, Asset, CreateAsset, Expense, CreateExpense, Address, CreateAddress, HouseholdWithMembers -
services/canopy-applications/src/domain.rs— Application, ApplicationProgram, CreateApplicationRequest, ExpeditedScreeningData, ApplicationWithPrograms -
services/canopy-eligibility/src/store/models.rs— EligibilityRequest, ProgramDetermination, CombinedResult -
services/canopy-snap/src/store/models.rs— SnapApplication, SnapDetermination, IevsVerificationRecord -
services/canopy-appeals/src/domain.rs— AppealRequest, AppealTimelineEvent, FileAppealRequest, ScheduleHearingRequest, RecordDecisionRequest, AppealWithTimeline -
services/canopy-appeals/src/ipv/domain.rs— IpvCase, IpvTimelineEvent, CreateIpvReferralRequest, ScheduleAdhRequest, RecordAdhDecisionRequest, RecordWaiverRequest, IpvCaseWithTimeline, ActiveDisqualificationResponse -
services/canopy-enrollment/src/domain.rs— SnapEnrollment, SnapBenefitIssuance, CreateEnrollmentRequest, IssueBenefitsRequest -
services/canopy-renewals/src/domain.rs— SnapCertification, SnapChangeReport, CreateCertificationRequest, RecordInterimContactRequest, CreateChangeReportRequest -
services/canopy-notices/src/domain.rs— Notice, NoticeAppealRights, GenerateNoticeRequest, NoticeWithAppealRights -
services/canopy-reporting/src/domain.rs— SnapMonthlyReport, SnapQcUniverseEntry, GenerateReportRequest, GenerateSnapshotRequest -
services/canopy-security/src/store/models.rs— AuditEvent, BreachAlert, NistControlMapping, AuditSummaryRow -
crates/canopy-common/src/error.rs— ApiError (derive ToSchema for the error response type)
For canopy-reference enum types used in domain structs (e.g., DeterminationStatus, IncomeType, NoticeType), add #[derive(utoipa::ToSchema)].
Special handling:
* serde_json::Value fields: annotate with [schema(value_type = Object)]
* Decimal fields: annotate with [schema(value_type = String)]
* Vec<String> fields: no special handling needed (utoipa handles natively)
* chrono::DateTime<Utc> and NaiveDate: utoipa handles via the chrono feature (already enabled)
* Uuid: utoipa handles via the uuid feature (already enabled)
Step 2: Annotate canopy-persons (13 routes)
Files: services/canopy-persons/src/api/mod.rs
Routes to annotate:
| Method | Path | Handler | Tag |
|---|---|---|---|
POST |
/v1/persons |
create_person |
Persons |
GET |
/v1/persons |
list_persons |
Persons |
GET |
/v1/persons/{id} |
get_person |
Persons |
PUT |
/v1/persons/{id} |
update_person |
Persons |
DELETE |
/v1/persons/{id} |
delete_person |
Persons |
POST |
/v1/households |
create_household |
Households |
GET |
/v1/households/{id} |
get_household |
Households |
POST |
/v1/households/{id}/members |
add_member |
Households |
DELETE |
/v1/households/{household_id}/members/{member_id} |
remove_member |
Households |
POST |
/v1/persons/{id}/income |
add_income |
Income |
POST |
/v1/persons/{id}/assets |
add_asset |
Assets |
POST |
/v1/persons/{id}/expenses |
add_expense |
Expenses |
POST |
/v1/persons/{id}/addresses |
add_address |
Addresses |
Add ApiDoc struct with #[derive(OpenApi)].
Tags: Persons, Households, Income, Assets, Expenses, Addresses.
Also add ListParams derive for utoipa::IntoParams so query parameters appear in the spec:
#[derive(Debug, Deserialize, utoipa::IntoParams)]
pub struct ListParams {
pub limit: Option<i64>,
pub offset: Option<i64>,
pub search: Option<String>,
}
Step 3: Annotate canopy-applications (8 routes)
Files: services/canopy-applications/src/api/mod.rs
Routes: create_application, list_applications, get_application, update_application, withdraw_application, waive_interview, complete_interview, record_determination.
Tags: Applications, Interviews, Determinations.
Step 4: Annotate canopy-rules (7 routes)
Files: services/canopy-rules/src/api/mod.rs
Routes: list_rule_sets, create_rule_set, get_rule_set, update_rule_set, delete_rule_set, evaluate, list_evaluations.
Tags: Rule Sets, Evaluation.
Note: The rules engine uses serde_json::Value for rule content and evaluation input/output — use #[schema(value_type = Object)].
Step 5: Annotate canopy-eligibility (4 routes)
Files: services/canopy-eligibility/src/api/mod.rs, services/canopy-eligibility/src/api/handlers.rs
Routes: post_determine, get_request, get_request_determinations, get_result.
Tags: Eligibility.
Step 6: Annotate canopy-snap (10 routes)
Files: services/canopy-snap/src/api/mod.rs, services/canopy-snap/src/api/determine_handler.rs, services/canopy-snap/src/api/categorical_handler.rs, services/canopy-snap/src/api/verification_handler.rs
Routes across 3 handler modules:
-
Determine: post_determine, get_determination, list_determinations
-
Categorical: post_participation, list_participations, post_student_status, list_student_statuses
-
Verification: list_discrepancies, resolve_discrepancy, list_ievs_matches
Tags: Determination, Categorical Eligibility, Verification.
Since routes are split across files, the #[derive(OpenApi)] struct goes in mod.rs and references handlers from submodules.
Step 7: Annotate canopy-appeals (19 routes)
Files: services/canopy-appeals/src/api/mod.rs, services/canopy-appeals/src/ipv/api.rs
Two sets of routes:
Appeals (8 routes): file_appeal, list_appeals, appeals_queue, get_appeal, schedule_hearing, record_decision, withdraw_appeal, trigger_clock_check.
IPV (11 routes): create_referral, list_cases, get_case, schedule_adh, send_notice, record_decision, record_waiver, impose_disqualification, withdraw_case, check_active_disqualification.
Tags: Appeals, Fair Hearings, IPV, Disqualification.
The trigger_clock_check internal endpoint should be tagged "Internal" and documented as admin-only.
Step 8: Annotate canopy-enrollment (6 routes)
Files: services/canopy-enrollment/src/api/mod.rs
Routes: create_enrollment, list_enrollments, get_enrollment, issue_benefits, list_issuances, terminate_enrollment.
Tags: Enrollment, Benefit Issuance.
Step 9: Annotate canopy-renewals (7 routes)
Files: services/canopy-renewals/src/api/mod.rs
Routes: create_certification, get_active_certification, get_certification, list_due, list_interim_contacts_due, record_interim_contact, create_change_report.
Tags: Certifications, Interim Contacts, Change Reports.
Step 10: Annotate canopy-notices (6 routes)
Files: services/canopy-notices/src/api/mod.rs
Routes: generate_notice, list_notices, get_notice, get_notice_pdf, resend_notice, list_delivery_queue.
Tags: Notices, Delivery.
Note: get_notice_pdf returns application/pdf — use content_type = "application/pdf" in the response annotation.
Step 11: Annotate canopy-reporting (6 routes)
Files: services/canopy-reporting/src/api/mod.rs
Routes: generate_fns_388, list_reports, get_report, generate_qc_snapshot, get_qc_universe, export_qc_csv.
Tags: FNS-388, QC Universe.
Note: export_qc_csv returns text/csv — use content_type = "text/csv" in the response annotation.
Step 12: Annotate canopy-security (7 routes)
Files: services/canopy-security/src/api/mod.rs
Routes: list_events, get_event, list_alerts, get_alert, update_alert, list_nist_controls, get_summary.
Tags: Audit Events, Breach Alerts, NIST Controls.
Step 13: Wire OpenApi doc into each service’s main.rs
Files: All 11 service main.rs files
For each service, change:
ApiServer::router(state, api::routes(), opts, None)
To:
use utoipa::OpenApi;
ApiServer::router(state, api::routes(), opts, Some(api::ApiDoc::openapi()))
Services to wire:
-
services/canopy-persons/src/main.rs -
services/canopy-applications/src/main.rs -
services/canopy-rules/src/main.rs -
services/canopy-eligibility/src/main.rs -
services/canopy-snap/src/main.rs -
services/canopy-appeals/src/main.rs -
services/canopy-enrollment/src/main.rs -
services/canopy-renewals/src/main.rs -
services/canopy-notices/src/main.rs -
services/canopy-reporting/src/main.rs -
services/canopy-security/src/main.rs
After wiring, each service’s Swagger UI is accessible at http://localhost:{port}/swagger-ui.
Step 14: Tests and validation
-
cargo fmt --check --all -
cargo clippy --workspace --all-targets — -D warnings— zero warnings -
cargo nextest run --workspace— all existing tests still pass (no behavioral changes) -
Add a unit test in each service that verifies the OpenApi doc generates without error:
#[test]
fn openapi_doc_generates() {
use utoipa::OpenApi;
let doc = super::ApiDoc::openapi();
let json = doc.to_json().expect("should serialize to JSON");
assert!(json.contains("\"openapi\":\"3.1.0\""));
// Verify expected path count
assert_eq!(doc.paths.paths.len(), 13); // adjust per service
}
-
With devstack running, verify each service’s
/swagger-uiloads in a browser -
Verify
/api-doc/openapi.jsonreturns valid OpenAPI 3.1.0 JSON for each service -
cargo xtask validate— full pre-push validation passes
Files Touched
| File | Change |
|---|---|
|
Add |
|
Add |
|
Pass |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Add |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
|
Wire OpenApi doc |
|
Add |
|
Add |
Verification
-
cargo nextest run --workspace --lib— unit tests pass (existing + 11 new openapi_doc_generates tests) -
cargo xtask dev reload— services restart with Swagger UI enabled -
cargo nextest run --workspace— integration tests pass -
cargo xtask e2e— E2E tests pass (no behavioral changes expected) -
cargo fmt --check --all— no formatting issues -
cargo clippy --workspace --all-targets — -D warnings— zero warnings -
cargo xtask validate— full pre-push validation passes -
Each service’s
/swagger-uiloads in browser with complete endpoint listing -
Each service’s
/api-doc/openapi.jsonreturns valid OpenAPI 3.1.0 JSON -
All endpoints show Bearer JWT security requirement in Swagger UI
-
Request/response schemas render correctly (no
object {}placeholders) -
Tag grouping correctly categorizes endpoints
Documentation Updates
-
.claude/CLAUDE.md— note that all API services serve Swagger UI at/swagger-ui -
.claude/docs/services.md— add Swagger UI URLs to service table -
docs/modules/ROOT/pages/plans/documentation-completeness.adoc— Step 2 can now reference auto-generated specs -
CHANGELOG.adoc— entry under== Unreleased