Skip to content

Commit

Permalink
fix: set hash sign as default json pointer (#485)
Browse files Browse the repository at this point in the history
* fix: set hash sign as default json pointer

* change test name
  • Loading branch information
ivan-tymoshenko authored Jul 5, 2022
1 parent 502011d commit 7d77f9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function resolveRef (location, ref) {
}

const schemaId = ref.slice(0, hashIndex) || location.schemaId
const jsonPointer = ref.slice(hashIndex)
const jsonPointer = ref.slice(hashIndex) || '#'

const schemaRef = schemaId + jsonPointer

Expand Down
27 changes: 27 additions & 0 deletions test/ref.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1926,3 +1926,30 @@ test('anyOf inside allOf', (t) => {

t.equal(output, JSON.stringify(object))
})

test('should resolve absolute $refs', (t) => {
t.plan(1)

const externalSchema = {
FooSchema: {
$id: 'FooSchema',
type: 'object',
properties: {
type: {
anyOf: [
{ type: 'string', const: 'bar' },
{ type: 'string', const: 'baz' }
]
}
}
}
}

const schema = { $ref: 'FooSchema' }

const object = { type: 'bar' }
const stringify = build(schema, { schema: externalSchema })
const output = stringify(object)

t.equal(output, JSON.stringify(object))
})

0 comments on commit 7d77f9d

Please sign in to comment.