Skip to content

Commit

Permalink
removed golang x package in favour of the std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
emilien-puget committed Jun 15, 2024
1 parent f27d57a commit d661153
Show file tree
Hide file tree
Showing 44 changed files with 78 additions and 71 deletions.
1 change: 1 addition & 0 deletions datamodel/high/base/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package base

import (
"encoding/json"

"github.com/pb33f/libopenapi/datamodel/high"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base"
Expand Down
1 change: 0 additions & 1 deletion datamodel/high/base/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/pb33f/libopenapi/datamodel"

"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
Expand Down
6 changes: 3 additions & 3 deletions datamodel/high/base/security_requirement.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
// The name used for each property MUST correspond to a security scheme declared in the Security Definitions
// - https://swagger.io/specification/v2/#securityDefinitionsObject
type SecurityRequirement struct {
Requirements *orderedmap.Map[string, []string] `json:"-" yaml:"-"`
ContainsEmptyRequirement bool // if a requirement is empty (this means it's optional)
low *base.SecurityRequirement
Requirements *orderedmap.Map[string, []string] `json:"-" yaml:"-"`
ContainsEmptyRequirement bool // if a requirement is empty (this means it's optional)
low *base.SecurityRequirement
}

// NewSecurityRequirement creates a new high-level SecurityRequirement from a low-level one.
Expand Down
4 changes: 2 additions & 2 deletions datamodel/low/extraction_functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"testing"

"golang.org/x/sync/syncmap"
"gopkg.in/yaml.v3"

"github.com/pb33f/libopenapi/index"
Expand Down Expand Up @@ -1901,7 +1901,7 @@ func TestLocateRefNode_DoARealLookup(t *testing.T) {
idx := index.NewSpecIndexWithConfig(&rootNode, cf)

// fake cache to a lookup for a file that does not exist will work.
fakeCache := new(syncmap.Map)
fakeCache := new(sync.Map)
fakeCache.Store(lookup, &index.Reference{Node: &no, Index: idx})
idx.SetCache(fakeCache)

Expand Down
3 changes: 1 addition & 2 deletions datamodel/low/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"strings"
"testing"

"github.com/pb33f/libopenapi/utils"

"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
Expand Down
2 changes: 1 addition & 1 deletion datamodel/low/v3/create_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"errors"
"path/filepath"
"sync"
"time"

"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/libopenapi/utils"
"time"
)

// CreateDocument will create a new Document instance from the provided SpecInfo.
Expand Down
5 changes: 3 additions & 2 deletions datamodel/spec_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
"strings"
"time"

"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion document_iteration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"slices"
)

type loopFrame struct {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ require (
github.com/stretchr/testify v1.8.4
github.com/vmware-labs/yaml-jsonpath v0.3.2
github.com/wk8/go-ordered-map/v2 v2.1.8
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/sync v0.6.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -87,8 +85,6 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
2 changes: 1 addition & 1 deletion index/extract_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strings"

"github.com/pb33f/libopenapi/utils"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
"slices"
)

// ExtractRefs will return a deduplicated slice of references for every unique ref found in the document.
Expand Down
9 changes: 4 additions & 5 deletions index/index_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"sync"

"github.com/pb33f/libopenapi/datamodel"
"golang.org/x/sync/syncmap"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -236,7 +235,7 @@ type SpecIndex struct {
allRefSchemaDefinitions []*Reference // all schemas found that are references.
allInlineSchemaDefinitions []*Reference // all schemas found in document outside of components (openapi) or definitions (swagger).
allInlineSchemaObjectDefinitions []*Reference // all schemas that are objects found in document outside of components (openapi) or definitions (swagger).
allComponentSchemaDefinitions *syncmap.Map // all schemas found in components (openapi) or definitions (swagger).
allComponentSchemaDefinitions *sync.Map // all schemas found in components (openapi) or definitions (swagger).
securitySchemesNode *yaml.Node // components/securitySchemes node
allSecuritySchemes map[string]*Reference // all security schemes / definitions.
requestBodiesNode *yaml.Node // components/requestBodies node
Expand Down Expand Up @@ -273,7 +272,7 @@ type SpecIndex struct {
componentIndexChan chan bool
polyComponentIndexChan chan bool
resolver *Resolver
cache *syncmap.Map
cache *sync.Map
built bool
uri []string
logger *slog.Logger
Expand All @@ -292,15 +291,15 @@ func (index *SpecIndex) GetConfig() *SpecIndexConfig {
return index.config
}

func (index *SpecIndex) SetCache(sync *syncmap.Map) {
func (index *SpecIndex) SetCache(sync *sync.Map) {
index.cache = sync
}

func (index *SpecIndex) GetNodeMap() map[int]map[int]*yaml.Node {
return index.nodeMap
}

func (index *SpecIndex) GetCache() *syncmap.Map {
func (index *SpecIndex) GetCache() *sync.Map {
return index.cache
}

Expand Down
3 changes: 1 addition & 2 deletions index/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"

"github.com/pb33f/libopenapi/utils"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
"slices"
)

// ResolvingError represents an issue the resolver had trying to stitch the tree together.
Expand Down Expand Up @@ -521,7 +521,6 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
continue
}


value := node.Content[i+1].Value
value = strings.ReplaceAll(value, "\\\\", "\\")
var locatedRef *Reference
Expand Down
6 changes: 3 additions & 3 deletions index/rolodex_file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"slices"
"strings"
"time"
"sync"

"github.com/pb33f/libopenapi/datamodel"
"golang.org/x/sync/syncmap"
"gopkg.in/yaml.v3"
)

Expand All @@ -25,12 +25,12 @@ type LocalFS struct {
indexConfig *SpecIndexConfig
entryPointDirectory string
baseDirectory string
Files syncmap.Map
Files sync.Map
extractedFiles map[string]RolodexFile
logger *slog.Logger
readingErrors []error
rolodex *Rolodex
processingFiles syncmap.Map
processingFiles sync.Map
}

// GetFiles returns the files that have been indexed. A map of RolodexFile objects keyed by the full path of the file.
Expand Down
10 changes: 5 additions & 5 deletions index/rolodex_remote_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/utils"
"golang.org/x/sync/syncmap"
"gopkg.in/yaml.v3"
"sync"
)

const (
Expand All @@ -38,8 +38,8 @@ type RemoteFS struct {
rootURL string
rootURLParsed *url.URL
RemoteHandlerFunc utils.RemoteURLHandler
Files syncmap.Map
ProcessingFiles syncmap.Map
Files sync.Map
ProcessingFiles sync.Map
FetchTime int64
FetchChannel chan *RemoteFile
remoteErrors []error
Expand Down Expand Up @@ -344,10 +344,10 @@ func (i *RemoteFS) Open(remoteURL string) (fs.File, error) {
remoteParsedURL.Host = i.rootURLParsed.Host
remoteParsedURL.Scheme = i.rootURLParsed.Scheme
// this has been disabled, because I don't think it has value, it causes more problems than it solves currently.
//if !strings.HasPrefix(remoteParsedURL.Path, "/") {
// if !strings.HasPrefix(remoteParsedURL.Path, "/") {
// remoteParsedURL.Path = filepath.Join(i.rootURLParsed.Path, remoteParsedURL.Path)
// remoteParsedURL.Path = strings.ReplaceAll(remoteParsedURL.Path, "\\", "/")
//}
// }
}

if remoteParsedURL.Scheme == "" {
Expand Down
3 changes: 1 addition & 2 deletions index/spec_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/pb33f/libopenapi/utils"
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
"golang.org/x/sync/syncmap"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func createNewIndex(rootNode *yaml.Node, index *SpecIndex, avoidBuildOut bool) *
index.nodeMap = make(map[int]map[int]*yaml.Node)
go index.MapNodes(rootNode) // this can run async.

index.cache = new(syncmap.Map)
index.cache = new(sync.Map)

// boot index.
results := index.ExtractRefs(index.root.Content[0], index.root, []string{}, 0, false, "")
Expand Down
4 changes: 2 additions & 2 deletions index/spec_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"time"

"github.com/pb33f/libopenapi/utils"
"golang.org/x/sync/syncmap"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"sync"
)

const (
Expand All @@ -44,7 +44,7 @@ func TestSpecIndex_GetCache(t *testing.T) {
assert.True(t, ok)

// create a new cache
newCache := new(syncmap.Map)
newCache := new(sync.Map)
index.SetCache(newCache)

// check that the cache has been set.
Expand Down
5 changes: 3 additions & 2 deletions renderer/mock_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package renderer
import (
"context"
"encoding/json"
"strings"
"testing"

"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand All @@ -14,8 +17,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
"strings"
"testing"
)

type fakeMockable struct {
Expand Down
2 changes: 1 addition & 1 deletion renderer/schema_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"io"
"math/rand"
"os"
"slices"
"strings"
"time"

"github.com/lucasjones/reggen"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/orderedmap"
"golang.org/x/exp/slices"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion what-changed/model/callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package model

import (
"context"
"testing"

"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)

func TestCompareCallback(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions what-changed/model/change_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package model

import (
"encoding/json"

"gopkg.in/yaml.v3"
)

Expand Down
3 changes: 1 addition & 2 deletions what-changed/model/comparison_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"strings"
"sync"

"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/libopenapi/utils"

"github.com/pb33f/libopenapi/datamodel/low"
"gopkg.in/yaml.v3"
)

Expand Down
3 changes: 2 additions & 1 deletion what-changed/model/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ package model

import (
"context"
"testing"

"github.com/pb33f/libopenapi/datamodel/low"
v2 "github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)

func TestCompareComponents_Swagger_Definitions_Equal(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion what-changed/model/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package model

import (
"context"
"testing"

"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)

func TestCompareContact_URLAdded(t *testing.T) {
Expand Down
Loading

0 comments on commit d661153

Please sign in to comment.