Skip to content

Commit b6546ad

Browse files
authored
break: drop uri-js (#20)
1 parent 63020a0 commit b6546ad

File tree

11 files changed

+85
-78
lines changed

11 files changed

+85
-78
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ on:
1212

1313
jobs:
1414
test:
15-
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
15+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
1616
with:
1717
lint: true

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# json-schema-resolver
22

3-
[![CI](https://github.com/Eomm/json-schema-resolver/workflows/ci/badge.svg)](https://github.com/Eomm/json-schema-resolver/actions?query=workflow%3Aci)
4-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
3+
[![CI](https://github.com/Eomm/json-schema-resolver/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Eomm/json-schema-resolver/actions/workflows/ci.yml)
4+
[![NPM version](https://img.shields.io/npm/v/json-schema-resolver.svg?style=flat)](https://www.npmjs.com/package/json-schema-resolver)
5+
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
56

67
Resolve all `$refs` in your [JSON schema](https://json-schema.org/specification.html)!
78
This module will resolve the `$ref` keyword against the `externalSchemas` you will provide.
@@ -32,7 +33,7 @@ const ref = RefResolver({
3233
clone: true, // Clone the input schema without changing it. Default: false,
3334
buildLocalReference (json, baseUri, fragment, i) {
3435
// the `json` that is being resolved
35-
// the `baseUri` object of the schema. Its values is the parse result from https://www.npmjs.com/package/uri-js
36+
// the `baseUri` object of the schema. Its values is the parse result from https://www.npmjs.com/package/fast-uri
3637
// the `fragment` is the `$ref` string when the `$ref` is a relative reference
3738
// the `i` is a local counter to generate a unique key
3839
return `def-${i}` // default value

eslint.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
module.exports = require('neostandard')({
4+
ignores: require('neostandard').resolveIgnoresFromGitignore()
5+
})

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"description": "Resolve all your $refs",
55
"main": "ref-resolver.js",
66
"scripts": {
7-
"lint": "standard",
8-
"lint:fix": "standard --fix",
9-
"test": "tap test/**/*.test.js"
7+
"lint": "eslint",
8+
"lint:fix": "eslint --fix",
9+
"test": "c8 node --test"
1010
},
1111
"engines": {
12-
"node": ">=10"
12+
"node": ">=20"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -23,13 +23,14 @@
2323
},
2424
"homepage": "https://github.com/Eomm/json-schema-resolver#readme",
2525
"devDependencies": {
26-
"standard": "^17.0.0",
27-
"tap": "^16.3.0"
26+
"c8": "^10.1.3",
27+
"eslint": "^9.18.0",
28+
"neostandard": "^0.12.0"
2829
},
2930
"dependencies": {
3031
"debug": "^4.1.1",
31-
"rfdc": "^1.1.4",
32-
"uri-js": "^4.2.2"
32+
"fast-uri": "^3.0.5",
33+
"rfdc": "^1.1.4"
3334
},
3435
"keywords": [
3536
"json",

ref-resolver.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const URI = require('uri-js')
3+
const URI = require('fast-uri')
44
const cloner = require('rfdc')({ proto: true, circles: false })
55
const { EventEmitter } = require('events')
66
const debug = require('debug')('json-schema-resolver')
@@ -103,7 +103,7 @@ function jsonSchemaResolver (options) {
103103
if (rootSchema.$id) {
104104
rootSchema.$id = baseUri // fix the schema $id value
105105
}
106-
rootSchema[kIgnore] = true
106+
Object.defineProperty(rootSchema, kIgnore, { value: true, enumerable: false })
107107

108108
mapIds(ee, appUri, rootSchema)
109109
debug('Processed root schema')
@@ -118,7 +118,7 @@ function jsonSchemaResolver (options) {
118118
debug('External $ref %s not provided with baseUri %s', ref, baseUri)
119119
return
120120
}
121-
evaluatedJson[kConsumed] = true
121+
Object.defineProperty(evaluatedJson, kConsumed, { value: true, enumerable: false })
122122
json.$ref = `#/definitions/${evaluatedJson[kRefToDef]}${refUri.fragment || ''}`
123123
})
124124

@@ -146,7 +146,8 @@ function jsonSchemaResolver (options) {
146146
const id = URI.serialize(baseUri) + rel
147147
if (!allIds.has(id)) {
148148
debug('Collected $id %s', id)
149-
json[kRefToDef] = buildLocalReference(json, baseUri, fragment, rolling++)
149+
const value = buildLocalReference(json, baseUri, fragment, rolling++)
150+
Object.defineProperty(json, kRefToDef, { value, enumerable: false })
150151
allIds.set(id, json)
151152
} else {
152153
debug('WARN duplicated id %s .. IGNORED - ', id)

test/example.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44

55
const RefResolver = require('../ref-resolver')
66

@@ -32,7 +32,7 @@ test('readme example', t => {
3232

3333
const singleSchema = ref.resolve(inputSchema, { externalSchemas: [addresSchema] })
3434

35-
t.same(singleSchema, {
35+
t.assert.deepStrictEqual(singleSchema, {
3636
$id: 'http://example.com/SimplePerson',
3737
type: 'object',
3838
properties: {
@@ -100,7 +100,7 @@ test('readme example #2', t => {
100100
// to get the definition you need only to call:
101101
const sharedDefinitions = ref.definitions()
102102

103-
t.same(sharedDefinitions, {
103+
t.assert.deepStrictEqual(sharedDefinitions, {
104104
definitions: {
105105
'def-0': {
106106
$id: 'relativeAddress',
@@ -117,7 +117,7 @@ test('readme example #2', t => {
117117
}
118118
})
119119

120-
t.same(singleSchema, {
120+
t.assert.deepStrictEqual(singleSchema, {
121121
$id: 'my-application.org',
122122
type: 'object',
123123
properties: {

test/ref-as-is.test.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
2-
const { test } = require('tap')
3-
const URI = require('uri-js')
1+
const { test } = require('node:test')
2+
const URI = require('fast-uri')
43
const RefResolver = require('../ref-resolver')
54

65
test('resolving schema within the $id', t => {
@@ -33,8 +32,8 @@ test('resolving schema within the $id', t => {
3332
const resolver = RefResolver(opts)
3433
const out = resolver.resolve(schema)
3534
const externalDef = resolver.definitions()
36-
t.equal(out.properties.greetings.$ref, '#/definitions/greetings')
37-
t.same(externalDef.definitions.greetings, opts.externalSchemas[0])
35+
t.assert.strictEqual(out.properties.greetings.$ref, '#/definitions/greetings')
36+
t.assert.deepStrictEqual(externalDef.definitions.greetings, opts.externalSchemas[0])
3837
})
3938

4039
test('resolving schema within the $id case #2', t => {
@@ -66,11 +65,11 @@ test('resolving schema within the $id case #2', t => {
6665

6766
const resolver = RefResolver(opts)
6867
const out = resolver.resolve(schema)
69-
t.equal(out.properties.hello.$ref, '#/definitions/urn%3Aschema%3Abase/definitions/hello')
68+
t.assert.strictEqual(out.properties.hello.$ref, '#/definitions/urn%3Aschema%3Abase/definitions/hello')
7069

7170
const externalDef = resolver.definitions()
72-
t.ok(externalDef.definitions['urn%3Aschema%3Abase'], 'buildLocalReference result')
73-
t.ok(externalDef.definitions['urn%3Aschema%3Aref'], 'buildLocalReference result')
71+
t.assert.ok(externalDef.definitions['urn%3Aschema%3Abase'], 'buildLocalReference result')
72+
t.assert.ok(externalDef.definitions['urn%3Aschema%3Aref'], 'buildLocalReference result')
7473
})
7574

7675
test('resolving schema within the $id relative', t => {
@@ -99,7 +98,7 @@ test('resolving schema within the $id relative', t => {
9998
}
10099
],
101100
buildLocalReference (json, baseUri, fragment, i) {
102-
t.equal(URI.serialize(baseUri), baseUriCheck.shift())
101+
t.assert.strictEqual(URI.serialize(baseUri), baseUriCheck.shift())
103102
return escape(json.$id)
104103
}
105104
}
@@ -111,6 +110,6 @@ test('resolving schema within the $id relative', t => {
111110

112111
const resolver = RefResolver(opts)
113112
const out = resolver.resolve(schema)
114-
t.equal(out.properties.user.$ref, '#/definitions/http%3A//hello.absolute/user.json/definitions/name')
115-
t.equal(out.properties.address.$ref, '#/definitions/adr/definitions/street')
113+
t.assert.strictEqual(out.properties.user.$ref, '#/definitions/http%3A//hello.absolute/user.json/definitions/name')
114+
t.assert.strictEqual(out.properties.address.$ref, '#/definitions/adr/definitions/street')
116115
})

test/ref-fragment.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44

55
const RefResolver = require('../ref-resolver')
66

@@ -30,7 +30,7 @@ test('Preserve $ref fragment', t => {
3030
}
3131
}, opts)
3232

33-
t.same(out, {
33+
t.assert.deepStrictEqual(out, {
3434
$id: 'my-schema',
3535
type: 'object',
3636
properties: {

test/ref-local.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44

55
const RefResolver = require('../ref-resolver')
66

@@ -45,7 +45,7 @@ test('Resolve absolute refs in schema', t => {
4545
$ref: 'ObjectC#'
4646
}, opts)
4747

48-
t.same(out, {
48+
t.assert.deepStrictEqual(out, {
4949
$ref: '#/definitions/def-1',
5050
definitions: {
5151
'def-0': {
@@ -110,7 +110,7 @@ test('Resolve relative refs in schema', t => {
110110
$ref: 'ObjectA#/properties/relativeExample'
111111
}, opts)
112112

113-
t.same(out, {
113+
t.assert.deepStrictEqual(out, {
114114
$ref: '#/definitions/def-0/properties/relativeExample',
115115
definitions: {
116116
'def-0': {

test/ref-resolver.test.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const clone = require('rfdc')({ proto: true, circles: false })
55

66
const RefResolver = require('../ref-resolver')
@@ -13,8 +13,8 @@ const save = (out) => require('fs').writeFileSync(`./out-${Date.now()}.json`, JS
1313

1414
test('wrong params', t => {
1515
t.plan(2)
16-
t.throws(() => RefResolver({ target: 'draft-1000' }))
17-
t.throws(() => RefResolver({ externalSchemas: [] }), 'need application uri')
16+
t.assert.throws(() => RefResolver({ target: 'draft-1000' }))
17+
t.assert.throws(() => RefResolver({ externalSchemas: [] }), 'need application uri')
1818
})
1919

2020
test('$ref to root', t => {
@@ -31,8 +31,8 @@ test('$ref to root', t => {
3131

3232
const originalSchema = clone(schema)
3333
const out = resolver.resolve(schema, opts)
34-
t.same(schema, originalSchema, 'the param schema should not be changed')
35-
t.equal(schema, out, 'the output schema is the same (LINK) of the input one')
34+
t.assert.deepStrictEqual(schema, originalSchema, 'the param schema should not be changed')
35+
t.assert.strictEqual(schema, out, 'the output schema is the same (LINK) of the input one')
3636
})
3737

3838
test('$ref to an external schema', t => {
@@ -48,9 +48,9 @@ test('$ref to an external schema', t => {
4848
const resolver = RefResolver()
4949

5050
const out = resolver.resolve(schema, opts)
51-
t.same(schema, out, 'the output is the same input - modified')
52-
t.ok(out.definitions, 'definitions has been added')
53-
t.same(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
51+
t.assert.deepStrictEqual(schema, out, 'the output is the same input - modified')
52+
t.assert.ok(out.definitions, 'definitions has been added')
53+
t.assert.deepStrictEqual(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
5454
})
5555

5656
test('$ref to an external schema without changes', t => {
@@ -67,10 +67,10 @@ test('$ref to an external schema without changes', t => {
6767

6868
const originalSchema = clone(schema)
6969
const out = resolver.resolve(schema, opts)
70-
t.same(schema, originalSchema, 'the input is unchanged')
71-
t.notMatch(schema, out, 'the input is unchanged')
72-
t.ok(out.definitions, 'definitions has been added')
73-
t.same(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
70+
t.assert.deepStrictEqual(schema, originalSchema, 'the input is unchanged')
71+
t.assert.notDeepStrictEqual(schema, out, 'the input is unchanged')
72+
t.assert.ok(out.definitions, 'definitions has been added')
73+
t.assert.deepStrictEqual(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
7474
})
7575

7676
test('$ref circular', t => {
@@ -89,9 +89,9 @@ test('$ref circular', t => {
8989

9090
const resolver = RefResolver()
9191
const out = resolver.resolve(schema, opts)
92-
t.same(schema, out, 'the output is the same input modified')
93-
t.ok(out.definitions, 'definitions has been added')
94-
t.same(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
92+
t.assert.deepStrictEqual(schema, out, 'the output is the same input modified')
93+
t.assert.ok(out.definitions, 'definitions has been added')
94+
t.assert.deepStrictEqual(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
9595
})
9696

9797
test('$ref circular', t => {
@@ -110,9 +110,9 @@ test('$ref circular', t => {
110110

111111
const resolver = RefResolver()
112112
const out = resolver.resolve(schema, opts)
113-
t.same(schema, out, 'the output is the same input modified')
114-
t.ok(out.definitions, 'definitions has been added')
115-
t.same(Object.values(out.definitions), [opts.externalSchemas[1]], 'only used schema are added')
113+
t.assert.deepStrictEqual(schema, out, 'the output is the same input modified')
114+
t.assert.ok(out.definitions, 'definitions has been added')
115+
t.assert.deepStrictEqual(Object.values(out.definitions), [opts.externalSchemas[1]], 'only used schema are added')
116116
})
117117

118118
test('$ref local ids', { skip: true }, t => {
@@ -128,9 +128,9 @@ test('$ref local ids', { skip: true }, t => {
128128

129129
const resolver = RefResolver()
130130
const out = resolver.resolve(schema, opts)
131-
t.same(schema, out, 'the output is the same input modified')
131+
t.assert.deepStrictEqual(schema, out, 'the output is the same input modified')
132132
// TODO build a graph to track is an external schema is referenced by the root
133-
t.equal(Object.values(out.definitions).length, 1, 'no external schema added')
133+
t.assert.strictEqual(Object.values(out.definitions).length, 1, 'no external schema added')
134134
})
135135

136136
test('skip duplicated ids', t => {
@@ -145,8 +145,8 @@ test('skip duplicated ids', t => {
145145

146146
const resolver = RefResolver()
147147
const out = resolver.resolve(schema, opts)
148-
t.same(schema, out, 'the output is the same input modified')
149-
t.equal(Object.values(out.definitions).length, 1, 'no external schema added')
148+
t.assert.deepStrictEqual(schema, out, 'the output is the same input modified')
149+
t.assert.strictEqual(Object.values(out.definitions).length, 1, 'no external schema added')
150150
})
151151

152152
test('dont resolve external schema missing', t => {
@@ -155,7 +155,7 @@ test('dont resolve external schema missing', t => {
155155

156156
const resolver = RefResolver({ clone: true })
157157
const out = resolver.resolve(schema)
158-
t.same(schema, out, 'the output is the same input not modified')
158+
t.assert.deepStrictEqual(schema, out, 'the output is the same input not modified')
159159
})
160160

161161
test('dont resolve external schema missing #2', t => {
@@ -164,7 +164,7 @@ test('dont resolve external schema missing #2', t => {
164164

165165
const resolver = RefResolver({ clone: true })
166166
const out = resolver.resolve(schema)
167-
t.same(schema, out, 'the output is the same input not modified')
167+
t.assert.deepStrictEqual(schema, out, 'the output is the same input not modified')
168168
})
169169

170170
test('missing id in root schema', t => {
@@ -182,9 +182,9 @@ test('missing id in root schema', t => {
182182

183183
const resolver = RefResolver()
184184
const out = resolver.resolve(schema, opts)
185-
t.same(schema, out, 'the output is the same input modified')
186-
t.ok(out.definitions, 'definitions has been added')
187-
t.same(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
185+
t.assert.deepStrictEqual(schema, out, 'the output is the same input modified')
186+
t.assert.ok(out.definitions, 'definitions has been added')
187+
t.assert.deepStrictEqual(Object.values(out.definitions), opts.externalSchemas, 'external schema has been added to definitions')
188188
})
189189

190190
test('absolute $ref', t => {
@@ -214,8 +214,8 @@ test('absolute $ref', t => {
214214
const resolver = RefResolver({ clone: true, applicationUri: 'todo.com', externalSchemas })
215215
const out = resolver.resolve(schema)
216216

217-
t.not(out.$ref, 'http://example.com/#/definitions/idParam')
218-
t.same(resolver.definitions(), {
217+
t.assert.notEqual(out.$ref, 'http://example.com/#/definitions/idParam')
218+
t.assert.deepStrictEqual(resolver.definitions(), {
219219
definitions: {
220220
'def-0': absSchemaId
221221
}
@@ -241,6 +241,6 @@ test('absolute $ref #2', t => {
241241

242242
const resolver = RefResolver({ clone: true })
243243
const out = resolver.resolve(schema, { externalSchemas })
244-
t.equal(out.properties.address.$ref, '#/definitions/def-0')
245-
t.equal(out.properties.houses.items.$ref, '#/definitions/def-0')
244+
t.assert.strictEqual(out.properties.address.$ref, '#/definitions/def-0')
245+
t.assert.strictEqual(out.properties.houses.items.$ref, '#/definitions/def-0')
246246
})

0 commit comments

Comments
 (0)