-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
35 changed files
with
521 additions
and
281 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
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.