@@ -92,7 +92,7 @@ type resolverContext struct {
9292 rootID string
9393 // ids holds all inherited $id for the current schema.
9494 // This is used to try alternate paths to resolve $ref.
95- //ids map[string]bool
95+ // ids map[string]bool
9696}
9797
9898func newResolverContext (expandOptions * ExpandOptions ) * resolverContext {
@@ -185,14 +185,12 @@ func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath, pointe
185185 if (ref .IsRoot () || ref .HasFragmentOnly ) && root == nil {
186186 if basePath != "" {
187187 debugLog ("fetch from basePath: %s" , basePath )
188- if baseRef , erb := NewRef (basePath ); erb == nil {
189- root , _ , _ , _ = r .load (baseRef .GetURL ())
190- }
188+ baseRef := MustCreateRef (basePath )
189+ root , _ = r .load (baseRef .GetURL ())
191190 } else {
192191 debugLog ("fetch from root in RelativeBase: %s" , r .options .RelativeBase )
193- if baseRef , erb := NewRef (r .options .RelativeBase ); erb == nil {
194- root , _ , _ , _ = r .load (baseRef .GetURL ())
195- }
192+ baseRef := MustCreateRef (r .options .RelativeBase )
193+ root , _ = r .load (baseRef .GetURL ())
196194 }
197195 }
198196
@@ -202,7 +200,7 @@ func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath, pointe
202200 if (ref .IsRoot () || ref .HasFragmentOnly ) && root != nil {
203201 data = root
204202 } else {
205- data , _ , _ , err = r .load (baseRef .GetURL ())
203+ data , err = r .load (baseRef .GetURL ())
206204 if err != nil {
207205 return err
208206 }
@@ -244,7 +242,7 @@ func (r *schemaLoader) resolveRef(ref *Ref, target interface{}, basePath, pointe
244242 return swag .DynamicJSONToStruct (res , target )
245243}
246244
247- func (r * schemaLoader ) load (refURL * url.URL ) (interface {}, url. URL , bool , error ) { // TODO: simplify return values
245+ func (r * schemaLoader ) load (refURL * url.URL ) (interface {}, error ) {
248246 debugLog ("loading schema from url: %s" , refURL )
249247 toFetch := * refURL
250248 toFetch .Fragment = ""
@@ -254,7 +252,7 @@ func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error)
254252 if pth == rootBase {
255253 pth , err = absPath (rootBase )
256254 if err != nil {
257- return nil , url. URL {}, false , err
255+ return nil , err
258256 }
259257 }
260258 normalized := normalizeAbsPath (pth )
@@ -263,20 +261,20 @@ func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error)
263261 if ! fromCache {
264262 b , err := r .context .loadDoc (normalized )
265263 if err != nil {
266- return nil , url. URL {}, false , fmt .Errorf ("%s [%s]: %w" , pth , normalized , err )
264+ return nil , fmt .Errorf ("%s [normalized: %s]: %w" , pth , normalized , err )
267265 }
268266
269267 var doc interface {}
270268 if err := json .Unmarshal (b , & doc ); err != nil {
271- return nil , url. URL {}, false , err
269+ return nil , err
272270 }
273271
274272 r .cache .Set (normalized , doc )
275273
276- return doc , toFetch , fromCache , nil
274+ return doc , nil
277275 }
278276
279- return data , toFetch , fromCache , nil
277+ return data , nil
280278}
281279
282280// isCircular detects cycles in sequences of $ref.
@@ -408,7 +406,7 @@ func (r *schemaLoader) setSchemaID(target interface{}, id, basePath, pointer str
408406 }
409407
410408 // remembers the schema id's encountered
411- //r.context.ids[id] = true
409+ // r.context.ids[id] = true
412410
413411 // updates the current base path
414412 // * important: ID can be a relative path
0 commit comments