danielgtaylor / restish

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

API config from spec_files fails for some json files #197

Closed metadatadriven closed 1 year ago

metadatadriven commented 1 year ago

The regex that openapi.go (line 29) used to determine whether a spec is openapi 3 fails for some valid files, for example:

{
  "openapi" : "3.0.0",
  "info" : {
    "title" : "Library API",
    "description" : "REST API documentation for production server",
    "version" : "3.0",
    "contact" : {
      "name" : "Library Support",
      "email" : "foo@bar.org"
    },

Which fails because of the space between the colon which is not defined in the regex:

// reOpenAPI3 is a regex used to detect OpenAPI files from their contents.
var reOpenAPI3 = regexp.MustCompile(`['"]?openapi['"]?:\s*['"]?3`)

The regexp should be:

// reOpenAPI3 is a regex used to detect OpenAPI files from their contents.
var reOpenAPI3 = regexp.MustCompile(`['"]?openapi['"]?\s*:\s*['"]?3`)
danielgtaylor commented 1 year ago

Closing as #198 was merged. Release is coming within the next few days.