Skip to content

Commit

Permalink
work on remaining bug with nested schema ID
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Jan 4, 2021
1 parent 55dd5ff commit 89c3074
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion circular_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions schema_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,17 @@ 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

// updates the current base path
// * 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 {
Expand Down

0 comments on commit 89c3074

Please sign in to comment.