Skip to content

Commit 6b0844f

Browse files
committed
fix: better detection of OpenAPI files
1 parent 5ff3f09 commit 6b0844f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

openapi/openapi.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"net/http"
77
"net/url"
8+
"regexp"
89
"sort"
910
"strings"
1011

@@ -15,6 +16,9 @@ import (
1516
"github.com/spf13/cobra"
1617
)
1718

19+
// reOpenAPI3 is a regex used to detect OpenAPI files from their contents.
20+
var reOpenAPI3 = regexp.MustCompile(`['"]?openapi['"]?:\s*['"]?3`)
21+
1822
// OpenAPI Extensions
1923
const (
2024
// Change the CLI name for an operation or parameter
@@ -475,7 +479,7 @@ func (l *loader) Detect(resp *http.Response) bool {
475479
body, _ := ioutil.ReadAll(resp.Body)
476480
defer resp.Body.Close()
477481

478-
if strings.Contains(string(body), "openapi: 3") {
482+
if reOpenAPI3.Match(body) {
479483
return true
480484
}
481485

0 commit comments

Comments
 (0)