3.5 KiB
Swagger response contracts
Every registered API operation has an explicit success response schema. JSON payloads document their envelope, property names, arrays, nested objects, and pagination. Operations without a data payload use message-only schemas; CSV, HTML, OAuth redirects, and WebSocket upgrades retain their actual media/protocol contracts rather than being described as generic JSON.
Response envelopes
domain.Response{data=ConcreteType}documentsmessage,success,status_code, endpoint-specificdata, andmetadata.response.APIResponse{data=ConcreteType}documents legacy account responses withstatus,message, typeddata,timestamp, and optional pagination.MessageResponseandMessageAPIResponsedescribe responses that omitdata.- Some endpoints, such as notification counts/lists and analytics, return a top-level object. Their schemas describe that object without adding an envelope.
Raw service/domain records retain their existing JSON casing. For example, assessment question sets and raw Vimeo upload results expose PascalCase fields. Their Swagger models use those exact names; this documentation update does not rename existing API properties.
Both immediately dispatched and scheduled bulk notifications are documented:
200 returns the delivery summary and 201 returns a scheduled notification.
Free-plan checkout includes an optional subscription in the checkout response.
Pagination metadata for staff lists and Vimeo lists has a concrete schema.
Extensible JSON and errors
Activity/notification metadata and template variables are intentionally extensible
objects. Their descriptions identify the source of their keys. A dynamic question
component's value depends on its kind; its description and x-json-types
extension explicitly document the permitted JSON variants. These fields cannot
truthfully be represented as one fixed object or as a byte array.
Reserved response metadata is null, or omitted in the legacy envelope, unless
the operation supplies a concrete metadata schema. Message-only responses document
this null value explicitly.
Error responses retain their real transport shape: JSON handler errors use
domain.ErrorResponse; handlers/middleware returning Fiber errors use a plain-text
string. The API does not have a universal JSON error envelope. Consumers should
respect the response Content-Type, particularly on authentication and service
failures. The documentation does not change runtime error handling.
Maintaining complete schemas
When adding an operation:
- Reuse an existing response type or add a small tagged payload DTO for maps.
- Specify the complete response envelope and typed
datain@Success. - Document each success status variant and the actual error bodies.
- Use explicit descriptions for genuinely open JSON extension points.
- Regenerate all artifacts and run the contract checks:
swag init -g cmd/main.go
go test ./internal/web_server/... ./internal/domain ./internal/apidocs/...
go run ./cmd/swagger-export -out exports/swagger-offline
TestEveryAPIResponseHasDetailedSchema checks response definitions recursively,
including item schemas and composed envelope overrides. It rejects generic success
envelopes, missing schemas, and unexplained empty fields. Other checks ensure route,
security, request-body, and path-parameter coverage, valid references, and parity
between docs.go, swagger.json, and swagger.yaml. Representative payload tests
also compare documentation-only DTOs with the JSON written by the runtime types.