Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.13.0 Introducing the Rolodex. #187

Merged
merged 75 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
ec3bf9e
Adding the rolodex
daveshanley Oct 10, 2023
8952d76
Working through the rolodex design.
daveshanley Oct 11, 2023
81902ef
working through rolodex build
daveshanley Oct 12, 2023
de85651
Performing some major surgery on the index
daveshanley Oct 13, 2023
511843e
Major surgery on the index and resolver. A complete flip in design.
daveshanley Oct 14, 2023
8b795c6
working through rolodex design and using it externally via vacuum
daveshanley Oct 15, 2023
d5f72a2
a first working engine of the new design.
daveshanley Oct 16, 2023
cea7bb0
chopping through index changes, basic design works.
daveshanley Oct 16, 2023
0fcd55e
More surgery on rolodex and the index
daveshanley Oct 17, 2023
5197176
Another massive surgical strike with the rolodex and index reshuffle.
daveshanley Oct 18, 2023
48c83dd
resolver tests all operational
daveshanley Oct 18, 2023
7781906
cleaning up a little.
daveshanley Oct 18, 2023
9ee1afe
digital ocean now running correctly
daveshanley Oct 18, 2023
054103b
working through logging now and further tests
daveshanley Oct 18, 2023
b295e8f
bashing through usecases and updating tests as we go.
daveshanley Oct 19, 2023
1bf772a
All spec_index tests pass
daveshanley Oct 20, 2023
afe8945
More fine tuning, handling resolving and edge cases now.
daveshanley Oct 20, 2023
bf270d3
whacking the shit out of exploded use-cases
daveshanley Oct 21, 2023
be7e477
index tests all pass! now time to clean.
daveshanley Oct 21, 2023
28047d0
First sweep at cleaning up dead code
daveshanley Oct 21, 2023
3bf830c
Another round of cleaning.
daveshanley Oct 21, 2023
8717b3c
An enormous amount of surgery on the low level model.
daveshanley Oct 23, 2023
6e9db7f
A massive test update to bring everything inlne with the new `Buildab…
daveshanley Oct 23, 2023
d30ac24
All tests pass! logs of tests fixed and tuning API for high level
daveshanley Oct 24, 2023
5d717bd
Changed document signatures to use `error` instead of `[]error`
daveshanley Oct 24, 2023
c1cf240
Working through test coverage
daveshanley Oct 24, 2023
f644fbb
bumped go version and build
daveshanley Oct 24, 2023
e26897d
Updated logic to handle a single core
daveshanley Oct 24, 2023
b82b46e
Pipeline is failing because it’s hanging somewhere
daveshanley Oct 24, 2023
a87d923
bumping test coverage
daveshanley Oct 25, 2023
eff4166
fixed flaking test
daveshanley Oct 25, 2023
765c7e2
Working through rolodex coverage.
daveshanley Oct 25, 2023
7cf93e8
bumping coverage
daveshanley Oct 26, 2023
3ee631c
working on more tests
daveshanley Oct 27, 2023
d8dfafd
Working through test cases
daveshanley Oct 30, 2023
aca3ed6
Adding more use-cases for resolving remote docs
daveshanley Oct 30, 2023
0cc6698
Adding more logic to resolver to handle mixed usecases
daveshanley Oct 30, 2023
ba8b5ac
more coverage tuning
daveshanley Oct 30, 2023
fde9ede
Working through more coverage
daveshanley Oct 31, 2023
5d41427
more coverage, bumping up rolodex coverage
daveshanley Oct 31, 2023
0b24a5b
flaky test fixed.
daveshanley Oct 31, 2023
9302f7c
whoops.
daveshanley Oct 31, 2023
9746f51
bumping up coverage of the rolodex
daveshanley Oct 31, 2023
0b08a63
more coverage bumps
daveshanley Oct 31, 2023
b37b9a2
more coverage bumps to rolodex
daveshanley Oct 31, 2023
8f3f568
Tuned some glitches with v3 doc creation.
daveshanley Oct 31, 2023
fec9962
ensuring we capture empty responses
daveshanley Oct 31, 2023
3d92d13
added swagger model tests
daveshanley Oct 31, 2023
701c77e
extraction functions coverage bumped back up
daveshanley Oct 31, 2023
720a86c
bumping coverage on utility methods in index.
daveshanley Nov 1, 2023
97659f2
rolodex remote loader coverage at 100%
daveshanley Nov 1, 2023
3c27c43
Added cache set/get for index
daveshanley Nov 1, 2023
33fc552
Another round of coverage
daveshanley Nov 1, 2023
2bc3c67
Removed some dead code that does not need to exist
daveshanley Nov 1, 2023
d096163
Deleting old code that cannot be run anymore.
daveshanley Nov 1, 2023
276c395
Changed remote loader to use a timeout
daveshanley Nov 1, 2023
760a76c
formatted spec index.
daveshanley Nov 1, 2023
cb5e498
is this the one to make it green?
daveshanley Nov 1, 2023
ce4a60b
cleaning up the last few stragglers
daveshanley Nov 1, 2023
80b2b2d
More cleaning and added docs.
daveshanley Nov 1, 2023
8bbb022
Addressed comments from review and fixed bug with schema props
daveshanley Nov 2, 2023
a8a0e1d
added context to schema buildout
daveshanley Nov 2, 2023
713aeec
Tuning parameter exraction for circular ref handling
daveshanley Nov 2, 2023
78763fd
cleaning up unreachable code.
daveshanley Nov 2, 2023
ddb761c
fixed issue with what-changed and path detection #186
daveshanley Nov 2, 2023
fa0b315
Enabling deep array circular reference checking
daveshanley Nov 3, 2023
fde5a99
tuning ref lookups, finding some gaps.
daveshanley Nov 3, 2023
7d8762f
added more coverage and resolved param ref issue
daveshanley Nov 3, 2023
8946afd
removed dead code
daveshanley Nov 3, 2023
f3094d0
Cleanup, sweep-up and tuneup
daveshanley Nov 4, 2023
54f4c82
More coverage tuning and cleaning
daveshanley Nov 4, 2023
f134ac2
updated token for tests
daveshanley Nov 4, 2023
9b92a55
Added in full resolving for specs is virtual filesystems
daveshanley Nov 4, 2023
91edf28
Merge branch 'main' of https://github.com/pb33f/libopenapi into v0.13.0
daveshanley Nov 4, 2023
10fd6e1
fixed merge conflicts
daveshanley Nov 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
id: go

- name: Checkout code
Expand Down
58 changes: 47 additions & 11 deletions datamodel/document_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package datamodel

import (
"net/http"
"github.com/pb33f/libopenapi/utils"
"io/fs"
"log/slog"
"net/url"
"os"
)

// DocumentConfiguration is used to configure the document creation process. It was added in v0.6.0 to allow
Expand All @@ -20,17 +23,47 @@ 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)
RemoteURLHandler utils.RemoteURLHandler

// 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.

// 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

// RemoteFS is a filesystem that will be used to retrieve remote documents. If not set, then the rolodex will
// use its own internal remote filesystem implementation. The RemoteURLHandler will be used to retrieve remote
// documents if it has been set. The default is to use the internal remote filesystem loader.
RemoteFS fs.FS

// LocalFS is a filesystem that will be used to retrieve local documents. If not set, then the rolodex will
// use its own internal local filesystem implementation. The default is to use the internal local filesystem loader.
LocalFS fs.FS

// 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.
Expand All @@ -52,18 +85,21 @@ type DocumentConfiguration struct {
// So if libopenapi is returning circular references for this use case, then this option should be enabled.
// this is disabled by default, which means array circular references will be checked.
IgnoreArrayCircularReferences bool
}

func NewOpenDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
AllowFileReferences: true,
AllowRemoteReferences: true,
}
// SkipCircularReferenceCheck will skip over checking for circular references. This is disabled by default, which
// 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 NewClosedDocumentConfiguration() *DocumentConfiguration {
func NewDocumentConfiguration() *DocumentConfiguration {
return &DocumentConfiguration{
AllowFileReferences: false,
AllowRemoteReferences: false,
Logger: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelError,
})),
}
}
11 changes: 2 additions & 9 deletions datamodel/document_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import (
)

func TestNewClosedDocumentConfiguration(t *testing.T) {
cfg := NewClosedDocumentConfiguration()
assert.False(t, cfg.AllowRemoteReferences)
assert.False(t, cfg.AllowFileReferences)
}

func TestNewOpenDocumentConfiguration(t *testing.T) {
cfg := NewOpenDocumentConfiguration()
assert.True(t, cfg.AllowRemoteReferences)
assert.True(t, cfg.AllowFileReferences)
cfg := NewDocumentConfiguration()
assert.NotNil(t, cfg)
}
3 changes: 2 additions & 1 deletion datamodel/high/base/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"fmt"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand Down Expand Up @@ -70,7 +71,7 @@ email: [email protected]
// build low
var lowContact lowbase.Contact
_ = lowmodel.BuildModel(cNode.Content[0], &lowContact)
_ = lowContact.Build(nil, cNode.Content[0], nil)
_ = lowContact.Build(context.Background(), nil, cNode.Content[0], nil)

// build high
highContact := NewContact(&lowContact)
Expand Down
5 changes: 3 additions & 2 deletions datamodel/high/base/dynamic_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestDynamicValue_MarshalYAMLInline(t *testing.T) {
_ = yaml.Unmarshal([]byte(ymlSchema), &node)

lowProxy := new(lowbase.SchemaProxy)
err := lowProxy.Build(nil, node.Content[0], idx)
err := lowProxy.Build(context.Background(), nil, node.Content[0], idx)
assert.NoError(t, err)

lowRef := low.NodeReference[*lowbase.SchemaProxy]{
Expand Down Expand Up @@ -160,7 +161,7 @@ func TestDynamicValue_MarshalYAMLInline_Error(t *testing.T) {
_ = yaml.Unmarshal([]byte(ymlSchema), &node)

lowProxy := new(lowbase.SchemaProxy)
err := lowProxy.Build(nil, node.Content[0], idx)
err := lowProxy.Build(context.Background(), nil, node.Content[0], idx)
assert.NoError(t, err)

lowRef := low.NodeReference[*lowbase.SchemaProxy]{
Expand Down
7 changes: 4 additions & 3 deletions datamodel/high/base/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"fmt"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand All @@ -29,7 +30,7 @@ x-hack: code`
var lowExample lowbase.Example
_ = lowmodel.BuildModel(cNode.Content[0], &lowExample)

_ = lowExample.Build(&cNode, cNode.Content[0], nil)
_ = lowExample.Build(context.Background(), &cNode, cNode.Content[0], nil)

// build high
highExample := NewExample(&lowExample)
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestExtractExamples(t *testing.T) {
var lowExample lowbase.Example
_ = lowmodel.BuildModel(cNode.Content[0], &lowExample)

_ = lowExample.Build(nil, cNode.Content[0], nil)
_ = lowExample.Build(context.Background(), nil, cNode.Content[0], nil)

examplesMap := make(map[lowmodel.KeyReference[string]]lowmodel.ValueReference[*lowbase.Example])
examplesMap[lowmodel.KeyReference[string]{
Expand Down Expand Up @@ -89,7 +90,7 @@ x-hack: code`
_ = lowmodel.BuildModel(node.Content[0], &lowExample)

// build out low-level example
_ = lowExample.Build(nil, node.Content[0], nil)
_ = lowExample.Build(context.Background(), nil, node.Content[0], nil)

// create a new high-level example
highExample := NewExample(&lowExample)
Expand Down
5 changes: 3 additions & 2 deletions datamodel/high/base/external_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"fmt"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand All @@ -26,7 +27,7 @@ x-hack: code`
var lowExt lowbase.ExternalDoc
_ = lowmodel.BuildModel(cNode.Content[0], &lowExt)

_ = lowExt.Build(nil, cNode.Content[0], nil)
_ = lowExt.Build(context.Background(), nil, cNode.Content[0], nil)

highExt := NewExternalDoc(&lowExt)

Expand Down Expand Up @@ -61,7 +62,7 @@ x-hack: code`
_ = lowmodel.BuildModel(node.Content[0], &lowExt)

// build out low-level properties (like extensions)
_ = lowExt.Build(nil, node.Content[0], nil)
_ = lowExt.Build(context.Background(), nil, node.Content[0], nil)

// create new high-level ExternalDoc
highExt := NewExternalDoc(&lowExt)
Expand Down
11 changes: 6 additions & 5 deletions datamodel/high/base/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -32,7 +33,7 @@ x-cli-name: chicken cli`

var lowInfo lowbase.Info
_ = lowmodel.BuildModel(cNode.Content[0], &lowInfo)
_ = lowInfo.Build(nil, cNode.Content[0], nil)
_ = lowInfo.Build(context.Background(), nil, cNode.Content[0], nil)

highInfo := NewInfo(&lowInfo)

Expand Down Expand Up @@ -74,7 +75,7 @@ version: 1.2.3`
// build out the low-level model
var lowInfo lowbase.Info
_ = lowmodel.BuildModel(&node, &lowInfo)
_ = lowInfo.Build(nil, node.Content[0], nil)
_ = lowInfo.Build(context.Background(), nil, node.Content[0], nil)

// build the high level model
highInfo := NewInfo(&lowInfo)
Expand All @@ -97,7 +98,7 @@ url: https://opensource.org/licenses/MIT`
// build out the low-level model
var lowLicense lowbase.License
_ = lowmodel.BuildModel(node.Content[0], &lowLicense)
_ = lowLicense.Build(nil, node.Content[0], nil)
_ = lowLicense.Build(context.Background(), nil, node.Content[0], nil)

// build the high level model
highLicense := NewLicense(&lowLicense)
Expand Down Expand Up @@ -140,7 +141,7 @@ func TestInfo_Render(t *testing.T) {
// build low
var lowInfo lowbase.Info
_ = lowmodel.BuildModel(cNode.Content[0], &lowInfo)
_ = lowInfo.Build(nil, cNode.Content[0], nil)
_ = lowInfo.Build(context.Background(), nil, cNode.Content[0], nil)

// build high
highInfo := NewInfo(&lowInfo)
Expand Down Expand Up @@ -181,7 +182,7 @@ x-cake:
// build low
var lowInfo lowbase.Info
_ = lowmodel.BuildModel(cNode.Content[0], &lowInfo)
_ = lowInfo.Build(nil, cNode.Content[0], nil)
_ = lowInfo.Build(context.Background(), nil, cNode.Content[0], nil)

// build high
highInfo := NewInfo(&lowInfo)
Expand Down
5 changes: 3 additions & 2 deletions datamodel/high/base/licence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -44,7 +45,7 @@ url: https://pb33f.io/not-real
// build low
var lowLicense lowbase.License
_ = lowmodel.BuildModel(cNode.Content[0], &lowLicense)
_ = lowLicense.Build(nil, cNode.Content[0], nil)
_ = lowLicense.Build(context.Background(), nil, cNode.Content[0], nil)

// build high
highLicense := NewLicense(&lowLicense)
Expand Down Expand Up @@ -92,7 +93,7 @@ func TestLicense_Render_IdentifierAndURL_Error(t *testing.T) {
// build low
var lowLicense lowbase.License
_ = lowmodel.BuildModel(cNode.Content[0], &lowLicense)
err := lowLicense.Build(nil, cNode.Content[0], nil)
err := lowLicense.Build(context.Background(), nil, cNode.Content[0], nil)

assert.Error(t, err)
}
1 change: 0 additions & 1 deletion datamodel/high/base/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ func NewSchema(schema *base.Schema) *Schema {
s.Anchor = schema.Anchor.Value
}

// TODO: check this behavior.
for i := range schema.Enum.Value {
enum = append(enum, schema.Enum.Value[i].Value)
}
Expand Down
3 changes: 2 additions & 1 deletion datamodel/high/base/schema_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package base

import (
"context"
"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestSchemaProxy_MarshalYAML(t *testing.T) {
_ = yaml.Unmarshal([]byte(ymlSchema), &node)

lowProxy := new(lowbase.SchemaProxy)
err := lowProxy.Build(nil, node.Content[0], idx)
err := lowProxy.Build(context.Background(), nil, node.Content[0], idx)
assert.NoError(t, err)

lowRef := low.NodeReference[*lowbase.SchemaProxy]{
Expand Down
Loading