mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Working on building out models
a recursive approach? or a dfs approach? not sure yet. still playing with ideas.
This commit is contained in:
19
openapi/create_document.go
Normal file
19
openapi/create_document.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel"
|
||||
v3 "github.com/pb33f/libopenapi/datamodel/low/3.0"
|
||||
)
|
||||
|
||||
func CreateDocument(spec []byte) (*v3.Document, error) {
|
||||
|
||||
// extract details from spec
|
||||
info, err := datamodel.ExtractSpecInfo(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doc := &v3.Document{}
|
||||
doc.Build(info.RootNode.Content[0])
|
||||
return doc, nil
|
||||
}
|
||||
22
openapi/create_document_test.go
Normal file
22
openapi/create_document_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateDocument_NoData(t *testing.T) {
|
||||
doc, err := CreateDocument(nil)
|
||||
assert.Nil(t, doc)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestCreateDocument(t *testing.T) {
|
||||
data, aErr := ioutil.ReadFile("../test_specs/petstorev3.json")
|
||||
assert.NoError(t, aErr)
|
||||
|
||||
doc, err := CreateDocument(data)
|
||||
assert.NotNil(t, doc)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user