api-v2-routes

Implements typed Huma handlers for CRUD resources on the Vikunja /api/v2 REST API.

5.2k|656|Updated Nov 28, 2018
One-click install
npx skills add https://github.com/go-vikunja/vikunja --skill api-v2-routes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-v2-routes
Source: https://github.com/go-vikunja/vikunja/tree/main/.agents/skills/api-v2-routes
Command: npx skills add https://github.com/go-vikunja/vikunja --skill api-v2-routes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding or porting resources to Vikunja's Huma-backed /api/v2 API involves many non-obvious conventions—typed per-operation handlers, shared envelopes, error bridging, doc tags, and AutoPatch behavior—that are easy to get wrong and produce silent bugs like empty lists or undocumented endpoints.

Core Features & Use Cases

  • Per-operation Huma handlers: Guides creating typed handlers that pull auth from context, call the shared handler.Do* functions, and translate domain errors into RFC 9457 problem+json responses.
  • Schema documentation rules: Enforces doc: and readOnly:"true" struct tags so the runtime-generated OpenAPI spec is complete, since Huma cannot read Go doc comments.
  • Automatic machinery awareness: Explains what is handled automatically—PATCH via AutoPatch, API token permissions, global security schemes—so nothing is hand-rolled twice.
  • Use Case: When porting the labels resource from v1 to v2, follow the reference implementation in pkg/routes/api/v2/labels.go to register list/read/create/update/delete operations with correct envelopes, ETag handling, and mandatory webtests.

Quick Start

Add a new /api/v2 resource for my model by following the api-v2-routes skill, mirroring pkg/routes/api/v2/labels.go.

Frequently Asked Questions about api-v2-routes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new endpoint to the Vikunja /api/v2 API?▼

Create a file in pkg/routes/api/v2 defining a Register<Resource>Routes function with one typed Huma handler per operation, then self-register it via an init() calling AddRouteRegistrar. Mirror pkg/routes/api/v2/labels.go as the reference implementation.

How do Huma v2 routes differ from Vikunja v1 API routes?▼

v2 uses typed per-operation Huma handlers instead of v1's generic WebHandler, and inverts verb conventions: create is POST and update is PUT in v2 versus PUT and POST in v1. PATCH is synthesized automatically by AutoPatch for every GET+PUT pair.

Why does my Huma list endpoint return an empty array?▼

The DoReadAll result is typed as any, so a blind cast or generic wrapper silently serializes an empty list. Type-assert the result to the concrete slice with an ok check and return a hard error on mismatch.

Should I check permissions in a Huma v2 handler?▼

No for standard CRUD—permissions are enforced by the model's Can* methods through the handler.Do* functions. Only custom non-CRUD routes must check permissions explicitly, since no generic Do* helper exists for them.

Why are my model fields missing from the OpenAPI spec?▼

Huma generates the schema from struct tags at runtime and cannot read Go doc comments. Every exposed field needs a doc tag, and server-controlled fields like id and created need readOnly:"true" to appear correctly in the spec.

Why does mage test:filter not run my v2 webtests?▼

mage test:filter injects -short, which causes the pkg/webtests suite to skip entirely and silently report success. Run the test directly with go test -run '<Name>' ./pkg/webtests/ to actually exercise it.