Skip to content

Commit ffa6a99

Browse files
authored
⬆️ upgrade ajv, migrate json scheam, remove use of deprecated Buffer constructor (#81)
1 parent 8eb0852 commit ffa6a99

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = Serializer => {
121121
if (value && value.type === 'Buffer' &&
122122
Array.isArray(value.data) &&
123123
Object.keys(value).length === 2)
124-
return new Buffer(value.data).toString(bufferEncoding)
124+
return Buffer.from(value.data).toString(bufferEncoding)
125125

126126
return value
127127
}, jsonSpaces)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fortune-json-api",
33
"description": "JSON API serializer for Fortune.",
4-
"version": "2.3.0",
4+
"version": "2.3.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",
@@ -20,7 +20,8 @@
2020
"uri-templates": "^0.2.0"
2121
},
2222
"devDependencies": {
23-
"ajv": "^4.11.8",
23+
"ajv": "^8",
24+
"ajv-formats": "^2.1.1",
2425
"chalk": "^3.0.0",
2526
"eslint": "^6.8.0",
2627
"eslint-config-boss": "^1.0.6",

test/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const deepEqual = require('deep-equal')
44
const qs = require('querystring')
5-
const Ajv = require('ajv')
5+
const Ajv = require('ajv').default
6+
const addFormats = require('ajv-formats').default
67

78
const run = require('tapdance')
89

@@ -11,6 +12,7 @@ const jsonApi = require('../lib')
1112
const jsonApiResponseSchema = require('./json-api-response-schema.json')
1213

1314
const ajv = new Ajv({allErrors: true, v5: true})
15+
addFormats(ajv)
1416
const validate = ajv.compile(jsonApiResponseSchema)
1517

1618
const mediaType = 'application/vnd.api+json'
@@ -80,7 +82,7 @@ run((assert, comment) => {
8082
name: 'Rover',
8183
type: 'Chihuahua',
8284
birthday: new Date().toJSON(),
83-
picture: new Buffer('This is a string.').toString('base64'),
85+
picture: Buffer.from('This is a string.').toString('base64'),
8486
'is-neutered': true,
8587
nicknames: [ 'Doge', 'The Dog' ],
8688
'some-date': '2015-01-04T00:00:00.000Z'
@@ -102,7 +104,7 @@ run((assert, comment) => {
102104
assert(response.body.data.type === 'animals', 'type is correct')
103105
assert(response.body.data.attributes['is-neutered'] === true,
104106
'inflected key value is correct')
105-
assert(new Buffer(response.body.data.attributes.picture, 'base64')
107+
assert(Buffer.from(response.body.data.attributes.picture, 'base64')
106108
.toString() === 'This is a string.', 'buffer is correct')
107109
assert(Date.now() - new Date(response.body.data.attributes.birthday)
108110
.getTime() < 60 * 1000, 'date is close enough')
@@ -655,7 +657,7 @@ run((assert, comment) => {
655657
name: 'Rover',
656658
type: 'Chihuahua',
657659
birthday: new Date().toJSON(),
658-
picture: new Buffer('This is a string.').toString('base64'),
660+
picture: Buffer.from('This is a string.').toString('base64'),
659661
'is-neutered': true,
660662
nicknames: [ 'Doge', 'The Dog' ],
661663
'some-date': '2015-01-04T00:00:00.000Z'
@@ -677,7 +679,7 @@ run((assert, comment) => {
677679
assert(response.body.data.type === 'animal', 'type is correct')
678680
assert(response.body.data.attributes['is-neutered'] === true,
679681
'inflected key value is correct')
680-
assert(new Buffer(response.body.data.attributes.picture, 'base64')
682+
assert(Buffer.from(response.body.data.attributes.picture, 'base64')
681683
.toString() === 'This is a string.', 'buffer is correct')
682684
assert(Date.now() - new Date(response.body.data.attributes.birthday)
683685
.getTime() < 60 * 1000, 'date is close enough')
@@ -778,7 +780,7 @@ run((assert, comment) => {
778780
name: 'Rover',
779781
type: 'Chihuahua',
780782
birthday: new Date().toJSON(),
781-
picture: new Buffer('This is a string.').toString('base64'),
783+
picture: Buffer.from('This is a string.').toString('base64'),
782784
'is-neutered': true,
783785
nicknames: [ 'Doge', 'The Dog' ],
784786
'some-date': '2015-01-04T00:00:00.000Z'

test/json-api-response-schema.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "http://json-schema.org/draft-04/schema#",
2+
"$schema": "http://json-schema.org/draft-07/schema",
33
"title": "JSON API Schema",
44
"description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
55
"oneOf": [
@@ -158,7 +158,7 @@
158158
"self": {
159159
"description": "A `self` member, whose value is a URL for the relationship itself (a \"relationship URL\"). This URL allows the client to directly manipulate the relationship. For example, it would allow a client to remove an `author` from an `article` without deleting the people resource itself.",
160160
"type": "string",
161-
"format": "uri"
161+
"format": "uri-reference"
162162
},
163163
"related": {
164164
"$ref": "#/definitions/link"
@@ -172,7 +172,7 @@
172172
{
173173
"description": "A string containing the link's URL.",
174174
"type": "string",
175-
"format": "uri"
175+
"format": "uri-reference"
176176
},
177177
{
178178
"type": "object",
@@ -183,7 +183,7 @@
183183
"href": {
184184
"description": "A string containing the link's URL.",
185185
"type": "string",
186-
"format": "uri"
186+
"format": "uri-reference"
187187
},
188188
"meta": {
189189
"$ref": "#/definitions/meta"
@@ -287,28 +287,28 @@
287287
"first": {
288288
"description": "The first page of data",
289289
"oneOf": [
290-
{ "type": "string", "format": "uri" },
290+
{ "type": "string", "format": "uri-reference" },
291291
{ "type": "null" }
292292
]
293293
},
294294
"last": {
295295
"description": "The last page of data",
296296
"oneOf": [
297-
{ "type": "string", "format": "uri" },
297+
{ "type": "string", "format": "uri-reference" },
298298
{ "type": "null" }
299299
]
300300
},
301301
"prev": {
302302
"description": "The previous page of data",
303303
"oneOf": [
304-
{ "type": "string", "format": "uri" },
304+
{ "type": "string", "format": "uri-reference" },
305305
{ "type": "null" }
306306
]
307307
},
308308
"next": {
309309
"description": "The next page of data",
310310
"oneOf": [
311-
{ "type": "string", "format": "uri" },
311+
{ "type": "string", "format": "uri-reference" },
312312
{ "type": "null" }
313313
]
314314
}

0 commit comments

Comments
 (0)