-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pierre Fenoll <[email protected]>
- Loading branch information
Showing
33 changed files
with
553 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
module github.com/getkin/kin-openapi | ||
|
||
go 1.16 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/go-openapi/jsonpointer v0.19.5 | ||
github.com/gorilla/mux v1.8.0 | ||
github.com/invopop/yaml v0.1.0 | ||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 | ||
github.com/stretchr/testify v1.8.1 | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
github.com/wk8/go-ordered-map/v2 v2.1.5 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
github.com/bahlo/generic-list-go v0.2.0 // indirect | ||
github.com/buger/jsonparser v1.1.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/go-openapi/swag v0.19.5 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package openapi2 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
orderedmap "github.com/wk8/go-ordered-map/v2" | ||
) | ||
|
||
type Paths struct { | ||
om *orderedmap.OrderedMap[string, *PathItem] | ||
} | ||
|
||
// MarshalJSON returns the JSON encoding of Paths. | ||
func (paths *Paths) MarshalJSON() ([]byte, error) { | ||
if paths == nil || paths.om == nil { | ||
return []byte("{}"), nil | ||
} | ||
return paths.om.MarshalJSON() | ||
} | ||
|
||
// UnmarshalJSON sets Paths to a copy of data. | ||
func (paths *Paths) UnmarshalJSON(data []byte) error { | ||
return json.Unmarshal(data, &paths.om) | ||
} | ||
|
||
func (paths *Paths) Value(key string) *PathItem { | ||
// if paths == nil || paths.om == nil { | ||
// return nil | ||
// } | ||
return paths.om.Value(key) | ||
} | ||
|
||
func (paths *Paths) Set(key string, value *PathItem) { | ||
// if paths != nil || paths.om != nil { | ||
_, _ = paths.om.Set(key, value) | ||
// } | ||
} | ||
|
||
func (paths *Paths) Len() int { | ||
if paths == nil || paths.om == nil { | ||
return 0 | ||
} | ||
return paths.om.Len() | ||
} | ||
|
||
func (paths *Paths) Iter() *pathsKV { | ||
if paths == nil || paths.om == nil { | ||
return nil | ||
} | ||
return (*pathsKV)(paths.om.Oldest()) | ||
} | ||
|
||
type pathsKV orderedmap.Pair[string, *PathItem] //FIXME: pub? | ||
|
||
func (pair *pathsKV) Next() *pathsKV { | ||
ompair := (*orderedmap.Pair[string, *PathItem])(pair) | ||
return (*pathsKV)(ompair.Next()) | ||
} | ||
|
||
// NewPathsWithCapacity builds a paths object of the given capacity. | ||
func NewPathsWithCapacity(cap int) *Paths { | ||
return &Paths{om: orderedmap.New[string, *PathItem](cap)} | ||
} | ||
|
||
// NewPaths builds a paths object with path items in insertion order. | ||
func NewPaths(opts ...NewPathsOption) *Paths { | ||
paths := NewPathsWithCapacity(len(opts)) | ||
for _, opt := range opts { | ||
opt(paths) | ||
} | ||
return paths | ||
} | ||
|
||
// NewPathsOption describes options to NewPaths func | ||
type NewPathsOption func(*Paths) | ||
|
||
// WithPath adds paths as an option to NewPaths | ||
func WithPath(path string, pathItem *PathItem) NewPathsOption { | ||
return func(paths *Paths) { paths.Set(path, pathItem) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.