Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions ref-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function jsonSchemaResolver (options) {
* @param {URI} baseUri
* @param {*} json
*/
function mapIds (ee, baseUri, json) {
function mapIds (ee, baseUri, json, parentKey) {
if (!(json instanceof Object)) return

if (json.$id) {
Expand Down Expand Up @@ -218,10 +218,10 @@ function mapIds (ee, baseUri, json) {

const fields = Object.keys(json)
for (const prop of fields) {
if (prop === '$ref') {
if (prop === '$ref' && (typeof json.$ref === 'string') && parentKey !== 'properties') {
ee.emit('$ref', json, baseUri, json[prop])
}
mapIds(ee, baseUri, json[prop])
mapIds(ee, baseUri, json[prop], parentKey)
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/ref-resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,12 @@ test('absolute $ref #2', t => {
t.equal(out.properties.address.$ref, '#/definitions/def-0')
t.equal(out.properties.houses.items.$ref, '#/definitions/def-0')
})

test('do not resolve meta refs', t => {
t.plan(1)
const schema = factory('metaRef')

const resolver = RefResolver({ clone: true })
const out = resolver.resolve(schema, {})
t.same(out.properties.$ref, { type: 'string' })
})
7 changes: 7 additions & 0 deletions test/schemas/metaRef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
$id: 'schemaWithMetaRef',
type: 'object',
properties: {
$ref: { type: 'string' }
}
}