Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"net/url"
"slices"

"github.com/go-openapi/spec"
"github.com/go-openapi/swag/loading"
Expand Down Expand Up @@ -107,6 +108,18 @@ func (l *loader) Load(path string) (json.RawMessage, error) {
return nil, errors.Join(lastErr, ErrLoads)
}

func (l *loader) clone() *loader {
if l == nil {
return nil
}

return &loader{
DocLoaderWithMatch: l.DocLoaderWithMatch,
loadingOptions: slices.Clone(l.loadingOptions),
Next: l.Next.clone(),
}
}

// JSONDoc loads a json document from either a file or a remote url.
//
// See [loading.Option] for available options (e.g. configuring authentifaction,
Expand Down
4 changes: 4 additions & 0 deletions loaders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ func TestLoader_EdgeCases(t *testing.T) {

_, err := ldr.Load(`d\::invalid uri\`)
require.Error(t, err)

clone := ldr.clone()
cnext := clone.WithHead(nil)
require.Equal(t, clone, cnext)
}
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func loaderFromOptions(options []LoaderOption) *loader {
apply(opts)
}

l := opts.loader
l := opts.loader.clone()
l.loadingOptions = opts.loadingOptions

return l
Expand Down
Loading