@@ -111,11 +111,20 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
111
111
req .Header .Set ("Authorization" , "Bearer " + bearerToken )
112
112
}
113
113
114
- data , err := getWithDefaults (req )
114
+ data , defaulted , err := getWithDefaults (req )
115
115
if err != nil {
116
116
return nil , false , fmt .Errorf ("error loading %s: %v" , url , err )
117
117
}
118
118
119
+ if defaulted != "" {
120
+ pathString = url
121
+ name = defaulted
122
+ if repo != nil {
123
+ repo .Path = path .Join (repo .Path , repo .Name )
124
+ repo .Name = defaulted
125
+ }
126
+ }
127
+
119
128
log .Debugf ("opened %s" , url )
120
129
121
130
result := & source {
@@ -137,31 +146,32 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
137
146
return result , true , nil
138
147
}
139
148
140
- func getWithDefaults (req * http.Request ) ([]byte , error ) {
149
+ func getWithDefaults (req * http.Request ) ([]byte , string , error ) {
141
150
originalPath := req .URL .Path
142
151
143
152
// First, try to get the original path as is. It might be an OpenAPI definition.
144
153
resp , err := http .DefaultClient .Do (req )
145
154
if err != nil {
146
- return nil , err
155
+ return nil , "" , err
147
156
}
148
157
defer resp .Body .Close ()
149
158
150
159
if resp .StatusCode == http .StatusOK {
151
- if toolBytes , err := io .ReadAll (resp .Body ); err == nil && isOpenAPI (toolBytes ) != 0 {
152
- return toolBytes , nil
153
- }
160
+ toolBytes , err := io .ReadAll (resp .Body )
161
+ return toolBytes , "" , err
162
+ }
163
+
164
+ base := path .Base (originalPath )
165
+ if strings .Contains (base , "." ) {
166
+ return nil , "" , fmt .Errorf ("error loading %s: %s" , req .URL .String (), resp .Status )
154
167
}
155
168
156
169
for i , def := range types .DefaultFiles {
157
- base := path .Base (originalPath )
158
- if ! strings .Contains (base , "." ) {
159
- req .URL .Path = path .Join (originalPath , def )
160
- }
170
+ req .URL .Path = path .Join (originalPath , def )
161
171
162
172
resp , err := http .DefaultClient .Do (req )
163
173
if err != nil {
164
- return nil , err
174
+ return nil , "" , err
165
175
}
166
176
defer resp .Body .Close ()
167
177
@@ -170,11 +180,13 @@ func getWithDefaults(req *http.Request) ([]byte, error) {
170
180
}
171
181
172
182
if resp .StatusCode != http .StatusOK {
173
- return nil , fmt .Errorf ("error loading %s: %s" , req .URL .String (), resp .Status )
183
+ return nil , "" , fmt .Errorf ("error loading %s: %s" , req .URL .String (), resp .Status )
174
184
}
175
185
176
- return io .ReadAll (resp .Body )
186
+ data , err := io .ReadAll (resp .Body )
187
+ return data , def , err
177
188
}
189
+
178
190
panic ("unreachable" )
179
191
}
180
192
0 commit comments