Improve documentation

This commit is contained in:
Jannis Mattheis 2018-02-27 19:52:35 +01:00 committed by Jannis Mattheis
parent 76c7d3244d
commit 3a2da09186
8 changed files with 102 additions and 1 deletions

View File

@ -2,11 +2,22 @@
// //
// This is the documentation of the Gotify REST-API. // This is the documentation of the Gotify REST-API.
// //
// # Authentication
// In Gotify there are two token types:
// __clientToken__: a client is something that receives message and manages stuff like creating new tokens or delete messages. (f.ex this token should be used for an android app)
// __appToken__: an application is something that sends messages (f.ex. this token should be used for a shell script)
//
// The token can be either transmitted through a header named `X-Gotify-Key` or a query parameter named `token`.
// There is also the possibility to authenticate through basic auth, this should only be used for creating a clientToken.
//
// \---
//
// Found a bug or have some questions? [Create an issue on GitHub](https://github.com/gotify/server/issues)
//
// Schemes: http, https // Schemes: http, https
// Host: localhost // Host: localhost
// Version: 1.0.1 // Version: 1.0.1
// License: MIT https://github.com/gotify/server/blob/master/LICENSE // License: MIT https://github.com/gotify/server/blob/master/LICENSE
// Contact: https://github.com/gotify/server/issues
// //
// Consumes: // Consumes:
// - application/json // - application/json

View File

@ -6,9 +6,22 @@ package model
// //
// swagger:model Application // swagger:model Application
type Application struct { type Application struct {
// The application id. Can be used as `appToken`. See Authentication.
//
// read only: true
// required: true
// example: AWH0wZ5r0Mbac.r
ID string `gorm:"primary_key;unique_index" json:"id"` ID string `gorm:"primary_key;unique_index" json:"id"`
UserID uint `gorm:"index" json:"-"` UserID uint `gorm:"index" json:"-"`
// The application name. This is how the application should be displayed to the user.
//
// required: true
// example: Backup Server
Name string `form:"name" query:"name" json:"name" binding:"required"` Name string `form:"name" query:"name" json:"name" binding:"required"`
// The description of the application.
//
// required: true
// example: Backup server for the interwebs
Description string `form:"description" query:"description" json:"description"` Description string `form:"description" query:"description" json:"description"`
Messages []Message `json:"-"` Messages []Message `json:"-"`
} }

View File

@ -6,7 +6,16 @@ package model
// //
// swagger:model Client // swagger:model Client
type Client struct { type Client struct {
// The client id. Can be used as `clientToken`. See Authentication.
//
// read only: true
// required: true
// example: CWH0wZ5r0Mbac.r
ID string `gorm:"primary_key;unique_index" json:"id"` ID string `gorm:"primary_key;unique_index" json:"id"`
UserID uint `gorm:"index" json:"-"` UserID uint `gorm:"index" json:"-"`
// The client name. This is how the client should be displayed to the user.
//
// required: true
// example: Android Phone
Name string `form:"name" query:"name" json:"name" binding:"required"` Name string `form:"name" query:"name" json:"name" binding:"required"`
} }

View File

@ -6,7 +6,19 @@ package model
// //
// swagger:model Error // swagger:model Error
type Error struct { type Error struct {
// The general error message
//
// required: true
// example: Unauthorized
Error string `json:"error"` Error string `json:"error"`
// The http error code.
//
// required: true
// example: 401
ErrorCode int `json:"errorCode"` ErrorCode int `json:"errorCode"`
// The http error code.
//
// required: true
// example: you need to provide a valid access token or user credentials to access this api
ErrorDescription string `json:"errorDescription"` ErrorDescription string `json:"errorDescription"`
} }

View File

@ -8,10 +8,36 @@ import "time"
// //
// swagger:model Message // swagger:model Message
type Message struct { type Message struct {
// The message id.
//
// read only: true
// required: true
// example: 25
ID uint `gorm:"AUTO_INCREMENT;primary_key;index" json:"id"` ID uint `gorm:"AUTO_INCREMENT;primary_key;index" json:"id"`
// The application id that send this message.
//
// read only: true
// required: true
// example: AWH0wZ5r0Mbac.r
ApplicationID string `json:"appid"` ApplicationID string `json:"appid"`
// The actual message.
//
// required: true
// example: Backup was successfully finished.
Message string `form:"message" query:"message" json:"message" binding:"required"` Message string `form:"message" query:"message" json:"message" binding:"required"`
// The title of the message.
//
// required: true
// example: Backup
Title string `form:"title" query:"title" json:"title" binding:"required"` Title string `form:"title" query:"title" json:"title" binding:"required"`
// The priority of the message.
//
// example: 2
Priority int `form:"priority" query:"priority" json:"priority"` Priority int `form:"priority" query:"priority" json:"priority"`
// The date the message was created.
//
// read only: true
// required: true
// example: 2018-02-27T19:36:10.5045044+01:00
Date time.Time `json:"date"` Date time.Time `json:"date"`
} }

View File

@ -16,8 +16,24 @@ type User struct {
// //
// swagger:model User // swagger:model User
type UserExternal struct { type UserExternal struct {
// The user id.
//
// read only: true
// required: true
// example: 25
ID uint `json:"id"` ID uint `json:"id"`
// The user name. For login.
//
// required: true
// example: unicorn
Name string `binding:"required" json:"name" query:"name" form:"name"` Name string `binding:"required" json:"name" query:"name" form:"name"`
// The user password. For login. (Will not be returned by any API)
//
// required: true
// example: mypassword; !will not be returned by any API!
Pass string `json:"pass,omitempty" form:"pass" query:"pass"` Pass string `json:"pass,omitempty" form:"pass" query:"pass"`
// If the user is an administrator.
//
// example: true
Admin bool `json:"admin" form:"admin" query:"admin"` Admin bool `json:"admin" form:"admin" query:"admin"`
} }

View File

@ -4,8 +4,20 @@ package model
// //
// swagger:model VersionInfo // swagger:model VersionInfo
type VersionInfo struct { type VersionInfo struct {
// The current version.
//
// required: true
// example: 5.2.6
Version string `json:"version"` Version string `json:"version"`
// The git commit hash on which this binary was built.
//
// required: true
// example: ae9512b6b6feea56a110d59a3353ea3b9c293864
Commit string `json:"commit"` Commit string `json:"commit"`
// The date on which this binary was built.
//
// required: true
// example: 2018-02-27T19:36:10.5045044+01:00
BuildDate string `json:"buildDate"` BuildDate string `json:"buildDate"`
} }

View File

@ -58,6 +58,8 @@ func Create(db *database.GormDatabase, vInfo *model.VersionInfo, conf *config.Co
// //
// Create a message. // Create a message.
// //
// __NOTE__: This API ONLY accepts an application token as authentication.
//
// --- // ---
// consumes: // consumes:
// - application/json // - application/json