Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,72 +527,75 @@
return ref, sch, nil
}

func expandParameterOrResponse(input any, resolver *schemaLoader, basePath string) error {
ref, sch, err := getRefAndSchema(input)
if err != nil {
return err
}

if ref == nil && sch == nil { // nothing to do
return nil
}

parentRefs := make([]string, 0, smallPrealloc)
if ref != nil {
// dereference this $ref
if err = resolver.deref(input, parentRefs, basePath); resolver.shouldStopOnError(err) {
return err
}

ref, sch, _ = getRefAndSchema(input)
if ref == nil {
ref = &Ref{} // empty ref
}
}

if ref.String() != "" {
transitiveResolver := resolver.transitiveResolver(basePath, *ref)
basePath = resolver.updateBasePath(transitiveResolver, basePath)
resolver = transitiveResolver
}

if sch == nil {
// nothing to be expanded
if ref != nil {
*ref = Ref{}
}

return nil
}

if sch.Ref.String() != "" {
rebasedRef, ern := NewRef(normalizeURI(sch.Ref.String(), basePath))
if ern != nil {
return ern
}

if resolver.isCircular(&rebasedRef, basePath, parentRefs...) {
// this is a circular $ref: stop expansion
if !resolver.options.AbsoluteCircularRef {
sch.Ref = denormalizeRef(&rebasedRef, resolver.context.basePath, resolver.context.rootID)
} else {
sch.Ref = rebasedRef
}
}
}

// $ref expansion or rebasing is performed by expandSchema below
if ref != nil {
*ref = Ref{}
}

// expand schema
// yes, we do it even if options.SkipSchema is true: we have to go down that rabbit hole and rebase nested $ref)
s, err := expandSchema(*sch, parentRefs, resolver, basePath)
if resolver.shouldStopOnError(err) {
return err
}

if s != nil { // guard for when continuing on error
*sch = *s
}

return nil
}

Check notice on line 601 in expander.go

View check run for this annotation

codefactor.io / CodeFactor

expander.go#L530-L601

Complex Method