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,8 +4,10 @@
package datamodel
import (
"log/slog"
"net/http"
"net/url"
"os"
)
// DocumentConfiguration is used to configure the document creation process. It was added in v0.6.0 to allow
@@ -20,17 +22,38 @@ type DocumentConfiguration struct {
// RemoteURLHandler is a function that will be used to retrieve remote documents. If not set, the default
// remote document getter will be used.
//
// The remote handler is only used if the BaseURL is set. If the BaseURL is not set, then the remote handler
// will not be used, as there will be nothing to use it against.
//
// Resolves [#132]: https://github.com/pb33f/libopenapi/issues/132
RemoteURLHandler func(url string) (*http.Response, error)
// FileFilter is a list of specific files to be included by the rolodex when looking up references. If this value
// is set, then only these specific files will be included. If this value is not set, then all files will be included.
FileFilter []string
// If resolving locally, the BasePath will be the root from which relative references will be resolved from.
// It's usually the location of the root specification.
//
// Be warned, setting this value will instruct the rolodex to index EVERY yaml and JSON file it finds from the
// base path. The rolodex will recurse into every directory and pick up everything form this location down.
//
// To avoid sucking in all the files, set the FileFilter to a list of specific files to be included.
BasePath string // set the Base Path for resolving relative references if the spec is exploded.
// AllowFileReferences will allow the index to locate relative file references. This is disabled by default.
//
// Deprecated: This behavior is now driven by the inclusion of a BasePath. If a BasePath is set, then the
// rolodex will look for relative file references. If no BasePath is set, then the rolodex will not look for
// relative file references. This value has no effect as of version 0.13.0 and will be removed in a future release.
AllowFileReferences bool
// AllowRemoteReferences will allow the index to lookup remote references. This is disabled by default.
//
// Deprecated: This behavior is now driven by the inclusion of a BaseURL. If a BaseURL is set, then the
// rolodex will look for remote references. If no BaseURL is set, then the rolodex will not look for
// remote references. This value has no effect as of version 0.13.0 and will be removed in a future release.
AllowRemoteReferences bool
// AvoidIndexBuild will avoid building the index. This is disabled by default, only use if you are sure you don't need it.
@@ -57,18 +80,26 @@ type DocumentConfiguration struct {
// means circular references will be checked. This is useful for developers building out models that should be
// indexed later on.
SkipCircularReferenceCheck bool
// Logger is a structured logger that will be used for logging errors and warnings. If not set, a default logger
// will be used, set to the Error level.
Logger *slog.Logger
}
func NewDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
Logger: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelError,
})),
}
}
// Deprecated: use NewDocumentConfiguration instead.
func NewOpenDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
AllowFileReferences: true,
AllowRemoteReferences: true,
}
return NewDocumentConfiguration()
}
// Deprecated: use NewDocumentConfiguration instead.
func NewClosedDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
AllowFileReferences: false,
AllowRemoteReferences: false,
}
return NewDocumentConfiguration()
}