Show embeds in type documentation
This commit is contained in:
parent
cafb43aa17
commit
ab81556651
@ -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.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package apiview
|
||||
package api
|
||||
|
||||
import (
|
||||
"path"
|
@ -1,5 +1,5 @@
|
||||
component API(types []*autodocs.Type)
|
||||
.api-docs-page
|
||||
.api-docs
|
||||
h1.mountable API
|
||||
|
||||
h2.mountable Endpoints
|
@ -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
|
||||
.api-types
|
||||
// ...
|
@ -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))
|
||||
}
|
||||
}
|
@ -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
|
||||
@ -26,6 +26,13 @@ component APIDocs(t reflect.Type, examples []string, fields []*utils.APIField)
|
||||
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")
|
||||
Icon("code")
|
8
pages/api/apitype/type.scarlet
Normal file
8
pages/api/apitype/type.scarlet
Normal file
@ -0,0 +1,8 @@
|
||||
.api-field
|
||||
//
|
||||
|
||||
.api-field-json
|
||||
//
|
||||
|
||||
.api-field-type
|
||||
opacity 0.5
|
@ -1,2 +0,0 @@
|
||||
.api-types
|
||||
// ...
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user