Low-level docs for v3 model are now in place

5/6 of the way there!
This commit is contained in:
Dave Shanley
2022-09-21 07:10:58 -04:00
parent d4857ffe05
commit f9016b8414
25 changed files with 351 additions and 88 deletions

View File

@@ -1,6 +1,7 @@
package v3
import (
"fmt"
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
@@ -577,3 +578,28 @@ func TestCreateDocument_ExternalDoc_Error(t *testing.T) {
_, err = CreateDocument(info)
assert.Len(t, err, 1)
}
func ExampleCreateDocument() {
// How to create a low-level OpenAPI 3 Document
// load petstore into bytes
petstoreBytes, _ := ioutil.ReadFile("../../../test_specs/petstorev3.json")
// read in specification
info, _ := datamodel.ExtractSpecInfo(petstoreBytes)
// build low-level document model
document, errors := CreateDocument(info)
// if something went wrong, a slice of errors is returned
if len(errors) > 0 {
for i := range errors {
fmt.Printf("error: %s\n", errors[i].Error())
}
panic("cannot build document")
}
// print out email address from the info > contact object.
fmt.Print(document.Info.Value.Contact.Value.Email.Value)
// Output: apiteam@swagger.io
}