Skip to content

Commit

Permalink
fix: handle circluar refs. and refs. to external spec. correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
masu-mi committed Aug 29, 2022
1 parent 2975544 commit a133d7f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion openapi3/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,8 @@ func (loader *Loader) resolveSchemaRef(doc *T, component *SchemaRef, documentPat
return err
}
component.Value = resolved.Value
documentPath = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
foundPath := loader.getResolvedRefPath(ref, &resolved, documentPath, componentPath)
documentPath = loader.documentPathForRecursiveRef(documentPath, foundPath)
}
}
value := component.Value
Expand Down Expand Up @@ -746,6 +747,22 @@ func (loader *Loader) resolveSchemaRef(doc *T, component *SchemaRef, documentPat
return nil
}

func (loader *Loader) getResolvedRefPath(ref string, resolved *SchemaRef, cur, found *url.URL) string {
referencedFilename := strings.Split(ref, "#")[0]
if referencedFilename == "" {
if cur != nil {
return path.Base(cur.Path)
}
return ""
}
// ref. to external file
if resolved.Ref != "" {
return resolved.Ref
}
// found dest spec. file
return path.Dir(found.Path)[len(loader.rootDir):]
}

func (loader *Loader) resolveSecuritySchemeRef(doc *T, component *SecuritySchemeRef, documentPath *url.URL) (err error) {
if component != nil && component.Value != nil {
if loader.visitedSecurityScheme == nil {
Expand Down

0 comments on commit a133d7f

Please sign in to comment.