mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Added mutate command to low level API
This simple method gives the low API a super powerful and simple way to mutate the value of any node, which is then reflected in the root node, can than be serialized again and, voila! now our spec is editable.
This commit is contained in:
@@ -40,6 +40,10 @@ func (n NodeReference[T]) GenerateMapKey() string {
|
||||
return fmt.Sprintf("%d:%d", n.ValueNode.Line, n.ValueNode.Column)
|
||||
}
|
||||
|
||||
func (n NodeReference[T]) Mutate(value T) {
|
||||
n.ValueNode.Value = fmt.Sprintf("%v", value)
|
||||
}
|
||||
|
||||
func (n ValueReference[T]) IsEmpty() bool {
|
||||
return n.ValueNode == nil
|
||||
}
|
||||
@@ -56,6 +60,10 @@ func (n KeyReference[T]) GenerateMapKey() string {
|
||||
return fmt.Sprintf("%d:%d", n.KeyNode.Line, n.KeyNode.Column)
|
||||
}
|
||||
|
||||
func (n ValueReference[T]) Mutate(value T) {
|
||||
n.ValueNode.Value = fmt.Sprintf("%v", value)
|
||||
}
|
||||
|
||||
func IsCircular(node *yaml.Node, idx *index.SpecIndex) bool {
|
||||
if idx == nil {
|
||||
return false // no index! nothing we can do.
|
||||
|
||||
Reference in New Issue
Block a user