From b6e8d037a0d1049369c10c4fb467f25628a4630b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 30 Nov 2022 16:46:14 +0100 Subject: [PATCH] Add json tags to query structs (otherwise swag does not get the correct names) --- server/api/handler/api.go | 20 ++--- server/api/handler/compat.go | 40 +++++----- server/api/handler/message.go | 34 ++++----- server/swagger/swagger.json | 94 +++++++++++------------ server/swagger/swagger.yaml | 138 +++++++++++++++++----------------- 5 files changed, 163 insertions(+), 163 deletions(-) diff --git a/server/api/handler/api.go b/server/api/handler/api.go index 1c8b272..226056b 100644 --- a/server/api/handler/api.go +++ b/server/api/handler/api.go @@ -515,7 +515,7 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse { UserID models.UserID `uri:"uid"` } type query struct { - Selector *string `form:"selector"` + Selector *string `json:"selector" form:"selector"` } type response struct { Channels []models.ChannelJSON `json:"channels"` @@ -720,10 +720,10 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse { ChannelID models.ChannelID `uri:"cid"` } type query struct { - PageSize *int `form:"page_size"` - NextPageToken *string `form:"next_page_token"` - Filter *string `form:"filter"` - Trimmed *bool `form:"trimmed"` + PageSize *int `json:"page_size" form:"page_size"` + NextPageToken *string `json:"next_page_token" form:"next_page_token"` + Filter *string `json:"filter" form:"filter"` + Trimmed *bool `json:"trimmed" form:"trimmed"` } type response struct { Messages []models.MessageJSON `json:"messages"` @@ -1015,7 +1015,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse { Channel string `form:"channel_name" binding:"required"` } type query struct { - ChanSubscribeKey *string `form:"chan_subscribe_key"` + ChanSubscribeKey *string `json:"chan_subscribe_key" form:"chan_subscribe_key"` } var u uri @@ -1136,10 +1136,10 @@ func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse { // @Router /api/messages [GET] func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse { type query struct { - PageSize *int `form:"page_size"` - NextPageToken *string `form:"next_page_token"` - Filter *string `form:"filter"` - Trimmed *bool `form:"trimmed"` //TODO more filter (sender-name, channel, timestamps, prio, ) + PageSize *int `json:"page_size" form:"page_size"` + NextPageToken *string `json:"next_page_token" form:"next_page_token"` + Filter *string `json:"filter" form:"filter"` + Trimmed *bool `json:"trimmed" form:"trimmed"` //TODO more filter (sender-name, channel, timestamps, prio, ) } type response struct { Messages []models.MessageJSON `json:"messages"` diff --git a/server/api/handler/compat.go b/server/api/handler/compat.go index 1bf5b60..f231a61 100644 --- a/server/api/handler/compat.go +++ b/server/api/handler/compat.go @@ -46,9 +46,9 @@ func NewCompatHandler(app *logic.Application) CompatHandler { // @Router /api/register.php [get] func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse { type query struct { - FCMToken *string `form:"fcm_token"` - Pro *string `form:"pro"` - ProToken *string `form:"pro_token"` + FCMToken *string `json:"fcm_token" form:"fcm_token"` + Pro *string `json:"pro" form:"pro"` + ProToken *string `json:"pro_token" form:"pro_token"` } type response struct { Success bool `json:"success"` @@ -152,8 +152,8 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse { // @Router /api/info.php [get] func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id" json:"user_id"` - UserKey *string `form:"user_key" json:"user_key"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` } type response struct { Success bool `json:"success"` @@ -238,9 +238,9 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse { // @Router /api/ack.php [get] func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id"` - UserKey *string `form:"user_key"` - MessageID *int64 `form:"scn_msg_id"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + MessageID *int64 `json:"scn_msg_id" form:"scn_msg_id"` } type response struct { Success bool `json:"success"` @@ -309,8 +309,8 @@ func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse { // @Router /api/requery.php [get] func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id"` - UserKey *string `form:"user_key"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` } type response struct { Success bool `json:"success"` @@ -378,9 +378,9 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse { // @Router /api/update.php [get] func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id"` - UserKey *string `form:"user_key"` - FCMToken *string `form:"fcm_token"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + FCMToken *string `json:"fcm_token" form:"fcm_token"` } type response struct { Success bool `json:"success"` @@ -491,9 +491,9 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse { // @Router /api/expand.php [get] func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id"` - UserKey *string `form:"user_key"` - MessageID *int64 `form:"scn_msg_id"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + MessageID *int64 `json:"scn_msg_id" form:"scn_msg_id"` } type response struct { Success bool `json:"success"` @@ -580,10 +580,10 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse { // @Router /api/upgrade.php [get] func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *int64 `form:"user_id"` - UserKey *string `form:"user_key"` - Pro *string `form:"pro"` - ProToken *string `form:"pro_token"` + UserID *int64 `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + Pro *string `json:"pro" form:"pro"` + ProToken *string `json:"pro_token" form:"pro_token"` } type response struct { Success bool `json:"success"` diff --git a/server/api/handler/message.go b/server/api/handler/message.go index b2db693..f7f4fb9 100644 --- a/server/api/handler/message.go +++ b/server/api/handler/message.go @@ -50,13 +50,13 @@ func NewMessageHandler(app *logic.Application) MessageHandler { // @Router /send.php [POST] func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *models.UserID `form:"user_id"` - UserKey *string `form:"user_key"` - Title *string `form:"title"` - Content *string `form:"content"` - Priority *int `form:"priority"` - UserMessageID *string `form:"msg_id"` - SendTimestamp *float64 `form:"timestamp"` + UserID *models.UserID `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + Title *string `json:"title" form:"title"` + Content *string `json:"content" form:"content"` + Priority *int `json:"priority" form:"priority"` + UserMessageID *string `json:"msg_id" form:"msg_id"` + SendTimestamp *float64 `json:"timestamp" form:"timestamp"` } type form struct { UserID *models.UserID `form:"user_id"` @@ -102,16 +102,16 @@ func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse { // @Router /send [POST] func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse { type query struct { - UserID *models.UserID `form:"user_id"` - UserKey *string `form:"user_key"` - Channel *string `form:"channel"` - ChanKey *string `form:"chan_key"` - Title *string `form:"title"` - Content *string `form:"content"` - Priority *int `form:"priority"` - UserMessageID *string `form:"msg_id"` - SendTimestamp *float64 `form:"timestamp"` - SenderName *string `form:"sender_name"` + UserID *models.UserID `json:"user_id" form:"user_id"` + UserKey *string `json:"user_key" form:"user_key"` + Channel *string `json:"channel" form:"channel"` + ChanKey *string `json:"chan_key" form:"chan_key"` + Title *string `json:"title" form:"title"` + Content *string `json:"content" form:"content"` + Priority *int `json:"priority" form:"priority"` + UserMessageID *string `json:"msg_id" form:"msg_id"` + SendTimestamp *float64 `json:"timestamp" form:"timestamp"` + SenderName *string `json:"sender_name" form:"sender_name"` } type body struct { UserID *models.UserID `json:"user_id"` diff --git a/server/swagger/swagger.json b/server/swagger/swagger.json index 80c44ac..9b11389 100644 --- a/server/swagger/swagger.json +++ b/server/swagger/swagger.json @@ -19,7 +19,7 @@ "parameters": [ { "type": "string", - "name": "chanKey", + "name": "chan_key", "in": "query" }, { @@ -32,19 +32,24 @@ "name": "content", "in": "query" }, + { + "type": "string", + "name": "msg_id", + "in": "query" + }, { "type": "integer", "name": "priority", "in": "query" }, { - "type": "number", - "name": "sendTimestamp", + "type": "string", + "name": "sender_name", "in": "query" }, { - "type": "string", - "name": "senderName", + "type": "number", + "name": "timestamp", "in": "query" }, { @@ -54,17 +59,12 @@ }, { "type": "integer", - "name": "userID", + "name": "user_id", "in": "query" }, { "type": "string", - "name": "userKey", - "in": "query" - }, - { - "type": "string", - "name": "userMessageID", + "name": "user_key", "in": "query" }, { @@ -394,12 +394,12 @@ }, { "type": "string", - "name": "nextPageToken", + "name": "next_page_token", "in": "query" }, { "type": "integer", - "name": "pageSize", + "name": "page_size", "in": "query" }, { @@ -1334,12 +1334,12 @@ }, { "type": "string", - "name": "nextPageToken", + "name": "next_page_token", "in": "query" }, { "type": "integer", - "name": "pageSize", + "name": "page_size", "in": "query" }, { @@ -1557,13 +1557,15 @@ } } } - }, - "delete": { + } + }, + "/api/users/{uid}/clients/{cid}": { + "get": { "tags": [ "API-v2" ], - "summary": "Delete a client", - "operationId": "api-clients-delete", + "summary": "Get a single client", + "operationId": "api-clients-get", "parameters": [ { "type": "integer", @@ -1612,15 +1614,13 @@ } } } - } - }, - "/api/users/{uid}/clients/{cid}": { - "get": { + }, + "delete": { "tags": [ "API-v2" ], - "summary": "Get a single clients", - "operationId": "api-clients-get", + "summary": "Delete a client", + "operationId": "api-clients-delete", "parameters": [ { "type": "integer", @@ -1736,7 +1736,7 @@ }, { "type": "string", - "name": "chanSubscribeKey", + "name": "chan_subscribe_key", "in": "query" }, { @@ -1959,7 +1959,7 @@ "parameters": [ { "type": "string", - "name": "chanKey", + "name": "chan_key", "in": "query" }, { @@ -1972,19 +1972,24 @@ "name": "content", "in": "query" }, + { + "type": "string", + "name": "msg_id", + "in": "query" + }, { "type": "integer", "name": "priority", "in": "query" }, { - "type": "number", - "name": "sendTimestamp", + "type": "string", + "name": "sender_name", "in": "query" }, { - "type": "string", - "name": "senderName", + "type": "number", + "name": "timestamp", "in": "query" }, { @@ -1994,17 +1999,12 @@ }, { "type": "integer", - "name": "userID", + "name": "user_id", "in": "query" }, { "type": "string", - "name": "userKey", - "in": "query" - }, - { - "type": "string", - "name": "userMessageID", + "name": "user_key", "in": "query" }, { @@ -2114,6 +2114,11 @@ "name": "content", "in": "query" }, + { + "type": "string", + "name": "msg_id", + "in": "query" + }, { "type": "integer", "name": "priority", @@ -2121,7 +2126,7 @@ }, { "type": "number", - "name": "sendTimestamp", + "name": "timestamp", "in": "query" }, { @@ -2131,17 +2136,12 @@ }, { "type": "integer", - "name": "userID", + "name": "user_id", "in": "query" }, { "type": "string", - "name": "userKey", - "in": "query" - }, - { - "type": "string", - "name": "userMessageID", + "name": "user_key", "in": "query" }, { diff --git a/server/swagger/swagger.yaml b/server/swagger/swagger.yaml index 46797db..4add681 100644 --- a/server/swagger/swagger.yaml +++ b/server/swagger/swagger.yaml @@ -491,7 +491,7 @@ paths: Only UserID, UserKey and Title are required parameters: - in: query - name: chanKey + name: chan_key type: string - in: query name: channel @@ -499,26 +499,26 @@ paths: - in: query name: content type: string + - in: query + name: msg_id + type: string - in: query name: priority type: integer - in: query - name: sendTimestamp - type: number - - in: query - name: senderName + name: sender_name type: string + - in: query + name: timestamp + type: number - in: query name: title type: string - in: query - name: userID + name: user_id type: integer - in: query - name: userKey - type: string - - in: query - name: userMessageID + name: user_key type: string - description: ' ' in: body @@ -742,10 +742,10 @@ paths: name: filter type: string - in: query - name: nextPageToken + name: next_page_token type: string - in: query - name: pageSize + name: page_size type: integer - description: TODO more filter (sender-name, channel, timestamps, prio, ) in: query @@ -1386,10 +1386,10 @@ paths: name: filter type: string - in: query - name: nextPageToken + name: next_page_token type: string - in: query - name: pageSize + name: page_size type: integer - in: query name: trimmed @@ -1467,43 +1467,6 @@ paths: tags: - API-v2 /api/users/{uid}/clients: - delete: - operationId: api-clients-delete - parameters: - - description: UserID - in: path - name: uid - required: true - type: integer - - description: ClientID - in: path - name: cid - required: true - type: integer - responses: - "200": - description: OK - schema: - $ref: '#/definitions/models.ClientJSON' - "400": - description: Bad Request - schema: - $ref: '#/definitions/ginresp.apiError' - "401": - description: Unauthorized - schema: - $ref: '#/definitions/ginresp.apiError' - "404": - description: Not Found - schema: - $ref: '#/definitions/ginresp.apiError' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/ginresp.apiError' - summary: Delete a client - tags: - - API-v2 get: operationId: api-clients-list parameters: @@ -1574,6 +1537,43 @@ paths: tags: - API-v2 /api/users/{uid}/clients/{cid}: + delete: + operationId: api-clients-delete + parameters: + - description: UserID + in: path + name: uid + required: true + type: integer + - description: ClientID + in: path + name: cid + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.ClientJSON' + "400": + description: Bad Request + schema: + $ref: '#/definitions/ginresp.apiError' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/ginresp.apiError' + "404": + description: Not Found + schema: + $ref: '#/definitions/ginresp.apiError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/ginresp.apiError' + summary: Delete a client + tags: + - API-v2 get: operationId: api-clients-get parameters: @@ -1608,7 +1608,7 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/ginresp.apiError' - summary: Get a single clients + summary: Get a single client tags: - API-v2 /api/users/{uid}/subscriptions: @@ -1653,7 +1653,7 @@ paths: required: true type: integer - in: query - name: chanSubscribeKey + name: chan_subscribe_key type: string - description: ' ' in: body @@ -1802,7 +1802,7 @@ paths: Only UserID, UserKey and Title are required parameters: - in: query - name: chanKey + name: chan_key type: string - in: query name: channel @@ -1810,26 +1810,26 @@ paths: - in: query name: content type: string + - in: query + name: msg_id + type: string - in: query name: priority type: integer - in: query - name: sendTimestamp - type: number - - in: query - name: senderName + name: sender_name type: string + - in: query + name: timestamp + type: number - in: query name: title type: string - in: query - name: userID + name: user_id type: integer - in: query - name: userKey - type: string - - in: query - name: userMessageID + name: user_key type: string - description: ' ' in: body @@ -1900,23 +1900,23 @@ paths: - in: query name: content type: string + - in: query + name: msg_id + type: string - in: query name: priority type: integer - in: query - name: sendTimestamp + name: timestamp type: number - in: query name: title type: string - in: query - name: userID + name: user_id type: integer - in: query - name: userKey - type: string - - in: query - name: userMessageID + name: user_key type: string - in: formData name: content