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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linters:
- godox
- gosmopolitan
- inamedparam
#- intrange # disabled while < go1.22
- intrange
- ireturn
- lll
- musttag
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

The object model for OpenAPI specification documents.

## Licensing

This library ships under the [SPDX-License-Identifier: Apache-2.0](./LICENSE).

### FAQ

* What does this do?
Expand Down
15 changes: 2 additions & 13 deletions auth_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand Down
34 changes: 11 additions & 23 deletions cache.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

import (
"maps"
"sync"
)

// ResolutionCache a cache for resolving urls
type ResolutionCache interface {
Get(string) (interface{}, bool)
Set(string, interface{})
Get(string) (any, bool)
Set(string, any)
}

type simpleCache struct {
lock sync.RWMutex
store map[string]interface{}
store map[string]any
}

func (s *simpleCache) ShallowClone() ResolutionCache {
store := make(map[string]interface{}, len(s.store))
store := make(map[string]any, len(s.store))
s.lock.RLock()
for k, v := range s.store {
store[k] = v
}
maps.Copy(store, s.store)
s.lock.RUnlock()

return &simpleCache{
Expand All @@ -43,7 +31,7 @@ func (s *simpleCache) ShallowClone() ResolutionCache {
}

// Get retrieves a cached URI
func (s *simpleCache) Get(uri string) (interface{}, bool) {
func (s *simpleCache) Get(uri string) (any, bool) {
s.lock.RLock()
v, ok := s.store[uri]

Expand All @@ -52,7 +40,7 @@ func (s *simpleCache) Get(uri string) (interface{}, bool) {
}

// Set caches a URI
func (s *simpleCache) Set(uri string, data interface{}) {
func (s *simpleCache) Set(uri string, data any) {
s.lock.Lock()
s.store[uri] = data
s.lock.Unlock()
Expand Down Expand Up @@ -80,7 +68,7 @@ func initResolutionCache() {
}

func defaultResolutionCache() *simpleCache {
return &simpleCache{store: map[string]interface{}{
return &simpleCache{store: map[string]any{
"http://swagger.io/v2/schema.json": MustLoadSwagger20Schema(),
"http://json-schema.org/draft-04/schema": MustLoadJSONSchemaDraft04(),
}}
Expand Down
3 changes: 3 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

import (
Expand Down
3 changes: 3 additions & 0 deletions circular_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

import (
Expand Down
15 changes: 2 additions & 13 deletions contact_info.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand Down
17 changes: 3 additions & 14 deletions contact_info_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand All @@ -33,7 +22,7 @@ var contactInfo = ContactInfo{ContactInfoProps: ContactInfoProps{
Name: "wordnik api team",
URL: "http://developer.wordnik.com",
Email: "[email protected]",
}, VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-teams": "test team"}}}
}, VendorExtensible: VendorExtensible{Extensions: map[string]any{"x-teams": "test team"}}}

func TestIntegrationContactInfo(t *testing.T) {
b, err := json.MarshalIndent(contactInfo, "", "\t")
Expand Down
17 changes: 3 additions & 14 deletions debug.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand Down Expand Up @@ -40,7 +29,7 @@ func debugOptions() {
specLogger = log.New(os.Stdout, "spec:", log.LstdFlags)
}

func debugLog(msg string, args ...interface{}) {
func debugLog(msg string, args ...any) {
// A private, trivial trace logger, based on go-openapi/spec/expander.go:debugLog()
if Debug {
_, file1, pos1, _ := runtime.Caller(1)
Expand Down
15 changes: 2 additions & 13 deletions debug_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand Down
3 changes: 3 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

import (
Expand Down
3 changes: 3 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

import "errors"
Expand Down
29 changes: 9 additions & 20 deletions expander.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0

package spec

Expand Down Expand Up @@ -104,7 +93,7 @@ const rootBase = ".root"

// baseForRoot loads in the cache the root document and produces a fake ".root" base path entry
// for further $ref resolution
func baseForRoot(root interface{}, cache ResolutionCache) string {
func baseForRoot(root any, cache ResolutionCache) string {
// cache the root document to resolve $ref's
normalizedBase := normalizeBase(rootBase)

Expand All @@ -116,7 +105,7 @@ func baseForRoot(root interface{}, cache ResolutionCache) string {
return normalizedBase
}

root = map[string]interface{}{}
root = map[string]any{}
}

cache.Set(normalizedBase, root)
Expand All @@ -132,7 +121,7 @@ func baseForRoot(root interface{}, cache ResolutionCache) string {
// (use ExpandSchemaWithBasePath to resolve external references).
//
// Setting the cache is optional and this parameter may safely be left to nil.
func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error {
func ExpandSchema(schema *Schema, root any, cache ResolutionCache) error {
cache = cacheOrDefault(cache)
if root == nil {
root = schema
Expand Down Expand Up @@ -463,7 +452,7 @@ func expandOperation(op *Operation, resolver *schemaLoader, basePath string) err
// (use ExpandResponse to resolve external references).
//
// Setting the cache is optional and this parameter may safely be left to nil.
func ExpandResponseWithRoot(response *Response, root interface{}, cache ResolutionCache) error {
func ExpandResponseWithRoot(response *Response, root any, cache ResolutionCache) error {
cache = cacheOrDefault(cache)
opts := &ExpandOptions{
RelativeBase: baseForRoot(root, cache),
Expand All @@ -489,7 +478,7 @@ func ExpandResponse(response *Response, basePath string) error {
//
// Notice that it is impossible to reference a json schema in a different document other than root
// (use ExpandParameter to resolve external references).
func ExpandParameterWithRoot(parameter *Parameter, root interface{}, cache ResolutionCache) error {
func ExpandParameterWithRoot(parameter *Parameter, root any, cache ResolutionCache) error {
cache = cacheOrDefault(cache)

opts := &ExpandOptions{
Expand All @@ -512,7 +501,7 @@ func ExpandParameter(parameter *Parameter, basePath string) error {
return expandParameterOrResponse(parameter, resolver, opts.RelativeBase)
}

func getRefAndSchema(input interface{}) (*Ref, *Schema, error) {
func getRefAndSchema(input any) (*Ref, *Schema, error) {
var (
ref *Ref
sch *Schema
Expand All @@ -538,7 +527,7 @@ func getRefAndSchema(input interface{}) (*Ref, *Schema, error) {
return ref, sch, nil
}

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