kopia lustrzana https://github.com/reiver/greatape
docs(project): 🧑💻 update swagger
rodzic
55fd673f37
commit
9295e98a95
|
@ -16,6 +16,38 @@ const docTemplate = `{
|
||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/.well-known/webfinger": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"WebFinger"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "acct:user@domain.com",
|
||||||
|
"description": "Resource",
|
||||||
|
"name": "resource",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/login": {
|
"/api/v1/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
|
@ -48,6 +80,37 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/profile": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/dto.User"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/signup": {
|
"/api/v1/signup": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
|
@ -111,6 +174,37 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/u/{username}": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"ActivityPub"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Username",
|
||||||
|
"name": "username",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
@ -208,7 +302,7 @@ const docTemplate = `{
|
||||||
"private_profile": {
|
"private_profile": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"publicKey": {
|
"public_key": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
|
@ -255,7 +349,7 @@ var SwaggerInfo = &swag.Spec{
|
||||||
BasePath: "/",
|
BasePath: "/",
|
||||||
Schemes: []string{},
|
Schemes: []string{},
|
||||||
Title: "GreatApe API",
|
Title: "GreatApe API",
|
||||||
Description: "GreatApe is a free audio and video social-media platform that can be used via an app. GreatApe is a Fediverse technology that supports federation via ActivityPub.",
|
Description: "GreatApe is a free audio and video social-media platform that can be used via an app. It is a Fediverse technology that supports federation via ActivityPub.",
|
||||||
InfoInstanceName: "swagger",
|
InfoInstanceName: "swagger",
|
||||||
SwaggerTemplate: docTemplate,
|
SwaggerTemplate: docTemplate,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,45 @@
|
||||||
{
|
{
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "GreatApe is a free audio and video social-media platform that can be used via an app. GreatApe is a Fediverse technology that supports federation via ActivityPub.",
|
"description": "GreatApe is a free audio and video social-media platform that can be used via an app. It is a Fediverse technology that supports federation via ActivityPub.",
|
||||||
"title": "GreatApe API",
|
"title": "GreatApe API",
|
||||||
"contact": {},
|
"contact": {},
|
||||||
"version": "1.0"
|
"version": "1.0"
|
||||||
},
|
},
|
||||||
"basePath": "/",
|
"basePath": "/",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/.well-known/webfinger": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"WebFinger"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "acct:user@domain.com",
|
||||||
|
"description": "Resource",
|
||||||
|
"name": "resource",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/login": {
|
"/api/v1/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
|
@ -40,6 +72,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/profile": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"User"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "Bearer \u003cAdd access token here\u003e",
|
||||||
|
"description": "Insert your access token",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/dto.User"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/signup": {
|
"/api/v1/signup": {
|
||||||
"post": {
|
"post": {
|
||||||
"consumes": [
|
"consumes": [
|
||||||
|
@ -103,6 +166,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/u/{username}": {
|
||||||
|
"get": {
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"ActivityPub"
|
||||||
|
],
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Username",
|
||||||
|
"name": "username",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
|
@ -200,7 +294,7 @@
|
||||||
"private_profile": {
|
"private_profile": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"publicKey": {
|
"public_key": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"username": {
|
"username": {
|
||||||
|
|
|
@ -62,7 +62,7 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
private_profile:
|
private_profile:
|
||||||
type: boolean
|
type: boolean
|
||||||
publicKey:
|
public_key:
|
||||||
type: string
|
type: string
|
||||||
username:
|
username:
|
||||||
type: string
|
type: string
|
||||||
|
@ -89,11 +89,31 @@ definitions:
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
description: GreatApe is a free audio and video social-media platform that can be
|
description: GreatApe is a free audio and video social-media platform that can be
|
||||||
used via an app. GreatApe is a Fediverse technology that supports federation via
|
used via an app. It is a Fediverse technology that supports federation via ActivityPub.
|
||||||
ActivityPub.
|
|
||||||
title: GreatApe API
|
title: GreatApe API
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
paths:
|
paths:
|
||||||
|
/.well-known/webfinger:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- default: acct:user@domain.com
|
||||||
|
description: Resource
|
||||||
|
in: query
|
||||||
|
name: resource
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
additionalProperties: true
|
||||||
|
type: object
|
||||||
|
tags:
|
||||||
|
- WebFinger
|
||||||
/api/v1/login:
|
/api/v1/login:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -114,6 +134,26 @@ paths:
|
||||||
$ref: '#/definitions/dto.LoginResponse'
|
$ref: '#/definitions/dto.LoginResponse'
|
||||||
tags:
|
tags:
|
||||||
- Authentication
|
- Authentication
|
||||||
|
/api/v1/profile:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- default: Bearer <Add access token here>
|
||||||
|
description: Insert your access token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/dto.User'
|
||||||
|
tags:
|
||||||
|
- User
|
||||||
/api/v1/signup:
|
/api/v1/signup:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -154,4 +194,24 @@ paths:
|
||||||
$ref: '#/definitions/dto.VerifyResponse'
|
$ref: '#/definitions/dto.VerifyResponse'
|
||||||
tags:
|
tags:
|
||||||
- Authentication
|
- Authentication
|
||||||
|
/u/{username}:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
parameters:
|
||||||
|
- description: Username
|
||||||
|
in: path
|
||||||
|
name: username
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
additionalProperties: true
|
||||||
|
type: object
|
||||||
|
tags:
|
||||||
|
- ActivityPub
|
||||||
swagger: "2.0"
|
swagger: "2.0"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app/docs"
|
||||||
"app/models/repos"
|
"app/models/repos"
|
||||||
"app/routes"
|
"app/routes"
|
||||||
"caching"
|
"caching"
|
||||||
|
@ -13,9 +14,13 @@ import (
|
||||||
|
|
||||||
// @title GreatApe API
|
// @title GreatApe API
|
||||||
// @version 1.0
|
// @version 1.0
|
||||||
// @description GreatApe is a free audio and video social-media platform that can be used via an app. GreatApe is a Fediverse technology that supports federation via ActivityPub.
|
// @description GreatApe is a free audio and video social-media platform that can be used via an app. It is a Fediverse technology that supports federation via ActivityPub.
|
||||||
// @BasePath /
|
// @BasePath /
|
||||||
func main() {
|
func main() {
|
||||||
|
if config.IsProduction() {
|
||||||
|
docs.SwaggerInfo.Host = config.DOMAIN
|
||||||
|
}
|
||||||
|
|
||||||
logger := logging.CreateLogger(logging.StdIOLogger)
|
logger := logging.CreateLogger(logging.StdIOLogger)
|
||||||
cache := caching.CreateCache(caching.InProcCache)
|
cache := caching.CreateCache(caching.InProcCache)
|
||||||
|
|
||||||
|
|
|
@ -33,15 +33,15 @@ type VerifyResponse struct {
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name,omitempty"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Password string `json:"-"`
|
Password string `json:"-"`
|
||||||
Bio string `json:"bio"`
|
Bio string `json:"bio,omitempty"`
|
||||||
Github string `json:"github"`
|
Github string `json:"github,omitempty"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar,omitempty"`
|
||||||
Banner string `json:"banner"`
|
Banner string `json:"banner,omitempty"`
|
||||||
ApiKey string `json:"api_key"`
|
ApiKey string `json:"api_key,omitempty"`
|
||||||
PublicKey string `json:"publicKey"`
|
PublicKey string `json:"public_key,omitempty"`
|
||||||
Actor string `json:"actor,omitempty"`
|
Actor string `json:"actor,omitempty"`
|
||||||
Webfinger string `json:"webfinger,omitempty"`
|
Webfinger string `json:"webfinger,omitempty"`
|
||||||
PrivateProfile bool `json:"private_profile"`
|
PrivateProfile bool `json:"private_profile"`
|
||||||
|
|
|
@ -10,13 +10,13 @@ import (
|
||||||
"utility/password"
|
"utility/password"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Login godoc
|
// Login godoc
|
||||||
// @Tags Authentication
|
// @Tags Authentication
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param payload body dto.LoginRequest true "Payload"
|
// @Param payload body dto.LoginRequest true "Payload"
|
||||||
// @Success 200 {object} dto.LoginResponse
|
// @Success 200 {object} dto.LoginResponse
|
||||||
// @Router /api/v1/login [post]
|
// @Router /api/v1/login [post]
|
||||||
func _() {}
|
func _() {}
|
||||||
|
|
||||||
var Login = route.New(HttpPost, "/api/v1/login", func(x IContext) error {
|
var Login = route.New(HttpPost, "/api/v1/login", func(x IContext) error {
|
||||||
|
|
|
@ -17,6 +17,15 @@ var Profile = route.New(HttpGet, "/profile", func(x IContext) error {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// GetProfile godoc
|
||||||
|
// @Tags User
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
|
||||||
|
// @Success 200 {object} dto.User
|
||||||
|
// @Router /api/v1/profile [get]
|
||||||
|
func _() {}
|
||||||
|
|
||||||
var GetProfile = route.New(HttpGet, "/api/v1/profile", func(x IContext) error {
|
var GetProfile = route.New(HttpGet, "/api/v1/profile", func(x IContext) error {
|
||||||
user, err := repos.FindUserById(x.GetUser())
|
user, err := repos.FindUserById(x.GetUser())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -11,13 +11,13 @@ import (
|
||||||
"utility/password"
|
"utility/password"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Signup godoc
|
// Signup godoc
|
||||||
// @Tags Authentication
|
// @Tags Authentication
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param payload body dto.SignupRequest true "Payload"
|
// @Param payload body dto.SignupRequest true "Payload"
|
||||||
// @Success 200 {object} dto.SignupResponse
|
// @Success 200 {object} dto.SignupResponse
|
||||||
// @Router /api/v1/signup [post]
|
// @Router /api/v1/signup [post]
|
||||||
func _() {}
|
func _() {}
|
||||||
|
|
||||||
var Signup = route.New(HttpPost, "/api/v1/signup", func(x IContext) error {
|
var Signup = route.New(HttpPost, "/api/v1/signup", func(x IContext) error {
|
||||||
|
@ -63,13 +63,13 @@ var Signup = route.New(HttpPost, "/api/v1/signup", func(x IContext) error {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Verify godoc
|
// Verify godoc
|
||||||
// @Tags Authentication
|
// @Tags Authentication
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param payload body dto.VerifyRequest true "Payload"
|
// @Param payload body dto.VerifyRequest true "Payload"
|
||||||
// @Success 200 {object} dto.VerifyResponse
|
// @Success 200 {object} dto.VerifyResponse
|
||||||
// @Router /api/v1/verify [post]
|
// @Router /api/v1/verify [post]
|
||||||
func _() {}
|
func _() {}
|
||||||
|
|
||||||
var Verify = route.New(HttpPost, "/api/v1/verify", func(x IContext) error {
|
var Verify = route.New(HttpPost, "/api/v1/verify", func(x IContext) error {
|
||||||
|
|
|
@ -8,6 +8,15 @@ import (
|
||||||
"server/route"
|
"server/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// User godoc
|
||||||
|
// @Tags ActivityPub
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param username path string true "Username"
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Router /u/{username} [get]
|
||||||
|
func _() {}
|
||||||
|
|
||||||
var User = route.New(contracts.HttpGet, "/u/:username", func(x contracts.IContext) error {
|
var User = route.New(contracts.HttpGet, "/u/:username", func(x contracts.IContext) error {
|
||||||
username := domain.Username(x.Request().Params("username"))
|
username := domain.Username(x.Request().Params("username"))
|
||||||
if username.IsEmpty() {
|
if username.IsEmpty() {
|
||||||
|
@ -34,7 +43,7 @@ var User = route.New(contracts.HttpGet, "/u/:username", func(x contracts.IContex
|
||||||
|
|
||||||
str := x.StringUtil()
|
str := x.StringUtil()
|
||||||
actor := createActor(user)
|
actor := createActor(user)
|
||||||
if x.Request().AcceptsActivityStream() {
|
if x.Request().AcceptsActivityStream() || x.Request().AcceptsJSON() {
|
||||||
return x.Activity(actor)
|
return x.Activity(actor)
|
||||||
} else if config.ExternalClient() {
|
} else if config.ExternalClient() {
|
||||||
return x.Redirect(str.Format("%s://%s/u/%s", config.PROTOCOL, config.CLIENT_DOMAIN, user.Username))
|
return x.Redirect(str.Format("%s://%s/u/%s", config.PROTOCOL, config.CLIENT_DOMAIN, user.Username))
|
||||||
|
|
|
@ -8,6 +8,15 @@ import (
|
||||||
"server/route"
|
"server/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WebFinger godoc
|
||||||
|
// @Tags WebFinger
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param resource query string true "Resource" default(acct:user@domain.com)
|
||||||
|
// @Success 200 {object} map[string]interface{}
|
||||||
|
// @Router /.well-known/webfinger [get]
|
||||||
|
func _() {}
|
||||||
|
|
||||||
var WebFinger = route.New(HttpGet, "/.well-known/webfinger", func(x IContext) error {
|
var WebFinger = route.New(HttpGet, "/.well-known/webfinger", func(x IContext) error {
|
||||||
resource := x.Request().Query("resource")
|
resource := x.Request().Query("resource")
|
||||||
if !x.StringUtil().Contains(resource, "acct:") {
|
if !x.StringUtil().Contains(resource, "acct:") {
|
||||||
|
|
Ładowanie…
Reference in New Issue