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:
@@ -58,11 +58,11 @@ type IssueChildKeyRequest struct {
|
||||
// @Produce json
|
||||
// @Security MasterAuth
|
||||
// @Param request body IssueChildKeyRequest true "Key Request"
|
||||
// @Success 201 {object} gin.H
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 403 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 201 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 403 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/tokens [post]
|
||||
func (h *MasterHandler) IssueChildKey(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -145,8 +145,8 @@ func (h *MasterHandler) IssueChildKey(c *gin.Context) {
|
||||
// @Tags master
|
||||
// @Produce json
|
||||
// @Security MasterAuth
|
||||
// @Success 200 {object} MasterView
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=MasterView}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/self [get]
|
||||
func (h *MasterHandler) GetSelf(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -219,9 +219,9 @@ func toTokenView(k model.Key) TokenView {
|
||||
// @Param page query int false "page (1-based)"
|
||||
// @Param limit query int false "limit (default 50, max 200)"
|
||||
// @Param search query string false "search by group/scopes/namespaces/status"
|
||||
// @Success 200 {array} TokenView
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=[]TokenView}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/tokens [get]
|
||||
func (h *MasterHandler) ListTokens(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -254,11 +254,11 @@ func (h *MasterHandler) ListTokens(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security MasterAuth
|
||||
// @Param id path int true "Token ID"
|
||||
// @Success 200 {object} TokenView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=TokenView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/tokens/{id} [get]
|
||||
func (h *MasterHandler) GetToken(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -302,11 +302,11 @@ type UpdateTokenRequest struct {
|
||||
// @Security MasterAuth
|
||||
// @Param id path int true "Token ID"
|
||||
// @Param request body UpdateTokenRequest true "Update payload"
|
||||
// @Success 200 {object} TokenView
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=TokenView}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/tokens/{id} [put]
|
||||
func (h *MasterHandler) UpdateToken(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
@@ -398,11 +398,11 @@ func (h *MasterHandler) UpdateToken(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Security MasterAuth
|
||||
// @Param id path int true "Token ID"
|
||||
// @Success 200 {object} gin.H
|
||||
// @Failure 400 {object} gin.H
|
||||
// @Failure 401 {object} gin.H
|
||||
// @Failure 404 {object} gin.H
|
||||
// @Failure 500 {object} gin.H
|
||||
// @Success 200 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 400 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 401 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 404 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Failure 500 {object} ResponseEnvelope{data=gin.H}
|
||||
// @Router /v1/tokens/{id} [delete]
|
||||
func (h *MasterHandler) DeleteToken(c *gin.Context) {
|
||||
master, exists := c.Get("master")
|
||||
|
||||
Reference in New Issue
Block a user