2022-06-16 03:07:38 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
//go:build ignore
|
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/uuid"
|
2023-09-25 17:43:30 +01:00
|
|
|
|
2022-06-16 03:07:38 +01:00
|
|
|
"storj.io/storj/private/apigen"
|
2023-09-25 13:08:33 +01:00
|
|
|
"storj.io/storj/private/apigen/example/myapi"
|
2022-06-16 03:07:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-08-24 17:55:59 +01:00
|
|
|
a := &apigen.API{PackageName: "example", Version: "v0", BasePath: "/api"}
|
2022-06-16 03:07:38 +01:00
|
|
|
|
2023-08-28 14:43:15 +01:00
|
|
|
g := a.Group("Documents", "docs")
|
2022-06-16 03:07:38 +01:00
|
|
|
|
2023-09-25 17:43:30 +01:00
|
|
|
g.Get("/", &apigen.Endpoint{
|
2023-09-27 17:48:01 +01:00
|
|
|
Name: "Get Documents",
|
|
|
|
Description: "Get the paths to all the documents under the specified paths",
|
|
|
|
GoName: "Get",
|
|
|
|
TypeScriptName: "get",
|
2023-09-25 17:43:30 +01:00
|
|
|
Response: []struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
Metadata myapi.Metadata `json:"metadata"`
|
|
|
|
LastRetrievals []struct {
|
|
|
|
User string `json:"user"`
|
|
|
|
When time.Time `json:"when"`
|
|
|
|
} `json:"last_retrievals"`
|
|
|
|
}{},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: []struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
Metadata myapi.Metadata `json:"metadata"`
|
|
|
|
LastRetrievals []struct {
|
|
|
|
User string `json:"user"`
|
|
|
|
When time.Time `json:"when"`
|
|
|
|
} `json:"last_retrievals"`
|
|
|
|
}{{
|
|
|
|
ID: uuid.UUID{},
|
|
|
|
Path: "/workspace/notes.md",
|
|
|
|
Metadata: myapi.Metadata{
|
|
|
|
Owner: "Storj",
|
|
|
|
Tags: [][2]string{{"category", "general"}},
|
|
|
|
},
|
|
|
|
LastRetrievals: []struct {
|
|
|
|
User string `json:"user"`
|
|
|
|
When time.Time `json:"when"`
|
|
|
|
}{{
|
|
|
|
User: "Storj",
|
|
|
|
When: time.Now().Add(-time.Hour),
|
|
|
|
}},
|
|
|
|
}},
|
2023-09-25 17:43:30 +01:00
|
|
|
})
|
|
|
|
|
2023-09-25 13:08:33 +01:00
|
|
|
g.Get("/{path}", &apigen.Endpoint{
|
2023-09-27 17:48:01 +01:00
|
|
|
Name: "Get One",
|
|
|
|
Description: "Get the document in the specified path",
|
|
|
|
GoName: "GetOne",
|
|
|
|
TypeScriptName: "getOne",
|
|
|
|
Response: myapi.Document{},
|
2023-09-25 13:08:33 +01:00
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("path", ""),
|
|
|
|
},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: myapi.Document{
|
|
|
|
ID: uuid.UUID{},
|
|
|
|
Date: time.Now().Add(-24 * time.Hour),
|
|
|
|
PathParam: "ID",
|
|
|
|
Body: "## Notes",
|
|
|
|
Version: myapi.Version{
|
|
|
|
Date: time.Now().Add(-30 * time.Minute),
|
|
|
|
Number: 1,
|
|
|
|
},
|
|
|
|
},
|
2023-09-25 13:08:33 +01:00
|
|
|
})
|
|
|
|
|
2023-09-25 17:43:30 +01:00
|
|
|
g.Get("/{path}/tag/{tagName}", &apigen.Endpoint{
|
2023-09-27 17:48:01 +01:00
|
|
|
Name: "Get a tag",
|
|
|
|
Description: "Get the tag of the document in the specified path and tag label ",
|
|
|
|
GoName: "GetTag",
|
|
|
|
TypeScriptName: "getTag",
|
|
|
|
Response: [2]string{},
|
2023-09-25 17:43:30 +01:00
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("path", ""),
|
|
|
|
apigen.NewParam("tagName", ""),
|
|
|
|
},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: [2]string{"category", "notes"},
|
2023-09-25 17:43:30 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
g.Get("/{path}/versions", &apigen.Endpoint{
|
2023-09-27 17:48:01 +01:00
|
|
|
Name: "Get Version",
|
|
|
|
Description: "Get all the version of the document in the specified path",
|
|
|
|
GoName: "GetVersions",
|
|
|
|
TypeScriptName: "getVersions",
|
|
|
|
Response: []myapi.Version{},
|
2023-09-25 17:43:30 +01:00
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("path", ""),
|
|
|
|
},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: []myapi.Version{
|
|
|
|
{Date: time.Now().Add(-360 * time.Hour), Number: 1},
|
|
|
|
{Date: time.Now().Add(-5 * time.Hour), Number: 2},
|
|
|
|
},
|
2023-09-25 17:43:30 +01:00
|
|
|
})
|
|
|
|
|
2022-06-16 03:07:38 +01:00
|
|
|
g.Post("/{path}", &apigen.Endpoint{
|
2023-09-27 17:48:01 +01:00
|
|
|
Name: "Update Content",
|
|
|
|
Description: "Update the content of the document with the specified path and ID if the last update is before the indicated date",
|
|
|
|
GoName: "UpdateContent",
|
|
|
|
TypeScriptName: "updateContent",
|
2022-06-16 03:07:38 +01:00
|
|
|
Response: struct {
|
2023-08-24 17:28:00 +01:00
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
PathParam string `json:"pathParam"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
}{},
|
|
|
|
Request: struct {
|
|
|
|
Content string `json:"content"`
|
2022-06-16 03:07:38 +01:00
|
|
|
}{},
|
|
|
|
QueryParams: []apigen.Param{
|
|
|
|
apigen.NewParam("id", uuid.UUID{}),
|
|
|
|
apigen.NewParam("date", time.Time{}),
|
|
|
|
},
|
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("path", ""),
|
|
|
|
},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: struct {
|
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
PathParam string `json:"pathParam"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
}{
|
|
|
|
ID: uuid.UUID{},
|
|
|
|
Date: time.Now(),
|
|
|
|
PathParam: "ID",
|
|
|
|
Body: "## Notes\n### General",
|
|
|
|
},
|
2022-06-16 03:07:38 +01:00
|
|
|
})
|
|
|
|
|
2023-10-03 18:27:08 +01:00
|
|
|
g = a.Group("Users", "users")
|
|
|
|
|
|
|
|
g.Get("/", &apigen.Endpoint{
|
|
|
|
Name: "Get Users",
|
|
|
|
Description: "Get the list of registered users",
|
|
|
|
GoName: "Get",
|
|
|
|
TypeScriptName: "get",
|
|
|
|
Response: []struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Surname string `json:"surname"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
}{},
|
2023-10-18 18:54:03 +01:00
|
|
|
ResponseMock: []struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Surname string `json:"surname"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
}{
|
|
|
|
{Name: "Storj", Surname: "Labs", Email: "storj@storj.test"},
|
|
|
|
{Name: "Test1", Surname: "Testing", Email: "test1@example.test"},
|
|
|
|
{Name: "Test2", Surname: "Testing", Email: "test2@example.test"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
g.Post("/", &apigen.Endpoint{
|
|
|
|
Name: "Create User",
|
|
|
|
Description: "Create a user",
|
|
|
|
GoName: "Create",
|
|
|
|
TypeScriptName: "create",
|
|
|
|
Request: []struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Surname string `json:"surname"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
}{},
|
2023-10-03 18:27:08 +01:00
|
|
|
})
|
|
|
|
|
2022-06-16 03:07:38 +01:00
|
|
|
a.MustWriteGo("api.gen.go")
|
2023-08-24 17:28:00 +01:00
|
|
|
a.MustWriteTS("client-api.gen.ts")
|
2023-10-18 18:54:03 +01:00
|
|
|
a.MustWriteTSMock("client-api-mock.gen.ts")
|
2023-08-24 17:28:00 +01:00
|
|
|
a.MustWriteDocs("apidocs.gen.md")
|
2022-06-16 03:07:38 +01:00
|
|
|
}
|