diff --git a/arn/autodocs/Type.go b/arn/autodocs/Type.go index 5872ebe7..5c3ba29c 100644 --- a/arn/autodocs/Type.go +++ b/arn/autodocs/Type.go @@ -16,7 +16,7 @@ type Type struct { // Endpoint returns the REST endpoint for that type. func (typ *Type) Endpoint() string { - return "/api/" + strings.ToLower(typ.Name) + "/" + return "/api/" + strings.ToLower(typ.Name) } // GitHubLink returns link to display the type in GitHub. diff --git a/pages/apiview/api.go b/pages/api/api.go similarity index 97% rename from pages/apiview/api.go rename to pages/api/api.go index 9e812253..6571e034 100644 --- a/pages/apiview/api.go +++ b/pages/api/api.go @@ -1,4 +1,4 @@ -package apiview +package api import ( "path" diff --git a/pages/apiview/api.pixy b/pages/api/api.pixy similarity index 96% rename from pages/apiview/api.pixy rename to pages/api/api.pixy index 89006cf8..2fa04c00 100644 --- a/pages/apiview/api.pixy +++ b/pages/api/api.pixy @@ -1,5 +1,5 @@ component API(types []*autodocs.Type) - .api-docs-page + .api-docs h1.mountable API h2.mountable Endpoints diff --git a/pages/apiview/apidocs/apidocs.scarlet b/pages/api/api.scarlet similarity index 53% rename from pages/apiview/apidocs/apidocs.scarlet rename to pages/api/api.scarlet index ac4da4a4..0357e54e 100644 --- a/pages/apiview/apidocs/apidocs.scarlet +++ b/pages/api/api.scarlet @@ -1,4 +1,4 @@ -.api-docs-page +.api-docs h1, h2, p @@ -10,11 +10,5 @@ .buttons justify-content flex-start -.api-field - // - -.api-field-json - // - -.api-field-type - opacity 0.5 \ No newline at end of file +.api-types + // ... diff --git a/pages/apiview/apidocs/apidocs.go b/pages/api/apitype/type.go similarity index 83% rename from pages/apiview/apidocs/apidocs.go rename to pages/api/apitype/type.go index 10e096ae..b66b4f5c 100644 --- a/pages/apiview/apidocs/apidocs.go +++ b/pages/api/apitype/type.go @@ -1,9 +1,8 @@ -package apidocs +package apitype import ( "reflect" "strings" - "unicode" "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" @@ -17,12 +16,18 @@ func ByType(typeName string) func(aero.Context) error { return func(ctx aero.Context) error { t := arn.API.Type(typeName) fields := []*utils.APIField{} + embedded := []string{} if t.Kind() == reflect.Struct { for i := 0; i < t.NumField(); i++ { field := t.Field(i) - if field.Anonymous || !unicode.IsUpper(rune(field.Name[0])) { + if field.Anonymous { + embedded = append(embedded, field.Name) + continue + } + + if len(field.PkgPath) > 0 { continue } @@ -56,6 +61,6 @@ func ByType(typeName string) func(aero.Context) error { route := "/api/" + strings.ToLower(typeName) + "/:id" examples := routetests.All()[route] - return ctx.HTML(components.APIDocs(t, examples, fields)) + return ctx.HTML(components.APIType(t, examples, fields, embedded)) } } diff --git a/pages/apiview/apidocs/apidocs.pixy b/pages/api/apitype/type.pixy similarity index 74% rename from pages/apiview/apidocs/apidocs.pixy rename to pages/api/apitype/type.pixy index 0617758d..1fb4d7ae 100644 --- a/pages/apiview/apidocs/apidocs.pixy +++ b/pages/api/apitype/type.pixy @@ -1,5 +1,5 @@ -component APIDocs(t reflect.Type, examples []string, fields []*utils.APIField) - .api-docs-page +component APIType(t reflect.Type, examples []string, fields []*utils.APIField, embedded []string) + .api-docs h1.mountable= t.Name() h2.mountable Examples @@ -25,6 +25,13 @@ component APIDocs(t reflect.Type, examples []string, fields []*utils.APIField) tr.api-field.mountable td.api-field-json(title=field.Name + " (Go)")= field.JSON td.api-field-type= field.Type + + if len(embedded) > 0 + h2.mountable Embeds + + ul + each embed in embedded + li.mountable= embed .corner-buttons a.button(href="/api") diff --git a/pages/api/apitype/type.scarlet b/pages/api/apitype/type.scarlet new file mode 100644 index 00000000..3ec1f3b1 --- /dev/null +++ b/pages/api/apitype/type.scarlet @@ -0,0 +1,8 @@ +.api-field + // + +.api-field-json + // + +.api-field-type + opacity 0.5 diff --git a/pages/apiview/api.scarlet b/pages/apiview/api.scarlet deleted file mode 100644 index f9a3ca57..00000000 --- a/pages/apiview/api.scarlet +++ /dev/null @@ -1,2 +0,0 @@ -.api-types - // ... \ No newline at end of file diff --git a/pages/index/apiroutes/apiroutes.go b/pages/index/apiroutes/apiroutes.go index 866cd4ba..fd078093 100644 --- a/pages/index/apiroutes/apiroutes.go +++ b/pages/index/apiroutes/apiroutes.go @@ -7,8 +7,8 @@ import ( "github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/pages/animeimport" "github.com/animenotifier/notify.moe/pages/animelist" - "github.com/animenotifier/notify.moe/pages/apiview" - "github.com/animenotifier/notify.moe/pages/apiview/apidocs" + "github.com/animenotifier/notify.moe/pages/api" + "github.com/animenotifier/notify.moe/pages/api/apitype" "github.com/animenotifier/notify.moe/pages/character" "github.com/animenotifier/notify.moe/pages/database" "github.com/animenotifier/notify.moe/pages/editor/jobs" @@ -26,10 +26,10 @@ import ( // Register registers the page routes. func Register(app *aero.Application) { // API pages - page.Get(app, "/api", apiview.Get) + page.Get(app, "/api", api.Get) for name := range arn.DB.Types() { - page.Get(app, "/api/"+strings.ToLower(name), apidocs.ByType(name)) + page.Get(app, "/api/"+strings.ToLower(name), apitype.ByType(name)) } // API