Plan: OpenAPI / Swagger Documentation

Status

Step Description Status

1

Add ToSchema derives to all domain/model structs and enums

Done (2026-04-05)

2

Add #[utoipa::path] annotations to canopy-persons (13 routes)

Done (2026-04-05)

3

Add #[utoipa::path] annotations to canopy-applications (8 routes)

Done (2026-04-05)

4

Add #[utoipa::path] annotations to canopy-rules (7 routes)

Done (2026-04-05)

5

Add #[utoipa::path] annotations to canopy-eligibility (4 routes)

Done (2026-04-05)

6

Add #[utoipa::path] annotations to canopy-snap (10 routes)

Done (2026-04-05)

7

Add #[utoipa::path] annotations to canopy-appeals (19 routes)

Done (2026-04-05)

8

Add #[utoipa::path] annotations to canopy-enrollment (6 routes)

Done (2026-04-05)

9

Add #[utoipa::path] annotations to canopy-renewals (7 routes)

Done (2026-04-05)

10

Add #[utoipa::path] annotations to canopy-notices (6 routes)

Done (2026-04-05)

11

Add #[utoipa::path] annotations to canopy-reporting (6 routes)

Done (2026-04-05)

12

Add #[utoipa::path] annotations to canopy-security (7 routes)

Done (2026-04-05)

13

Wire OpenApi doc into each service’s main.rs (pass to ApiServer::router)

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:

  1. Accepts an Option<utoipa::openapi::OpenApi> in ApiServer::router()

  2. Mounts SwaggerUi::new("/swagger-ui") when a doc is provided

  3. 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:

  • ToSchema derives 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 OpenApi doc to ApiServer::router() in each service’s main.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-docs command (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;

main.rs Wiring

Each service changes from:

let router = ApiServer::router(state, api::routes(), opts, None);

To:

let router = ApiServer::router(
    state,
    api::routes(),
    opts,
    Some(api::ApiDoc::openapi()),
);

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:

  1. services/canopy-persons/src/store/models.rs — Person, CreatePerson, UpdatePerson, Household, CreateHousehold, HouseholdMember, AddMember, Income, CreateIncome, Asset, CreateAsset, Expense, CreateExpense, Address, CreateAddress, HouseholdWithMembers

  2. services/canopy-applications/src/domain.rs — Application, ApplicationProgram, CreateApplicationRequest, ExpeditedScreeningData, ApplicationWithPrograms

  3. services/canopy-eligibility/src/store/models.rs — EligibilityRequest, ProgramDetermination, CombinedResult

  4. services/canopy-snap/src/store/models.rs — SnapApplication, SnapDetermination, IevsVerificationRecord

  5. services/canopy-appeals/src/domain.rs — AppealRequest, AppealTimelineEvent, FileAppealRequest, ScheduleHearingRequest, RecordDecisionRequest, AppealWithTimeline

  6. services/canopy-appeals/src/ipv/domain.rs — IpvCase, IpvTimelineEvent, CreateIpvReferralRequest, ScheduleAdhRequest, RecordAdhDecisionRequest, RecordWaiverRequest, IpvCaseWithTimeline, ActiveDisqualificationResponse

  7. services/canopy-enrollment/src/domain.rs — SnapEnrollment, SnapBenefitIssuance, CreateEnrollmentRequest, IssueBenefitsRequest

  8. services/canopy-renewals/src/domain.rs — SnapCertification, SnapChangeReport, CreateCertificationRequest, RecordInterimContactRequest, CreateChangeReportRequest

  9. services/canopy-notices/src/domain.rs — Notice, NoticeAppealRights, GenerateNoticeRequest, NoticeWithAppealRights

  10. services/canopy-reporting/src/domain.rs — SnapMonthlyReport, SnapQcUniverseEntry, GenerateReportRequest, GenerateSnapshotRequest

  11. services/canopy-security/src/store/models.rs — AuditEvent, BreachAlert, NistControlMapping, AuditSummaryRow

  12. 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:

  1. services/canopy-persons/src/main.rs

  2. services/canopy-applications/src/main.rs

  3. services/canopy-rules/src/main.rs

  4. services/canopy-eligibility/src/main.rs

  5. services/canopy-snap/src/main.rs

  6. services/canopy-appeals/src/main.rs

  7. services/canopy-enrollment/src/main.rs

  8. services/canopy-renewals/src/main.rs

  9. services/canopy-notices/src/main.rs

  10. services/canopy-reporting/src/main.rs

  11. 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

  1. cargo fmt --check --all

  2. cargo clippy --workspace --all-targets — -D warnings — zero warnings

  3. cargo nextest run --workspace — all existing tests still pass (no behavioral changes)

  4. 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
}
  1. With devstack running, verify each service’s /swagger-ui loads in a browser

  2. Verify /api-doc/openapi.json returns valid OpenAPI 3.1.0 JSON for each service

  3. cargo xtask validate — full pre-push validation passes

Files Touched

File Change

services/canopy-persons/src/store/models.rs

Add ToSchema derives to 16 types

services/canopy-persons/src/api/mod.rs

Add #[utoipa::path] to 13 handlers, ApiDoc struct, IntoParams on ListParams

services/canopy-persons/src/main.rs

Pass Some(api::ApiDoc::openapi()) to router

services/canopy-applications/src/domain.rs

Add ToSchema derives to 5 types

services/canopy-applications/src/api/mod.rs

Add #[utoipa::path] to 8 handlers, ApiDoc struct

services/canopy-applications/src/main.rs

Wire OpenApi doc

services/canopy-rules/src/api/mod.rs

Add #[utoipa::path] to 7 handlers, ApiDoc struct

services/canopy-rules/src/main.rs

Wire OpenApi doc

services/canopy-eligibility/src/store/models.rs

Add ToSchema derives to 3 types

services/canopy-eligibility/src/api/handlers.rs

Add #[utoipa::path] to 4 handlers

services/canopy-eligibility/src/api/mod.rs

Add ApiDoc struct

services/canopy-eligibility/src/main.rs

Wire OpenApi doc

services/canopy-snap/src/store/models.rs

Add ToSchema derives to 3 types

services/canopy-snap/src/api/determine_handler.rs

Add #[utoipa::path] to 3 handlers

services/canopy-snap/src/api/categorical_handler.rs

Add #[utoipa::path] to 4 handlers

services/canopy-snap/src/api/verification_handler.rs

Add #[utoipa::path] to 3 handlers

services/canopy-snap/src/api/mod.rs

Add ApiDoc struct

services/canopy-snap/src/main.rs

Wire OpenApi doc

services/canopy-appeals/src/domain.rs

Add ToSchema derives to 6 types

services/canopy-appeals/src/ipv/domain.rs

Add ToSchema derives to 8 types

services/canopy-appeals/src/api/mod.rs

Add #[utoipa::path] to 8 handlers, ApiDoc struct

services/canopy-appeals/src/ipv/api.rs

Add #[utoipa::path] to 11 handlers

services/canopy-appeals/src/main.rs

Wire OpenApi doc

services/canopy-enrollment/src/domain.rs

Add ToSchema derives to 4 types

services/canopy-enrollment/src/api/mod.rs

Add #[utoipa::path] to 6 handlers, ApiDoc struct

services/canopy-enrollment/src/main.rs

Wire OpenApi doc

services/canopy-renewals/src/domain.rs

Add ToSchema derives to 5 types

services/canopy-renewals/src/api/mod.rs

Add #[utoipa::path] to 7 handlers, ApiDoc struct

services/canopy-renewals/src/main.rs

Wire OpenApi doc

services/canopy-notices/src/domain.rs

Add ToSchema derives to 4 types

services/canopy-notices/src/api/mod.rs

Add #[utoipa::path] to 6 handlers, ApiDoc struct

services/canopy-notices/src/main.rs

Wire OpenApi doc

services/canopy-reporting/src/domain.rs

Add ToSchema derives to 4 types

services/canopy-reporting/src/api/mod.rs

Add #[utoipa::path] to 6 handlers, ApiDoc struct

services/canopy-reporting/src/main.rs

Wire OpenApi doc

services/canopy-security/src/store/models.rs

Add ToSchema derives to 4 types

services/canopy-security/src/api/mod.rs

Add #[utoipa::path] to 7 handlers, ApiDoc struct

services/canopy-security/src/main.rs

Wire OpenApi doc

crates/canopy-reference/src/lib.rs

Add ToSchema derives to enums used in API types

crates/canopy-common/src/error.rs

Add ToSchema derive to ApiError

Verification

  1. cargo nextest run --workspace --lib — unit tests pass (existing + 11 new openapi_doc_generates tests)

  2. cargo xtask dev reload — services restart with Swagger UI enabled

  3. cargo nextest run --workspace — integration tests pass

  4. cargo xtask e2e — E2E tests pass (no behavioral changes expected)

  5. cargo fmt --check --all — no formatting issues

  6. cargo clippy --workspace --all-targets — -D warnings — zero warnings

  7. cargo xtask validate — full pre-push validation passes

  8. Each service’s /swagger-ui loads in browser with complete endpoint listing

  9. Each service’s /api-doc/openapi.json returns valid OpenAPI 3.1.0 JSON

  10. All endpoints show Bearer JWT security requirement in Swagger UI

  11. Request/response schemas render correctly (no object {} placeholders)

  12. 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

Edit this page · default