All tests pass! logs of tests fixed and tuning API for high level

Document configuration has been simplified, no more need for AllowRemote stuff in the document configuration, it’s assumed by setting the baseURL or the basePath.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-10-24 10:24:19 -04:00
parent 6e9db7f838
commit d30ac24db9
38 changed files with 734 additions and 647 deletions

View File

@@ -4,9 +4,11 @@
package libopenapi
import (
"bytes"
"fmt"
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/index"
"log/slog"
"net/url"
"os"
"strings"
@@ -64,13 +66,24 @@ func ExampleNewDocument_fromWithDocumentConfigurationFailure() {
digitalOcean, _ := os.ReadFile("test_specs/digitalocean.yaml")
// create a DocumentConfiguration that prevents loading file and remote references
config := datamodel.DocumentConfiguration{
AllowFileReferences: false,
AllowRemoteReferences: false,
}
config := datamodel.NewDocumentConfiguration()
// create a new structured logger to capture error logs that will be spewed out by the rolodex
// when it tries to load external references. We're going to create a byte buffer to capture the logs
// and then look at them after the document is built.
var logs []byte
buf := bytes.NewBuffer(logs)
logger := slog.New(slog.NewTextHandler(buf, &slog.HandlerOptions{
Level: slog.LevelError,
}))
config.Logger = logger // set the config logger to our new logger.
// Do not set any baseURL, as this will allow the rolodex to resolve relative references.
// without a baseURL (for remote references, or a basePath for local references) the rolodex
// will consider the reference to be local, and will not attempt to load it from the network.
// create a new document from specification bytes
doc, err := NewDocumentWithConfiguration(digitalOcean, &config)
doc, err := NewDocumentWithConfiguration(digitalOcean, config)
// if anything went wrong, an error is thrown
if err != nil {
@@ -80,11 +93,16 @@ func ExampleNewDocument_fromWithDocumentConfigurationFailure() {
// only errors will be thrown, so just capture them and print the number of errors.
_, errors := doc.BuildV3Model()
// there should be 475 errors logs
logItems := strings.Split(buf.String(), "\n")
fmt.Printf("There are %d errors logged\n", len(logItems))
// if anything went wrong when building the v3 model, a slice of errors will be returned
if len(errors) > 0 {
fmt.Println("Error building Digital Ocean spec errors reported")
}
// Output: Error building Digital Ocean spec errors reported
// Output: There are 475 errors logged
//Error building Digital Ocean spec errors reported
}
func ExampleNewDocument_fromWithDocumentConfigurationSuccess() {