mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +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:
14
document.go
14
document.go
@@ -10,6 +10,8 @@ import (
|
||||
v3high "github.com/pb33f/libopenapi/datamodel/high/3.0"
|
||||
v2low "github.com/pb33f/libopenapi/datamodel/low/2.0"
|
||||
v3low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Document struct {
|
||||
@@ -40,6 +42,18 @@ func (d *Document) GetSpecInfo() *datamodel.SpecInfo {
|
||||
return d.info
|
||||
}
|
||||
|
||||
func (d *Document) Serialize() ([]byte, error) {
|
||||
if d.info == nil {
|
||||
return nil, fmt.Errorf("unable to serialize, document has not yet been initialized")
|
||||
}
|
||||
if d.info.SpecFileType == datamodel.YAMLFileType {
|
||||
return yaml.Marshal(d.info.RootNode)
|
||||
} else {
|
||||
yamlData, _ := yaml.Marshal(d.info.RootNode)
|
||||
return utils.ConvertYAMLtoJSON(yamlData)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Document) BuildV2Document() (*DocumentModel[v2high.Swagger], []error) {
|
||||
var errors []error
|
||||
if d.info == nil {
|
||||
|
||||
Reference in New Issue
Block a user