mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(api): wrap JSON responses in envelope
Add response envelope middleware to standardize JSON responses as
`{code,data,message}` with consistent business codes across endpoints.
Update Swagger annotations and tests to reflect the new response shape.
BREAKING CHANGE: API responses are now wrapped in a response envelope; clients must read payloads from `data` and handle `code`/`message` fields.
This commit is contained in:
12
internal/api/response_envelope.go
Normal file
12
internal/api/response_envelope.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package api
|
||||
|
||||
// ResponseEnvelope is the standard wrapper for EZ-API JSON responses.
|
||||
// Code is a stable business code string (e.g., ok, invalid_request, not_found).
|
||||
// Message is empty for success and mirrors the top-level error for failures.
|
||||
// Data holds the original response payload.
|
||||
// swagger:model ResponseEnvelope
|
||||
type ResponseEnvelope struct {
|
||||
Code string `json:"code" example:"ok"`
|
||||
Data any `json:"data" swaggertype:"object"`
|
||||
Message string `json:"message" example:""`
|
||||
}
|
||||
Reference in New Issue
Block a user