From 89c3074da32423cfbb132b83818b0479383995ad Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Mon, 4 Jan 2021 14:05:15 +0100 Subject: [PATCH] work on remaining bug with nested schema ID Signed-off-by: Frederic BIDON --- circular_test.go | 3 ++- expander.go | 1 + schema_loader.go | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/circular_test.go b/circular_test.go index 4e11a7a..1718047 100644 --- a/circular_test.go +++ b/circular_test.go @@ -195,11 +195,12 @@ func TestExpandCircular_RemoteCircularID(t *testing.T) { }) t.Run("withID", func(t *testing.T) { + t.SkipNow() // TODO(fred) Debug = true - t.SkipNow() // TODO(fredbi) const fixturePath = "fixtures/more_circulars/with-id.json" jazon := expandThisOrDieTrying(t, fixturePath) t.Log(jazon) + Debug = false // cannot guarantee that the circular will always hook on the same $ref // but we can assert that thre is only one diff --git a/expander.go b/expander.go index 362a2a0..14c2eee 100644 --- a/expander.go +++ b/expander.go @@ -204,6 +204,7 @@ func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader, ba if target.ID != "" { var parent string basePath, parent = resolver.setSchemaID(target, target.ID, basePath, pointer) + // TODO(fred): do we need this? resolver = resolver.transitiveResolver(basePath, MustCreateRef(parent)) // add normalized ID to the list of parents, in order to detect cycles parentRefs = append(parentRefs, parent) diff --git a/schema_loader.go b/schema_loader.go index 7e06711..f917e20 100644 --- a/schema_loader.go +++ b/schema_loader.go @@ -405,6 +405,8 @@ func (r *schemaLoader) setSchemaID(target interface{}, id, basePath, pointer str r.context.rootID = id } + // u, _ := url.Parse(refPath) + // remembers the schema id's encountered // r.context.ids[id] = true @@ -412,6 +414,8 @@ func (r *schemaLoader) setSchemaID(target interface{}, id, basePath, pointer str // * important: ID can be a relative path // * registers target to be fetchable from the new base proposed by this id newBasePath := normalizePaths(refPath, basePath) + debugLog("newBasePath: %s", newBasePath) + // debugLog("pointer: %s, %s", pointer, u.Path) // store found IDs for possible future reuse in $ref if _, found := r.cache.Get(newBasePath); !found {