Skip to content

Commit 7d77f9d

Browse files
fix: set hash sign as default json pointer (#485)
* fix: set hash sign as default json pointer * change test name
1 parent 502011d commit 7d77f9d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function resolveRef (location, ref) {
5555
}
5656

5757
const schemaId = ref.slice(0, hashIndex) || location.schemaId
58-
const jsonPointer = ref.slice(hashIndex)
58+
const jsonPointer = ref.slice(hashIndex) || '#'
5959

6060
const schemaRef = schemaId + jsonPointer
6161

test/ref.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,3 +1926,30 @@ test('anyOf inside allOf', (t) => {
19261926

19271927
t.equal(output, JSON.stringify(object))
19281928
})
1929+
1930+
test('should resolve absolute $refs', (t) => {
1931+
t.plan(1)
1932+
1933+
const externalSchema = {
1934+
FooSchema: {
1935+
$id: 'FooSchema',
1936+
type: 'object',
1937+
properties: {
1938+
type: {
1939+
anyOf: [
1940+
{ type: 'string', const: 'bar' },
1941+
{ type: 'string', const: 'baz' }
1942+
]
1943+
}
1944+
}
1945+
}
1946+
}
1947+
1948+
const schema = { $ref: 'FooSchema' }
1949+
1950+
const object = { type: 'bar' }
1951+
const stringify = build(schema, { schema: externalSchema })
1952+
const output = stringify(object)
1953+
1954+
t.equal(output, JSON.stringify(object))
1955+
})

0 commit comments

Comments
 (0)