abiosoft / caddy-json-schema

JSON schema generator for Caddy v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors with Caddy 2.2.1

deadlysnek opened this issue · comments

I'm compiling Caddy 2.2.1 with xcaddy using Go 1.14.4 on Ubuntu 20.04.1 LTS

xcaddy build \
    --with github.com/abiosoft/caddy-json-schema \
    --with github.com/caddy-dns/cloudflare

Caddy builds and runs fine, executing caddy json-schema --vscode gives me this message

panic: reflect: call of reflect.Value.Type on zero Value
 
goroutine 1 [running]:
reflect.Value.Type(0x0, 0x0, 0x0, 0xc0006d7130, 0xc00073ee78)
        reflect/value.go:1872 +0x183
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc0008750e0, 0x0, 0x0)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:143 +0xef
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000875050, 0x148df40, 0xc0005c5860)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:132 +0x38e
github.com/abiosoft/caddy-json-schema.(*Interface).populateStruct(0xc000874e10, 0x1a7a5a0, 0x15fbd00)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:186 +0xd4a
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000874e10, 0x15fbd00, 0xc0005305c0)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:120 +0x2ac
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000874d80, 0x1488a80, 0xc0005c5840)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:132 +0x38e
github.com/abiosoft/caddy-json-schema.(*Interface).populateStruct(0xc00073fc88, 0x1a7a5a0, 0x1634e60)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:186 +0xd4a
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc00073fc88, 0x1634e60, 0xc0004142a0)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:120 +0x2ac
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc00073fc88, 0x15a28c0, 0xc000115bc0)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/interface.go:124 +0x14e
github.com/abiosoft/caddy-json-schema.generateSchema(0x0, 0x0)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/schema_util.go:51 +0x159
github.com/abiosoft/caddy-json-schema.run(0xc000115a40, 0xc00003a1a0, 0x1, 0x1)
        github.com/abiosoft/caddy-json-schema@v0.0.0-20200527180432-2d0cb96ed8ea/command.go:67 +0x3d
github.com/caddyserver/caddy/v2/cmd.Main()
        github.com/caddyserver/caddy/v2@v2.2.1/cmd/main.go:85 +0x239
main.main()
        caddy/main.go:13 +0x20

I just got this same error. I see the issue was logged in October. Has anyone looked at this?

Hi. It's caused by passed to f.populate() and is caused by the Outputs []interface{} definition in http.handler.map.
A quick fix would be to add this to interface.go:

func (f *Interface) populate(s interface{}) {

    if s == nil {
        f.Type = "string"
        return
    }

But I don't see how multiple types can be added to the json schema: "type": ["string", "null"] would be better.

@ghostwheel42 Thanks so much.
I have not tested all the functionality.
I just needed to get this module working.

$ caddy json-schema --vscode
json-schema .vscode/caddy_schema.json written.
json-schema .vscode/settings.json written.

Thanks @ghostwheel42 for this. Better late than never :)

Everything should be fine now and the broken documentation has also been fixed for standard and third party plugins.