docs(project): 🧑‍💻 update swagger

master
Xeronith 2022-09-30 10:28:58 +03:30
rodzic 55fd673f37
commit 9295e98a95
10 zmienionych plików z 308 dodań i 28 usunięć

Wyświetl plik

@ -16,6 +16,38 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"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": {
"post": {
"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": {
"post": {
"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": {
@ -208,7 +302,7 @@ const docTemplate = `{
"private_profile": {
"type": "boolean"
},
"publicKey": {
"public_key": {
"type": "string"
},
"username": {
@ -255,7 +349,7 @@ var SwaggerInfo = &swag.Spec{
BasePath: "/",
Schemes: []string{},
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",
SwaggerTemplate: docTemplate,
}

Wyświetl plik

@ -1,13 +1,45 @@
{
"swagger": "2.0",
"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",
"contact": {},
"version": "1.0"
},
"basePath": "/",
"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": {
"post": {
"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": {
"post": {
"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": {
@ -200,7 +294,7 @@
"private_profile": {
"type": "boolean"
},
"publicKey": {
"public_key": {
"type": "string"
},
"username": {

Wyświetl plik

@ -62,7 +62,7 @@ definitions:
type: integer
private_profile:
type: boolean
publicKey:
public_key:
type: string
username:
type: string
@ -89,11 +89,31 @@ definitions:
info:
contact: {}
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.
used via an app. It is a Fediverse technology that supports federation via ActivityPub.
title: GreatApe API
version: "1.0"
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:
post:
consumes:
@ -114,6 +134,26 @@ paths:
$ref: '#/definitions/dto.LoginResponse'
tags:
- 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:
post:
consumes:
@ -154,4 +194,24 @@ paths:
$ref: '#/definitions/dto.VerifyResponse'
tags:
- 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"

Wyświetl plik

@ -1,6 +1,7 @@
package main
import (
"app/docs"
"app/models/repos"
"app/routes"
"caching"
@ -13,9 +14,13 @@ import (
// @title GreatApe API
// @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 /
func main() {
if config.IsProduction() {
docs.SwaggerInfo.Host = config.DOMAIN
}
logger := logging.CreateLogger(logging.StdIOLogger)
cache := caching.CreateCache(caching.InProcCache)

Wyświetl plik

@ -33,15 +33,15 @@ type VerifyResponse struct {
type User struct {
ID uint `json:"id"`
Username string `json:"username"`
DisplayName string `json:"display_name"`
DisplayName string `json:"display_name,omitempty"`
Email string `json:"email"`
Password string `json:"-"`
Bio string `json:"bio"`
Github string `json:"github"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
ApiKey string `json:"api_key"`
PublicKey string `json:"publicKey"`
Bio string `json:"bio,omitempty"`
Github string `json:"github,omitempty"`
Avatar string `json:"avatar,omitempty"`
Banner string `json:"banner,omitempty"`
ApiKey string `json:"api_key,omitempty"`
PublicKey string `json:"public_key,omitempty"`
Actor string `json:"actor,omitempty"`
Webfinger string `json:"webfinger,omitempty"`
PrivateProfile bool `json:"private_profile"`

Wyświetl plik

@ -10,13 +10,13 @@ import (
"utility/password"
)
// Login godoc
// Login godoc
// @Tags Authentication
// @Accept json
// @Produce json
// @Param payload body dto.LoginRequest true "Payload"
// @Success 200 {object} dto.LoginResponse
// @Router /api/v1/login [post]
// @Param payload body dto.LoginRequest true "Payload"
// @Success 200 {object} dto.LoginResponse
// @Router /api/v1/login [post]
func _() {}
var Login = route.New(HttpPost, "/api/v1/login", func(x IContext) error {

Wyświetl plik

@ -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 {
user, err := repos.FindUserById(x.GetUser())
if err != nil {

Wyświetl plik

@ -11,13 +11,13 @@ import (
"utility/password"
)
// Signup godoc
// Signup godoc
// @Tags Authentication
// @Accept json
// @Produce json
// @Param payload body dto.SignupRequest true "Payload"
// @Success 200 {object} dto.SignupResponse
// @Router /api/v1/signup [post]
// @Param payload body dto.SignupRequest true "Payload"
// @Success 200 {object} dto.SignupResponse
// @Router /api/v1/signup [post]
func _() {}
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
// @Accept json
// @Produce json
// @Param payload body dto.VerifyRequest true "Payload"
// @Success 200 {object} dto.VerifyResponse
// @Router /api/v1/verify [post]
// @Param payload body dto.VerifyRequest true "Payload"
// @Success 200 {object} dto.VerifyResponse
// @Router /api/v1/verify [post]
func _() {}
var Verify = route.New(HttpPost, "/api/v1/verify", func(x IContext) error {

Wyświetl plik

@ -8,6 +8,15 @@ import (
"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 {
username := domain.Username(x.Request().Params("username"))
if username.IsEmpty() {
@ -34,7 +43,7 @@ var User = route.New(contracts.HttpGet, "/u/:username", func(x contracts.IContex
str := x.StringUtil()
actor := createActor(user)
if x.Request().AcceptsActivityStream() {
if x.Request().AcceptsActivityStream() || x.Request().AcceptsJSON() {
return x.Activity(actor)
} else if config.ExternalClient() {
return x.Redirect(str.Format("%s://%s/u/%s", config.PROTOCOL, config.CLIENT_DOMAIN, user.Username))

Wyświetl plik

@ -8,6 +8,15 @@ import (
"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 {
resource := x.Request().Query("resource")
if !x.StringUtil().Contains(resource, "acct:") {