restish
restish copied to clipboard
Getting `Caught error: runtime error: invalid memory address or nil pointer dereference` trying to import basic OpenAPI spec
This tool looks really cool! Unsure if this is a bug or I'm doing something wrong, but I'm unable to sync a basic OpenAPI spec file
Process
On Ubuntu 20.04:
wget https://github.com/danielgtaylor/restish/releases/download/v0.20.0/restish-0.20.0-linux-amd64.tar.gz
tar xfv restish-0.20.0-linux-amd64.tar.gz
./restish api edit
Update config to
{
"$schema": "https://rest.sh/schemas/apis.json",
"myip": {
"base": "https://api.ipify.org/",
"spec_files": ["/home/liam/myip.yaml"]
}
}
create file /home/liam/myip.yaml
with
openapi: 3.1.0
info:
title: My IP
version: 0.0.1
paths:
/:
get:
summary: Get your own IP
operationId: getMyIP
Finally run: ./restish -v api sync myip
Result
DEBUG: Configuration: map[app-name:restish cache-dir:/home/liam/.cache/restish color:true config-directory:/home/liam/.config/restish home-directory:/home/liam rsh-ca-cert: rsh-client-cert: rsh-client-key: rsh-filter: rsh-header:[] rsh-ignore-status-code:false rsh-insecure:false rsh-no-cache:false rsh-no-paginate:false rsh-output-format:auto rsh-profile:default rsh-query:[] rsh-raw:false rsh-retry:2 rsh-server: rsh-timeout:0s rsh-verbose:true server-index:0 tty:true]
DEBUG: API loading took 8.76647ms
ERROR: Caught error: runtime error: invalid memory address or nil pointer dereference
DEBUG: goroutine 1 [running]:
runtime/debug.Stack()
/opt/hostedtoolcache/go/1.18.10/x64/src/runtime/debug/stack.go:24 +0x65
github.com/danielgtaylor/restish/cli.Run.func1()
/home/runner/work/restish/restish/cli/cli.go:849 +0x71
panic({0xf3aa20, 0x19a91e0})
/opt/hostedtoolcache/go/1.18.10/x64/src/runtime/panic.go:838 +0x207
github.com/danielgtaylor/restish/openapi.openapiOperation(_, {_, _}, _, _, _)
/home/runner/work/restish/restish/openapi/openapi.go:416 +0x1d5b
github.com/danielgtaylor/restish/openapi.loadOpenAPI3({0x12f4f58, 0xc00047c0b0}, 0x107f312f406458?, 0xc00018ce10, 0x7f315609c108?)
/home/runner/work/restish/restish/openapi/openapi.go:618 +0x15d2
github.com/danielgtaylor/restish/openapi.(*loader).Load(_, {{0xc00074a660, 0x5}, {0x0, 0x0}, 0x0, {0xc00074a668, 0xd}, {0xc00074a675, 0x1}, ...}, ...)
/home/runner/work/restish/restish/openapi/openapi.go:803 +0x1b1
github.com/danielgtaylor/restish/cli.load(_, {{0xc00074a660, 0x5}, {0x0, 0x0}, 0x0, {0xc00074a668, 0xd}, {0xc00074a675, 0x1}, ...}, ...)
/home/runner/work/restish/restish/cli/api.go:81 +0xe2
github.com/danielgtaylor/restish/cli.Load({0xc00074a660, 0x16}, 0xc00074c300)
/home/runner/work/restish/restish/cli/api.go:180 +0x1aab
github.com/danielgtaylor/restish/cli.initAPIConfig.func5(0xc000018000?, {0xc000741a60, 0x1, 0x2?})
/home/runner/work/restish/restish/cli/apiconfig.go:221 +0x8a
github.com/spf13/cobra.(*Command).execute(0xc000018000, {0xc000741a40, 0x2, 0x2})
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0xc00074c300)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1044 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
github.com/danielgtaylor/restish/cli.Run()
/home/runner/work/restish/restish/cli/cli.go:857 +0x818
main.main()
/home/runner/work/restish/restish/main.go:40 +0x23a
Digging some more, if I update myip.yaml
to include a responses
block as follows:
openapi: 3.1.0
info:
title: My IP
version: 0.0.1
paths:
/:
get:
summary: Get your own IP
operationId: getMyIP
responses:
"200":
description: text body containing your IP address
then it all works.
I don't think (based on https://swagger.io/specification/#operation-object) that the responses block should be required?