V2 swagger model in place

tests being written to validate and flush out bugs
This commit is contained in:
Dave Shanley
2022-09-03 13:30:53 -04:00
parent 8929db5868
commit 1814ac58eb
17 changed files with 1161 additions and 90 deletions

View File

@@ -1,30 +1,51 @@
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"
)
func main() {
// testData := `openapi: 3.0.1
//info:
// title: this is a title
// description: this is a description`
//
// 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)
// highDoc.Info.GoLow().Title.ValueNode.Value = "let's hack this shizzle"
//
// modified, _ := yaml.Marshal(info.RootNode)
// fmt.Println(string(modified))
testData := `openapi: 3.0.1
info:
title: this is a title
description: this is a description
tags:
- name: Tag A
description: cake
x-hack: true
- name: Tag B
description: coffee
x-code: hack`
//os.Remove("sample.yaml")
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)
highDoc.Info.GoLow().Title.ValueNode.Value = "let's hack this shizzle"
modified, _ := yaml.Marshal(info.RootNode)
fmt.Println(string(modified))
d, _ := yaml.Marshal(highDoc.Tags[0])
fmt.Println(d)
os.Remove("sample.yaml")
}