Skip to content

feat(page): DocsUI::Endpoint + FieldTable/ErrorTable — the endpoint-reference kit#30

Merged
mhenrixon merged 1 commit into
mainfrom
issue-14-endpoint-reference-kit
Jul 3, 2026
Merged

feat(page): DocsUI::Endpoint + FieldTable/ErrorTable — the endpoint-reference kit#30
mhenrixon merged 1 commit into
mainfrom
issue-14-endpoint-reference-kit

Conversation

@mhenrixon

Copy link
Copy Markdown
Owner

Closes #14. Part of #8 (Phase 2).

Problem

The gem had zero API-documentation vocabulary. Every API page in a consuming site repeated the same shape by hand — an HTTP-method badge + path, a parameters table, and an error table — with per-page row helpers (err_row, field_row, scope_row, event_row) redefined across files with drifting arities and inconsistent "no value" placeholders ("-" vs "—").

What this adds

Three thin, composable pieces plus a Section extension. Documenting an endpoint's reference material is now declarative and renders identically across every site.

1. DocsUI::Endpoint.new(method, path)

A method badge + monospace path, rendered inline so it drops straight into a Section description or a run of prose.

  • Verb → colour is a frozen Hash of literal class strings so the Tailwind scan (which reads the gem's Ruby) generates every badge class: GETbadge-success, POSTbadge-primary, PATCH/PUTbadge-warning, DELETEbadge-error.
  • An unknown verb falls back to a neutral badge and never raises — a typo degrades gracefully.
  • Accepts a Symbol or String; the label is upcased.

2. Section#description accepts a Phlex component

DocsUI::Section("Create a message", description: DocsUI::Endpoint.new(:post, "/v1/messages"))

A component instance is matched before the callable branch (a Phlex component also responds to #call, so order matters). The existing String and proc forms are untouched — covered by unchanged passing specs.

3. DocsUI::FieldTable + DocsUI::ErrorTable

Keyword-schema presets over Table:

  • FieldTable.new(fields) — each { name:, type:, required: false, description: } → Name (code-styled) / Type / Required ( or the canonical em-dash ) / Description.
  • ErrorTable.new(errors) — each { scenario:, status:, type:, param: nil } → Scenario / Status / Type (code) / Param (code). The Param column is auto-hidden when no row names a param.

Descriptions honour Table's cell convention, so [:md, "…"] renders inline Markdown today.

Test plan

Spec Validates
endpoint_spec.rb badge class per verb; path monospace; upcasing; unknown verb → neutral (no raise); inline rendering; HTML escaping
field_table_spec.rb name code-styled; required tick vs canonical em-dash; [:md, …] description; composition over Table; escaping
error_table_spec.rb type code-styled; Param column present iff any row has a param (asserts the <td> count); composition; escaping
section_spec.rb a Phlex component instance description renders in place; existing String/proc specs untouched

Verification

  • bundle exec rspec187 examples, 0 failures (92% line coverage)
  • bundle exec rubocop — no offenses
  • cd docs && bun run build:cssbadge-success / badge-primary / badge-warning / badge-error / badge-neutral all present in the compiled CSS, proving the scan caught the literal frozen-Hash classes
  • Backwards compatible — the existing Section description forms are covered by untouched passing specs

Dogfood

The components reference page (docs/) gains an "Endpoint, FieldTable & ErrorTable" section rendering a realistic POST /api/webhook_endpoints example live, and the README component table lists all three.

Out of scope (per the issue)

  • Request/response example components (next issue).
  • OpenAPI ingestion into these components (possible follow-up epic).
  • Migrating app-4's pages (consumer follow-up; these components are their landing spot).

…eference kit

## Summary

The gem had zero API-documentation vocabulary, so every consuming API page
hand-rolled a method+path badge, a fields table, and an error table with
drifting per-page row helpers. This adds three thin, composable pieces plus a
Section extension so documenting an endpoint's reference material is declarative
and renders identically across every site.

- `DocsUI::Endpoint.new(method, path)` — verb badge (GET→success, POST→primary,
  PATCH/PUT→warning, DELETE→error via a frozen Hash of LITERAL class strings the
  CSS scan sees; unknown verb → neutral badge, no raise) + monospace path,
  rendered inline so it drops into a Section description or a run of prose.
- `Section#description` now also accepts a Phlex component instance (matched
  before the callable branch, since a component also responds to #call). The
  existing String/proc forms are untouched.
- `DocsUI::FieldTable` / `DocsUI::ErrorTable` — keyword-schema presets over Table.
  FieldTable: Name (code) / Type / Required (✓ or canonical em-dash —) /
  Description. ErrorTable: Scenario / Status / Type (code) / Param (code); the
  Param column is auto-hidden when no row names a param.

Descriptions honour Table's cell convention, so `[:md, …]` renders inline
Markdown today.

## Test Coverage

- spec/docs_ui/endpoint_spec.rb — badge class per verb, path monospace, upcasing,
  unknown verb → neutral (no raise), inline rendering, HTML escaping.
- spec/docs_ui/field_table_spec.rb — name code-styled, required tick vs canonical
  em-dash, [:md, …] description, composition over Table, escaping.
- spec/docs_ui/error_table_spec.rb — type code-styled, Param column present iff
  any row has a param (td-count asserted), composition, escaping.
- spec/docs_ui/section_spec.rb — a Phlex component instance description renders in
  place; existing String/proc specs untouched (backwards compatible).

## Verification

- [x] bundle exec rspec — 187 examples, 0 failures (92% line coverage)
- [x] bundle exec rubocop — no offenses
- [x] bun run build:css — badge-success/primary/warning/error/neutral all present
      in the compiled CSS (the literal frozen-Hash classes were scanned)

Closes #14
@mhenrixon mhenrixon merged commit 3d7dd75 into main Jul 3, 2026
3 checks passed
@mhenrixon mhenrixon deleted the issue-14-endpoint-reference-kit branch July 4, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api-docs): DocsUI::Endpoint + FieldTable/ErrorTable — the endpoint-reference kit

1 participant