mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-08 05:47:07 +09:00
GO-4459: Update swagger docs
This commit is contained in:
parent
6aa1162061
commit
a9eb7259a1
9 changed files with 75 additions and 75 deletions
|
@ -15,8 +15,8 @@ import (
|
|||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} DisplayCodeResponse "Challenge ID"
|
||||
// @Failure 502 {object} util.ServerError "Internal server error"
|
||||
// @Router /auth/displayCode [post]
|
||||
// @Failure 502 {object} util.ServerError "Internal server error"
|
||||
// @Router /auth/display_code [post]
|
||||
func DisplayCodeHandler(s *AuthService) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
challengeId, err := s.GenerateNewChallenge(c.Request.Context(), "api-test")
|
||||
|
@ -38,18 +38,18 @@ func DisplayCodeHandler(s *AuthService) gin.HandlerFunc {
|
|||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param code query string true "The code retrieved from Anytype Desktop app"
|
||||
// @Param challenge_id query string true "The challenge ID"
|
||||
// @Success 200 {object} TokenResponse "Authentication token"
|
||||
// @Param code query string true "The 4-digit code retrieved from Anytype Desktop app"
|
||||
// @Success 200 {object} TokenResponse "Authentication token"
|
||||
// @Failure 400 {object} util.ValidationError "Invalid input"
|
||||
// @Failure 502 {object} util.ServerError "Internal server error"
|
||||
// @Router /auth/token [get]
|
||||
// @Router /auth/token [post]
|
||||
func TokenHandler(s *AuthService) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
challengeID := c.Query("challenge_id")
|
||||
challengeId := c.Query("challenge_id")
|
||||
code := c.Query("code")
|
||||
|
||||
sessionToken, appKey, err := s.SolveChallengeForToken(c.Request.Context(), challengeID, code)
|
||||
sessionToken, appKey, err := s.SolveChallengeForToken(c.Request.Context(), challengeId, code)
|
||||
errCode := util.MapErrorCode(err,
|
||||
util.ErrToCode(ErrInvalidInput, http.StatusBadRequest),
|
||||
util.ErrToCode(ErrFailedAuthenticate, http.StatusInternalServerError),
|
||||
|
|
|
@ -16,7 +16,7 @@ var (
|
|||
|
||||
type Service interface {
|
||||
GenerateNewChallenge(ctx context.Context, appName string) (string, error)
|
||||
SolveChallengeForToken(ctx context.Context, challengeID, code string) (sessionToken, appKey string, err error)
|
||||
SolveChallengeForToken(ctx context.Context, challengeId string, code string) (sessionToken, appKey string, err error)
|
||||
}
|
||||
|
||||
type AuthService struct {
|
||||
|
@ -39,14 +39,14 @@ func (s *AuthService) GenerateNewChallenge(ctx context.Context, appName string)
|
|||
}
|
||||
|
||||
// SolveChallengeForToken calls AccountLocalLinkSolveChallenge and returns the session token + app key, or an error if it fails.
|
||||
func (s *AuthService) SolveChallengeForToken(ctx context.Context, challengeID, code string) (sessionToken, appKey string, err error) {
|
||||
if challengeID == "" || code == "" {
|
||||
func (s *AuthService) SolveChallengeForToken(ctx context.Context, challengeId string, code string) (sessionToken string, appKey string, err error) {
|
||||
if challengeId == "" || code == "" {
|
||||
return "", "", ErrInvalidInput
|
||||
}
|
||||
|
||||
// Call AccountLocalLinkSolveChallenge to retrieve session token and app key
|
||||
resp := s.mw.AccountLocalLinkSolveChallenge(ctx, &pb.RpcAccountLocalLinkSolveChallengeRequest{
|
||||
ChallengeId: challengeID,
|
||||
ChallengeId: challengeId,
|
||||
Answer: code,
|
||||
})
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@ func main() {
|
|||
body map[string]interface{}
|
||||
}{
|
||||
// auth
|
||||
// {"POST", "/auth/displayCode", nil, nil},
|
||||
// {"GET", "/auth/token?challengeId={challengeId}&code={code}", map[string]interface{}{"challengeId": "6738dfc5cda913aad90e8c2a", "code": "2931"}, nil},
|
||||
// {"POST", "/auth/display_code", nil, nil},
|
||||
// {"POST", "/auth/token?challenge_id={challenge_id}&code={code}", map[string]interface{}{"challenge_id": "6738dfc5cda913aad90e8c2a", "code": "2931"}, nil},
|
||||
|
||||
// export
|
||||
// {"GET", "/spaces/{space_id}/objects/{object_id}/export/{format}", map[string]interface{}{"space_id": testSpaceId, "object_id": testObjectId, "format": "markdown"}, nil},
|
||||
|
|
|
@ -24,7 +24,7 @@ const docTemplate = `{
|
|||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/auth/displayCode": {
|
||||
"/auth/display_code": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -53,7 +53,7 @@ const docTemplate = `{
|
|||
}
|
||||
},
|
||||
"/auth/token": {
|
||||
"get": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -67,15 +67,15 @@ const docTemplate = `{
|
|||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The code retrieved from Anytype Desktop app",
|
||||
"name": "code",
|
||||
"description": "The challenge ID",
|
||||
"name": "challenge_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The challenge ID",
|
||||
"name": "challenge_id",
|
||||
"description": "The 4-digit code retrieved from Anytype Desktop app",
|
||||
"name": "code",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/spaces/{space_id}/objectTypes": {
|
||||
"/spaces/{space_id}/object_types": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -354,7 +354,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"types_and_templates"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve object types in a specific space",
|
||||
"parameters": [
|
||||
|
@ -410,7 +410,7 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/spaces/{space_id}/objectTypes/{typeId}/templates": {
|
||||
"/spaces/{space_id}/object_types/{type_id}/templates": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -419,7 +419,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"types_and_templates"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve a list of templates for a specific object type in a space",
|
||||
"parameters": [
|
||||
|
@ -433,7 +433,7 @@ const docTemplate = `{
|
|||
{
|
||||
"type": "string",
|
||||
"description": "The ID of the object type",
|
||||
"name": "typeId",
|
||||
"name": "type_id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
|
@ -494,7 +494,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve objects in a specific space",
|
||||
"parameters": [
|
||||
|
@ -560,7 +560,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Create a new object in a specific space",
|
||||
"parameters": [
|
||||
|
@ -621,7 +621,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve a specific object in a space",
|
||||
"parameters": [
|
||||
|
@ -675,7 +675,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Update an existing object in a specific space",
|
||||
"parameters": [
|
||||
|
@ -746,7 +746,7 @@ const docTemplate = `{
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"exports"
|
||||
"export"
|
||||
],
|
||||
"summary": "Export an object",
|
||||
"parameters": [
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"host": "localhost:31009",
|
||||
"basePath": "/v1",
|
||||
"paths": {
|
||||
"/auth/displayCode": {
|
||||
"/auth/display_code": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -47,7 +47,7 @@
|
|||
}
|
||||
},
|
||||
"/auth/token": {
|
||||
"get": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -61,15 +61,15 @@
|
|||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The code retrieved from Anytype Desktop app",
|
||||
"name": "code",
|
||||
"description": "The challenge ID",
|
||||
"name": "challenge_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The challenge ID",
|
||||
"name": "challenge_id",
|
||||
"description": "The 4-digit code retrieved from Anytype Desktop app",
|
||||
"name": "code",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
|
@ -339,7 +339,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/spaces/{space_id}/objectTypes": {
|
||||
"/spaces/{space_id}/object_types": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -348,7 +348,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"types_and_templates"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve object types in a specific space",
|
||||
"parameters": [
|
||||
|
@ -404,7 +404,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/spaces/{space_id}/objectTypes/{typeId}/templates": {
|
||||
"/spaces/{space_id}/object_types/{type_id}/templates": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
|
@ -413,7 +413,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"types_and_templates"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve a list of templates for a specific object type in a space",
|
||||
"parameters": [
|
||||
|
@ -427,7 +427,7 @@
|
|||
{
|
||||
"type": "string",
|
||||
"description": "The ID of the object type",
|
||||
"name": "typeId",
|
||||
"name": "type_id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
|
@ -488,7 +488,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve objects in a specific space",
|
||||
"parameters": [
|
||||
|
@ -554,7 +554,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Create a new object in a specific space",
|
||||
"parameters": [
|
||||
|
@ -615,7 +615,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Retrieve a specific object in a space",
|
||||
"parameters": [
|
||||
|
@ -669,7 +669,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"space_objects"
|
||||
"objects"
|
||||
],
|
||||
"summary": "Update an existing object in a specific space",
|
||||
"parameters": [
|
||||
|
@ -740,7 +740,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"exports"
|
||||
"export"
|
||||
],
|
||||
"summary": "Export an object",
|
||||
"parameters": [
|
||||
|
|
|
@ -334,7 +334,7 @@ info:
|
|||
title: Anytype API
|
||||
version: "1.0"
|
||||
paths:
|
||||
/auth/displayCode:
|
||||
/auth/display_code:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -353,20 +353,20 @@ paths:
|
|||
tags:
|
||||
- auth
|
||||
/auth/token:
|
||||
get:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: The code retrieved from Anytype Desktop app
|
||||
in: query
|
||||
name: code
|
||||
required: true
|
||||
type: string
|
||||
- description: The challenge ID
|
||||
in: query
|
||||
name: challenge_id
|
||||
required: true
|
||||
type: string
|
||||
- description: The 4-digit code retrieved from Anytype Desktop app
|
||||
in: query
|
||||
name: code
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
@ -548,7 +548,7 @@ paths:
|
|||
summary: Retrieve a list of members for the specified Space
|
||||
tags:
|
||||
- spaces
|
||||
/spaces/{space_id}/objectTypes:
|
||||
/spaces/{space_id}/object_types:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -591,8 +591,8 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Retrieve object types in a specific space
|
||||
tags:
|
||||
- types_and_templates
|
||||
/spaces/{space_id}/objectTypes/{typeId}/templates:
|
||||
- objects
|
||||
/spaces/{space_id}/object_types/{type_id}/templates:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -604,7 +604,7 @@ paths:
|
|||
type: string
|
||||
- description: The ID of the object type
|
||||
in: path
|
||||
name: typeId
|
||||
name: type_id
|
||||
required: true
|
||||
type: string
|
||||
- description: The number of items to skip before starting to collect the result
|
||||
|
@ -642,7 +642,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Retrieve a list of templates for a specific object type in a space
|
||||
tags:
|
||||
- types_and_templates
|
||||
- objects
|
||||
/spaces/{space_id}/objects:
|
||||
get:
|
||||
consumes:
|
||||
|
@ -688,7 +688,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Retrieve objects in a specific space
|
||||
tags:
|
||||
- space_objects
|
||||
- objects
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -727,7 +727,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Create a new object in a specific space
|
||||
tags:
|
||||
- space_objects
|
||||
- objects
|
||||
/spaces/{space_id}/objects/{object_id}:
|
||||
get:
|
||||
consumes:
|
||||
|
@ -764,7 +764,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Retrieve a specific object in a space
|
||||
tags:
|
||||
- space_objects
|
||||
- objects
|
||||
put:
|
||||
consumes:
|
||||
- application/json
|
||||
|
@ -810,7 +810,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Update an existing object in a specific space
|
||||
tags:
|
||||
- space_objects
|
||||
- objects
|
||||
/spaces/{space_id}/objects/{object_id}/export/{format}:
|
||||
post:
|
||||
consumes:
|
||||
|
@ -856,7 +856,7 @@ paths:
|
|||
$ref: '#/definitions/util.ServerError'
|
||||
summary: Export an object
|
||||
tags:
|
||||
- exports
|
||||
- export
|
||||
securityDefinitions:
|
||||
BasicAuth:
|
||||
type: basic
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
// GetObjectExportHandler exports an object to the specified format
|
||||
//
|
||||
// @Summary Export an object
|
||||
// @Tags exports
|
||||
// @Tags export
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "Space ID"
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// GetObjectsHandler retrieves objects in a specific space
|
||||
//
|
||||
// @Summary Retrieve objects in a specific space
|
||||
// @Tags space_objects
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
|
@ -50,7 +50,7 @@ func GetObjectsHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// GetObjectHandler retrieves a specific object in a space
|
||||
//
|
||||
// @Summary Retrieve a specific object in a space
|
||||
// @Tags space_objects
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
|
@ -84,7 +84,7 @@ func GetObjectHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// CreateObjectHandler creates a new object in a specific space
|
||||
//
|
||||
// @Summary Create a new object in a specific space
|
||||
// @Tags space_objects
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
|
@ -128,7 +128,7 @@ func CreateObjectHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// UpdateObjectHandler updates an existing object in a specific space
|
||||
//
|
||||
// @Summary Update an existing object in a specific space
|
||||
// @Tags space_objects
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
|
@ -172,7 +172,7 @@ func UpdateObjectHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// GetTypesHandler retrieves object types in a specific space
|
||||
//
|
||||
// @Summary Retrieve object types in a specific space
|
||||
// @Tags types_and_templates
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
|
@ -182,7 +182,7 @@ func UpdateObjectHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// @Failure 403 {object} util.UnauthorizedError "Unauthorized"
|
||||
// @Failure 404 {object} util.NotFoundError "Resource not found"
|
||||
// @Failure 502 {object} util.ServerError "Internal server error"
|
||||
// @Router /spaces/{space_id}/objectTypes [get]
|
||||
// @Router /spaces/{space_id}/object_types [get]
|
||||
func GetTypesHandler(s *ObjectService) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
spaceId := c.Param("space_id")
|
||||
|
@ -208,22 +208,22 @@ func GetTypesHandler(s *ObjectService) gin.HandlerFunc {
|
|||
// GetTemplatesHandler retrieves a list of templates for a specific object type in a space
|
||||
//
|
||||
// @Summary Retrieve a list of templates for a specific object type in a space
|
||||
// @Tags types_and_templates
|
||||
// @Tags objects
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param space_id path string true "The ID of the space"
|
||||
// @Param typeId path string true "The ID of the object type"
|
||||
// @Param type_id path string true "The ID of the object type"
|
||||
// @Param offset query int false "The number of items to skip before starting to collect the result set"
|
||||
// @Param limit query int false "The number of items to return" default(100)
|
||||
// @Success 200 {object} map[string][]ObjectTemplate "List of templates"
|
||||
// @Failure 403 {object} util.UnauthorizedError "Unauthorized"
|
||||
// @Failure 404 {object} util.NotFoundError "Resource not found"
|
||||
// @Failure 502 {object} util.ServerError "Internal server error"
|
||||
// @Router /spaces/{space_id}/objectTypes/{typeId}/templates [get]
|
||||
// @Router /spaces/{space_id}/object_types/{type_id}/templates [get]
|
||||
func GetTemplatesHandler(s *ObjectService) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
spaceId := c.Param("space_id")
|
||||
typeId := c.Param("typeId")
|
||||
typeId := c.Param("type_id")
|
||||
offset := c.GetInt("offset")
|
||||
limit := c.GetInt("limit")
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ func (s *Server) NewRouter() *gin.Engine {
|
|||
{
|
||||
// Auth
|
||||
v1.POST("/auth/display_code", auth.DisplayCodeHandler(s.authService))
|
||||
v1.GET("/auth/token", auth.TokenHandler(s.authService))
|
||||
v1.POST("/auth/token", auth.TokenHandler(s.authService))
|
||||
|
||||
// Export
|
||||
v1.POST("/spaces/:space_id/objects/:object_id/export/:format", export.GetObjectExportHandler(s.exportService))
|
||||
v1.GET("/spaces/:space_id/objects/export/:format", export.GetSpaceExportHandler(s.exportService))
|
||||
v1.POST("/spaces/:space_id/objects/export/:format", export.GetSpaceExportHandler(s.exportService))
|
||||
|
||||
// Object
|
||||
v1.GET("/spaces/:space_id/objects", paginator, object.GetObjectsHandler(s.objectService))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue