Skip to content

Commit ed8af76

Browse files
authored
Merge pull request #990 from gotify/appid-spec
fix: appid spec
2 parents 0fd65a0 + 5097077 commit ed8af76

3 files changed

Lines changed: 92 additions & 8 deletions

File tree

api/message.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (a *MessageAPI) DeleteMessage(ctx *gin.Context) {
345345
// description: the message to add
346346
// required: true
347347
// schema:
348-
// $ref: "#/definitions/Message"
348+
// $ref: "#/definitions/CreateMessage"
349349
// responses:
350350
// 200:
351351
// description: Ok
@@ -364,7 +364,7 @@ func (a *MessageAPI) DeleteMessage(ctx *gin.Context) {
364364
// schema:
365365
// $ref: "#/definitions/Error"
366366
func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
367-
message := model.MessageExternal{}
367+
message := model.CreateMessage{}
368368
if err := ctx.Bind(&message); err != nil {
369369
return
370370
}
@@ -395,8 +395,6 @@ func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
395395
message.Priority = &app.DefaultPriority
396396
}
397397

398-
message.Date = timeNow()
399-
message.ID = 0
400398
msgInternal := toInternalMessage(&message)
401399
if success := successOrAbort(ctx, 500, a.DB.CreateMessage(msgInternal)); !success {
402400
return
@@ -405,13 +403,12 @@ func (a *MessageAPI) CreateMessage(ctx *gin.Context) {
405403
ctx.JSON(200, toExternalMessage(msgInternal))
406404
}
407405

408-
func toInternalMessage(msg *model.MessageExternal) *model.Message {
406+
func toInternalMessage(msg *model.CreateMessage) *model.Message {
409407
res := &model.Message{
410-
ID: msg.ID,
411408
ApplicationID: msg.ApplicationID,
412409
Message: msg.Message,
413410
Title: msg.Title,
414-
Date: msg.Date,
411+
Date: timeNow(),
415412
}
416413
if msg.Priority != nil {
417414
res.Priority = *msg.Priority

docs/spec.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@
15581558
"in": "body",
15591559
"required": true,
15601560
"schema": {
1561-
"$ref": "#/definitions/Message"
1561+
"$ref": "#/definitions/CreateMessage"
15621562
}
15631563
}
15641564
],
@@ -2746,6 +2746,57 @@
27462746
},
27472747
"x-go-package": "github.com/gotify/server/v2/api"
27482748
},
2749+
"CreateMessage": {
2750+
"description": "The CreateMessage holds information about a message that will be sent.",
2751+
"type": "object",
2752+
"title": "CreateMessage Model",
2753+
"required": [
2754+
"message"
2755+
],
2756+
"properties": {
2757+
"appid": {
2758+
"description": "The application id that send this message. Always set when returned via the API.",
2759+
"type": "integer",
2760+
"format": "int64",
2761+
"x-go-name": "ApplicationID",
2762+
"example": 5
2763+
},
2764+
"extras": {
2765+
"description": "The extra data sent along the message.\n\nThe extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type.\n\nThe keys should be in the following format: \u0026lt;top-namespace\u0026gt;::[\u0026lt;sub-namespace\u0026gt;::]\u0026lt;action\u0026gt;\n\nThese namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes.",
2766+
"type": "object",
2767+
"additionalProperties": {},
2768+
"x-go-name": "Extras",
2769+
"example": {
2770+
"home::appliances::lighting::on": {
2771+
"brightness": 15
2772+
},
2773+
"home::appliances::thermostat::change_temperature": {
2774+
"temperature": 23
2775+
}
2776+
}
2777+
},
2778+
"message": {
2779+
"description": "The message. Markdown (excluding html) is allowed.",
2780+
"type": "string",
2781+
"x-go-name": "Message",
2782+
"example": "**Backup** was successfully finished."
2783+
},
2784+
"priority": {
2785+
"description": "The priority of the message. If unset, then the default priority of the\napplication will be used.",
2786+
"type": "integer",
2787+
"format": "int64",
2788+
"x-go-name": "Priority",
2789+
"example": 2
2790+
},
2791+
"title": {
2792+
"description": "The title of the message.",
2793+
"type": "string",
2794+
"x-go-name": "Title",
2795+
"example": "Backup"
2796+
}
2797+
},
2798+
"x-go-package": "github.com/gotify/server/v2/model"
2799+
},
27492800
"CreateUserExternal": {
27502801
"description": "Used for user creation.",
27512802
"type": "object",

model/message.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,39 @@ type MessageExternal struct {
6464
// example: 2018-02-27T19:36:10.5045044+01:00
6565
Date time.Time `json:"date"`
6666
}
67+
68+
// CreateMessage Model
69+
//
70+
// The CreateMessage holds information about a message that will be sent.
71+
//
72+
// swagger:model CreateMessage
73+
type CreateMessage struct {
74+
// The application id that send this message. Always set when returned via the API.
75+
//
76+
// example: 5
77+
ApplicationID uint `json:"appid"`
78+
// The message. Markdown (excluding html) is allowed.
79+
//
80+
// required: true
81+
// example: **Backup** was successfully finished.
82+
Message string `form:"message" query:"message" json:"message" binding:"required"`
83+
// The title of the message.
84+
//
85+
// example: Backup
86+
Title string `form:"title" query:"title" json:"title"`
87+
// The priority of the message. If unset, then the default priority of the
88+
// application will be used.
89+
//
90+
// example: 2
91+
Priority *int `form:"priority" query:"priority" json:"priority"`
92+
// The extra data sent along the message.
93+
//
94+
// The extra fields are stored in a key-value scheme. Only accepted in CreateMessage requests with application/json content-type.
95+
//
96+
// The keys should be in the following format: <top-namespace>::[<sub-namespace>::]<action>
97+
//
98+
// These namespaces are reserved and might be used in the official clients: gotify android ios web server client. Do not use them for other purposes.
99+
//
100+
// example: {"home::appliances::thermostat::change_temperature":{"temperature":23},"home::appliances::lighting::on":{"brightness":15}}
101+
Extras map[string]any `form:"-" query:"-" json:"extras,omitempty"`
102+
}

0 commit comments

Comments
 (0)