Skip to content

Commit

Permalink
Merge pull request #7 from veops/dev
Browse files Browse the repository at this point in the history
feat: add swagger api doc
  • Loading branch information
ttktatakai authored Dec 12, 2023
2 parents 9fc2cfe + a74ee36 commit 5daa094
Show file tree
Hide file tree
Showing 11 changed files with 999 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.PHONY: lint
lint: ## Apply go lint check
@golangci-lint run --timeout 10m ./...
.PHONY: lint

.PHONY: swagger
swagger:
swag fmt && swag init --parseInternal --pd -p snakecase
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ docker run -d --name messenger -p 8888:8888 -v $(pwd)/conf:/messenger/conf --res

## API

> You can also visit http://127.0.0.1:8888/swagger/index.html to check api.
### 发送消息

请求方式:POST
Expand Down Expand Up @@ -132,7 +134,7 @@ func main() {

| 参数(请求体) | 是否必须 | 类型 | 说明 |
| :------------- | :------- | :--- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| body || json | 请求body为您的sender配置,如`{"wechatBot": [{"name": "yourSenderName", "url": "https://xxx"}]`<br>POST:同类型配置会被全部覆盖<br>PUT:同类型同名称的配置会被更新,新配置将被添加<br>DELETE:同类型同名称配置将被删除 |
| body || json | 请求body为您的sender配置,如`{"wechatBot": [{"name": "yourSenderName", "url": "https://xxx"}]}`<br>POST:同类型配置会被全部覆盖<br>PUT:同类型同名称的配置会被更新,新配置将被添加<br>DELETE:同类型同名称配置将被删除 |

返回结果:
```json
Expand Down
337 changes: 337 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"

const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/v1/message": {
"post": {
"description": "send a new message\nhttps://github.com/veops/messenger?tab=readme-ov-file#发送消息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"send"
],
"parameters": [
{
"description": " ",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/send.message"
}
}
],
"responses": {
"200": {
"description": "a map with msg info, eg. {msg:ok}",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/v1/senders": {
"put": {
"description": "push a conf to overwrite(POST), update(PUT) or delete(DELETE) existing conf of senders\nhttps://github.com/veops/messenger?tab=readme-ov-file#更新配置",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"conf"
],
"parameters": [
{
"description": "senders config, eg. {wechatBot: [{name: yourSenderName, url: https://xxx}]}",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
],
"responses": {
"200": {
"description": "a map with msg info, eg. {msg:ok}",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
},
"post": {
"description": "push a conf to overwrite(POST), update(PUT) or delete(DELETE) existing conf of senders\nhttps://github.com/veops/messenger?tab=readme-ov-file#更新配置",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"conf"
],
"parameters": [
{
"description": "senders config, eg. {wechatBot: [{name: yourSenderName, url: https://xxx}]}",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
],
"responses": {
"200": {
"description": "a map with msg info, eg. {msg:ok}",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
},
"delete": {
"description": "push a conf to overwrite(POST), update(PUT) or delete(DELETE) existing conf of senders\nhttps://github.com/veops/messenger?tab=readme-ov-file#更新配置",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"conf"
],
"parameters": [
{
"description": "senders config, eg. {wechatBot: [{name: yourSenderName, url: https://xxx}]}",
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
],
"responses": {
"200": {
"description": "a map with msg info, eg. {msg:ok}",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/v1/uid/getbyphone": {
"post": {
"description": "get user's uid by he or she's phone number\nhttps://github.com/veops/messenger?tab=readme-ov-file#查询用户ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"send"
],
"parameters": [
{
"description": " ",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/send.getUIDByPhoneReq"
}
}
],
"responses": {
"200": {
"description": "a map with phone as key and uid as value",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
},
"definitions": {
"send.getUIDByPhoneReq": {
"type": "object",
"required": [
"phone",
"sender"
],
"properties": {
"phone": {
"type": "string",
"example": "133123456789"
},
"sender": {
"type": "string",
"example": "myWechatBot"
}
}
},
"send.message": {
"type": "object",
"required": [
"content",
"msgtype",
"sender"
],
"properties": {
"at_mobiles": {
"type": "array",
"items": {
"type": "string"
},
"example": [
"133123456789"
]
},
"ats": {
"type": "array",
"items": {
"type": "string"
},
"example": [
"xxx"
]
},
"ccs": {
"type": "array",
"items": {
"type": "string"
},
"example": [
""
]
},
"content": {
"type": "string",
"example": "this is a text content"
},
"extra": {
"type": "string",
"example": "{\"enable_duplicate_check\": 1,\"duplicate_check_interval\": 1800}"
},
"msgtype": {
"type": "string",
"example": "text"
},
"sender": {
"type": "string",
"example": "myWechatBot"
},
"simple": {
"type": "boolean",
"example": true
},
"sync": {
"type": "boolean",
"example": true
},
"title": {
"type": "string",
"example": ""
},
"tos": {
"type": "array",
"items": {
"type": "string"
},
"example": [
""
]
}
}
}
},
"externalDocs": {
"description": "Messenger README",
"url": "https://github.com/veops/messenger?tab=readme-ov-file#messenger"
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}
Loading

0 comments on commit 5daa094

Please sign in to comment.