danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
885 stars 74 forks source link

Ignore error with "$ref" to markdown #75

Open iShift opened 2 years ago

iShift commented 2 years ago

Currently if an object (tag or other) has link in description (usually used for docs generation in e.g. redoc-cli) - this will lead to error in restish.

I think it would be better to ignore them (or try to download and show)

Example:

"name": "Tag_1",
      "description":{
        "$ref":"markdown/usecases.md"
      }
danielgtaylor commented 2 years ago

Example configuration (~/.restish/apis.json) which triggers this bug:

{
  "do": {
    "base": "https://api.digitalocean.com/v2",
    "profiles": {
      "default": {
        "headers": {
          "authorization": "Bearer ***REDACTED***"
        }
      }
    },
    "spec_files": [
      "https://raw.githubusercontent.com/digitalocean/openapi/main/specification/DigitalOcean-public.v2.yaml"
    ]
  }
}

Error:

$ restish do --help
panic: error unmarshaling JSON: failed to unmarshal property "info" (*openapi3.Info): failed to unmarshal property "description" (*string): json: cannot unmarshal object into Go value of type string

goroutine 1 [running]:
github.com/danielgtaylor/restish/cli.Run()
    /Users/foo/go/pkg/mod/github.com/danielgtaylor/restish@v0.13.1/cli/cli.go:718 +0x99b
main.main()
    /Users/foo/go/pkg/mod/github.com/danielgtaylor/restish@v0.13.1/main.go:27 +0x18a

This will need to be fixed upstream in https://github.com/getkin/kin-openapi, which is the library that loads and dereferences OpenAPI documents.