mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
2.0 model at 90% coverage
Error handling still required, but a nice jump.
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pb33f/libopenapi/datamodel"
|
||||
high "github.com/pb33f/libopenapi/datamodel/high/3.0"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"fmt"
|
||||
"github.com/pb33f/libopenapi/datamodel"
|
||||
high "github.com/pb33f/libopenapi/datamodel/high/3.0"
|
||||
low "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
testData := `openapi: 3.0.1
|
||||
testData := `openapi: 3.0.1
|
||||
info:
|
||||
title: this is a title
|
||||
description: this is a description
|
||||
@@ -24,28 +24,28 @@ tags:
|
||||
description: coffee
|
||||
x-code: hack`
|
||||
|
||||
data := []byte(testData)
|
||||
_ = ioutil.WriteFile("sample.yaml", data, 0664)
|
||||
data := []byte(testData)
|
||||
_ = ioutil.WriteFile("sample.yaml", data, 0664)
|
||||
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
lowDoc, err := low.CreateDocument(info)
|
||||
if len(err) > 0 {
|
||||
for e := range err {
|
||||
fmt.Printf("%e\n", err[e])
|
||||
}
|
||||
return
|
||||
}
|
||||
highDoc := high.NewDocument(lowDoc)
|
||||
fmt.Println(highDoc.Info.Title)
|
||||
info, _ := datamodel.ExtractSpecInfo(data)
|
||||
lowDoc, err := low.CreateDocument(info)
|
||||
if len(err) > 0 {
|
||||
for e := range err {
|
||||
fmt.Printf("%e\n", err[e])
|
||||
}
|
||||
return
|
||||
}
|
||||
highDoc := high.NewDocument(lowDoc)
|
||||
|
||||
highDoc.Info.GoLow().Title.ValueNode.Value = "let's hack this shizzle"
|
||||
highDoc.Info.GoLow().Title.ValueNode.Value = "let's hack this"
|
||||
highDoc.Tags[0].SetName("We are a new name now")
|
||||
highDoc.Tags[0].SetDescription("and a new description")
|
||||
|
||||
modified, _ := yaml.Marshal(info.RootNode)
|
||||
fmt.Println(string(modified))
|
||||
//newTag := lowDoc.AddTag()
|
||||
//fmt.Println(newTag)
|
||||
modified, _ := yaml.Marshal(info.RootNode)
|
||||
fmt.Println(string(modified))
|
||||
|
||||
d, _ := yaml.Marshal(highDoc.Tags[0])
|
||||
fmt.Println(d)
|
||||
|
||||
os.Remove("sample.yaml")
|
||||
os.Remove("sample.yaml")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user