Updated config.Message API docs. Allow params to be input via swagger ui.

This commit is contained in:
Patrick Connolly 2018-11-05 04:32:39 +08:00
parent de00b56d9a
commit 110b840d48
5 changed files with 156 additions and 40 deletions

View File

@ -108,6 +108,7 @@ func (b *Api) handleDocsRedirect(c echo.Context) error {
// @Summary Create/Update a message // @Summary Create/Update a message
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param body body object true "Message object to create"
// @Success 200 {object} config.Message // @Success 200 {object} config.Message
// @Router /message [post] // @Router /message [post]
func (b *API) handlePostMessage(c echo.Context) error { func (b *API) handlePostMessage(c echo.Context) error {
@ -127,7 +128,7 @@ func (b *API) handlePostMessage(c echo.Context) error {
} }
// handleMessages godoc // handleMessages godoc
// @Summary Lists messages // @Summary List of new messages
// @Produce json // @Produce json
// @Success 200 {array} config.Message // @Success 200 {array} config.Message
// @Router /messages [get] // @Router /messages [get]
@ -141,7 +142,7 @@ func (b *API) handleMessages(c echo.Context) error {
// handleStream godoc // handleStream godoc
// @Summary Streams realtime messages // @Summary Streams realtime messages
// @Produce json // @Produce json-stream
// @Success 200 {object} config.Message // @Success 200 {object} config.Message
// @Router /stream [get] // @Router /stream [get]
func (b *API) handleStream(c echo.Context) error { func (b *API) handleStream(c echo.Context) error {

View File

@ -27,18 +27,30 @@ const (
) )
type Message struct { type Message struct {
Text string `json:"text"` // Content of the message
Channel string `json:"channel"` Text string `json:"text" example:"Testing, testing, 1-2-3."`
Username string `json:"username"` // Human-readable channel name
UserID string `json:"userid"` // userid on the bridge Channel string `json:"channel" example:"test-channel"`
Avatar string `json:"avatar"` // Human-readable username
Account string `json:"account"` Username string `json:"username" example:"alice"`
Event string `json:"event"` // userid on the bridge
Protocol string `json:"protocol"` UserID string `json:"userid" example:"U4MCXJKNC"`
Gateway string `json:"gateway"` // URL to an avatar image
Avatar string `json:"avatar" example:"https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg"`
// Unique account name of format "<protocol>.<slug>"
Account string `json:"account" example:"slack.myteam"`
// Can be blank.
Event string `json:"event" example:""`
// Chat protocol of incoming message
Protocol string `json:"protocol" example:"slack"`
// Name of the gateway
Gateway string `json:"gateway" example:"test-channel-gateway"`
// Unique ID of a parent message, if threaded
ParentID string `json:"parent_id"` ParentID string `json:"parent_id"`
Timestamp time.Time `json:"timestamp"` Timestamp time.Time `json:"timestamp" example:"1541361213.030700"`
ID string `json:"id"` // Unique ID of message on the gateway
ID string `json:"id" example:"slack 1541361213.030700"`
// Extra data that doesn't fit in other fields. Used for processing incoming messages.
Extra map[string][]interface{} Extra map[string][]interface{}
} }

View File

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // This file was generated by swaggo/swag at
// 2018-11-05 01:51:14.853722 +0800 CST m=+0.078800065 // 2018-11-05 04:31:47.316226 +0800 CST m=+0.167027083
package docs package docs
@ -30,6 +30,17 @@ var doc = `{
"application/json" "application/json"
], ],
"summary": "Create/Update a message", "summary": "Create/Update a message",
"parameters": [
{
"description": "Message object to create",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -46,7 +57,7 @@ var doc = `{
"produces": [ "produces": [
"application/json" "application/json"
], ],
"summary": "Lists messages", "summary": "List of new messages",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -63,7 +74,7 @@ var doc = `{
"/stream": { "/stream": {
"get": { "get": {
"produces": [ "produces": [
"application/json" "application/x-json-stream"
], ],
"summary": "Streams realtime messages", "summary": "Streams realtime messages",
"responses": { "responses": {
@ -83,40 +94,61 @@ var doc = `{
"type": "object", "type": "object",
"properties": { "properties": {
"account": { "account": {
"type": "string" "description": "Unique account name of format \"\u003cprotocol\u003e.\u003cslug\u003e\"\n",
"type": "string",
"example": "slack.myteam"
}, },
"avatar": { "avatar": {
"type": "string" "description": "URL to an avatar image\n",
"type": "string",
"example": "https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg"
}, },
"channel": { "channel": {
"type": "string" "description": "Human-readable channel name\n",
"type": "string",
"example": "test-channel"
}, },
"event": { "event": {
"description": "Can be blank.\n",
"type": "string" "type": "string"
}, },
"extra": { "extra": {
"description": "Extra data that doesn't fit in other fields. Used for processing incoming messages.\n",
"type": "object" "type": "object"
}, },
"gateway": { "gateway": {
"type": "string" "description": "Name of the gateway\n",
"type": "string",
"example": "test-channel-gateway"
}, },
"id": { "id": {
"type": "string" "description": "Unique ID of message on the gateway\n",
"type": "string",
"example": "slack 1541361213.030700"
}, },
"protocol": { "protocol": {
"type": "string" "description": "Chat protocol of incoming message\n",
"type": "string",
"example": "slack"
}, },
"text": { "text": {
"type": "string" "description": "Content of the message\n",
"type": "string",
"example": "Testing, testing, 1-2-3."
}, },
"timestamp": { "timestamp": {
"type": "string" "type": "string",
"example": "1541361213.030700"
}, },
"userid": { "userid": {
"type": "string" "description": "userid on the bridge\n",
"type": "string",
"example": "U4MCXJKNC"
}, },
"username": { "username": {
"type": "string" "description": "Human-readable username\n",
"type": "string",
"example": "alice"
} }
} }
} }

View File

@ -20,6 +20,17 @@
"application/json" "application/json"
], ],
"summary": "Create/Update a message", "summary": "Create/Update a message",
"parameters": [
{
"description": "Message object to create",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -36,7 +47,7 @@
"produces": [ "produces": [
"application/json" "application/json"
], ],
"summary": "Lists messages", "summary": "List of new messages",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -53,7 +64,7 @@
"/stream": { "/stream": {
"get": { "get": {
"produces": [ "produces": [
"application/json" "application/x-json-stream"
], ],
"summary": "Streams realtime messages", "summary": "Streams realtime messages",
"responses": { "responses": {
@ -73,40 +84,61 @@
"type": "object", "type": "object",
"properties": { "properties": {
"account": { "account": {
"type": "string" "description": "Unique account name of format \"\u003cprotocol\u003e.\u003cslug\u003e\"\n",
"type": "string",
"example": "slack.myteam"
}, },
"avatar": { "avatar": {
"type": "string" "description": "URL to an avatar image\n",
"type": "string",
"example": "https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg"
}, },
"channel": { "channel": {
"type": "string" "description": "Human-readable channel name\n",
"type": "string",
"example": "test-channel"
}, },
"event": { "event": {
"description": "Can be blank.\n",
"type": "string" "type": "string"
}, },
"extra": { "extra": {
"description": "Extra data that doesn't fit in other fields. Used for processing incoming messages.\n",
"type": "object" "type": "object"
}, },
"gateway": { "gateway": {
"type": "string" "description": "Name of the gateway\n",
"type": "string",
"example": "test-channel-gateway"
}, },
"id": { "id": {
"type": "string" "description": "Unique ID of message on the gateway\n",
"type": "string",
"example": "slack 1541361213.030700"
}, },
"protocol": { "protocol": {
"type": "string" "description": "Chat protocol of incoming message\n",
"type": "string",
"example": "slack"
}, },
"text": { "text": {
"type": "string" "description": "Content of the message\n",
"type": "string",
"example": "Testing, testing, 1-2-3."
}, },
"timestamp": { "timestamp": {
"type": "string" "type": "string",
"example": "1541361213.030700"
}, },
"userid": { "userid": {
"type": "string" "description": "userid on the bridge\n",
"type": "string",
"example": "U4MCXJKNC"
}, },
"username": { "username": {
"type": "string" "description": "Human-readable username\n",
"type": "string",
"example": "alice"
} }
} }
} }

View File

@ -3,28 +3,60 @@ definitions:
config.Message: config.Message:
properties: properties:
account: account:
description: |
Unique account name of format "<protocol>.<slug>"
example: slack.myteam
type: string type: string
avatar: avatar:
description: |
URL to an avatar image
example: https://secure.gravatar.com/avatar/1234567890abcdef1234567890abcdef.jpg
type: string type: string
channel: channel:
description: |
Human-readable channel name
example: test-channel
type: string type: string
event: event:
description: |
Can be blank.
type: string type: string
extra: extra:
description: |
Extra data that doesn't fit in other fields. Used for processing incoming messages.
type: object type: object
gateway: gateway:
description: |
Name of the gateway
example: test-channel-gateway
type: string type: string
id: id:
description: |
Unique ID of message on the gateway
example: slack 1541361213.030700
type: string type: string
protocol: protocol:
description: |
Chat protocol of incoming message
example: slack
type: string type: string
text: text:
description: |
Content of the message
example: Testing, testing, 1-2-3.
type: string type: string
timestamp: timestamp:
example: "1541361213.030700"
type: string type: string
userid: userid:
description: |
userid on the bridge
example: U4MCXJKNC
type: string type: string
username: username:
description: |
Human-readable username
example: alice
type: string type: string
type: object type: object
info: info:
@ -39,6 +71,13 @@ paths:
post: post:
consumes: consumes:
- application/json - application/json
parameters:
- description: Message object to create
in: body
name: body
required: true
schema:
type: object
produces: produces:
- application/json - application/json
responses: responses:
@ -59,11 +98,11 @@ paths:
items: items:
$ref: '#/definitions/config.Message' $ref: '#/definitions/config.Message'
type: array type: array
summary: Lists messages summary: List of new messages
/stream: /stream:
get: get:
produces: produces:
- application/json - application/x-json-stream
responses: responses:
"200": "200":
description: OK description: OK