1- // Copyright 2015 go-swagger maintainers
2- //
3- // Licensed under the Apache License, Version 2.0 (the "License");
4- // you may not use this file except in compliance with the License.
5- // You may obtain a copy of the License at
6- //
7- // http://www.apache.org/licenses/LICENSE-2.0
8- //
9- // Unless required by applicable law or agreed to in writing, software
10- // distributed under the License is distributed on an "AS IS" BASIS,
11- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12- // See the License for the specific language governing permissions and
13- // limitations under the License.
1+ // SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
2+ // SPDX-License-Identifier: Apache-2.0
143
154package spec
165
176import (
7+ "maps"
188 "sync"
199)
2010
2111// ResolutionCache a cache for resolving urls
2212type ResolutionCache interface {
23- Get (string ) (interface {} , bool )
24- Set (string , interface {} )
13+ Get (string ) (any , bool )
14+ Set (string , any )
2515}
2616
2717type simpleCache struct {
2818 lock sync.RWMutex
29- store map [string ]interface {}
19+ store map [string ]any
3020}
3121
3222func (s * simpleCache ) ShallowClone () ResolutionCache {
33- store := make (map [string ]interface {} , len (s .store ))
23+ store := make (map [string ]any , len (s .store ))
3424 s .lock .RLock ()
35- for k , v := range s .store {
36- store [k ] = v
37- }
25+ maps .Copy (store , s .store )
3826 s .lock .RUnlock ()
3927
4028 return & simpleCache {
@@ -43,7 +31,7 @@ func (s *simpleCache) ShallowClone() ResolutionCache {
4331}
4432
4533// Get retrieves a cached URI
46- func (s * simpleCache ) Get (uri string ) (interface {} , bool ) {
34+ func (s * simpleCache ) Get (uri string ) (any , bool ) {
4735 s .lock .RLock ()
4836 v , ok := s .store [uri ]
4937
@@ -52,7 +40,7 @@ func (s *simpleCache) Get(uri string) (interface{}, bool) {
5240}
5341
5442// Set caches a URI
55- func (s * simpleCache ) Set (uri string , data interface {} ) {
43+ func (s * simpleCache ) Set (uri string , data any ) {
5644 s .lock .Lock ()
5745 s .store [uri ] = data
5846 s .lock .Unlock ()
@@ -80,7 +68,7 @@ func initResolutionCache() {
8068}
8169
8270func defaultResolutionCache () * simpleCache {
83- return & simpleCache {store : map [string ]interface {} {
71+ return & simpleCache {store : map [string ]any {
8472 "http://swagger.io/v2/schema.json" : MustLoadSwagger20Schema (),
8573 "http://json-schema.org/draft-04/schema" : MustLoadJSONSchemaDraft04 (),
8674 }}
0 commit comments