Skip to content

Commit c156d56

Browse files
authored
fix: get remote file before appending default file names (#538)
Signed-off-by: Grant Linville <[email protected]>
1 parent efe806f commit c156d56

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/loader/url.go

+14
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
133133

134134
func getWithDefaults(req *http.Request) ([]byte, error) {
135135
originalPath := req.URL.Path
136+
137+
// First, try to get the original path as is. It might be an OpenAPI definition.
138+
resp, err := http.DefaultClient.Do(req)
139+
if err != nil {
140+
return nil, err
141+
}
142+
defer resp.Body.Close()
143+
144+
if resp.StatusCode == http.StatusOK {
145+
if toolBytes, err := io.ReadAll(resp.Body); err == nil && isOpenAPI(toolBytes) != 0 {
146+
return toolBytes, nil
147+
}
148+
}
149+
136150
for i, def := range types.DefaultFiles {
137151
base := path.Base(originalPath)
138152
if !strings.Contains(base, ".") {

0 commit comments

Comments
 (0)