@openaddresses/batch-schema 10.19.0 → 10.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v10.22.0
14
+
15
+ - :rocket: Increase usefulness of schema error messages by including the schema path and the value that failed validation
16
+
17
+ ### v10.21.0
18
+
19
+ - :rocket: Surface outgoing schema errors in the logs
20
+
21
+ ### v10.20.0
22
+
23
+ - :arrow_up: Update Core Types
24
+
13
25
  ### v10.19.0
14
26
 
15
27
  - :rocket: Allow passing through morgan options
package/lib/schema.ts CHANGED
@@ -159,13 +159,18 @@ export default class Schemas {
159
159
  const errors: Array<ErrorListItem> = [];
160
160
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
161
161
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
162
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
162
+ if (errors.length) {
163
+ return Err.respond(new Err(
164
+ 400, null, `Validation Error GET ${path}`
165
+ ), res, errors);
166
+ }
163
167
 
164
168
  const json = res.json;
165
169
  res.json = function(obj) {
166
170
  obj = JSON.parse(JSON.stringify(obj)) // Here as Date => String needs to happen
167
171
  if ((res.statusCode === null || res.statusCode === 200) && resValidation && !resValidation(obj)) {
168
172
  res.status(400);
173
+ console.error(`Response Validation Error: ${JSON.stringify(obj)}`);
169
174
  return json.call(this, { type: 'Response', errors: resValidation.errors as ErrorObject[] });
170
175
  } else {
171
176
  return json.call(this, obj);
@@ -206,13 +211,18 @@ export default class Schemas {
206
211
  const errors: Array<ErrorListItem> = [];
207
212
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
208
213
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
209
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
214
+ if (errors.length) {
215
+ return Err.respond(new Err(
216
+ 400, null, `Validation Error DELETE ${path}`
217
+ ), res, errors);
218
+ }
210
219
 
211
220
  const json = res.json;
212
221
  res.json = function(obj) {
213
222
  obj = JSON.parse(JSON.stringify(obj)) // Here as Date => String needs to happen
214
223
  if ((res.statusCode === null || res.statusCode === 200) && resValidation && !resValidation(obj)) {
215
224
  res.status(400);
225
+ console.error(`Response Validation Error: ${JSON.stringify(obj)}`);
216
226
  return json.call(this, { type: 'Response', errors: resValidation.errors as ErrorObject[] });
217
227
  } else {
218
228
  return json.call(this, obj);
@@ -254,13 +264,18 @@ export default class Schemas {
254
264
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
255
265
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
256
266
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
257
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
267
+ if (errors.length) {
268
+ return Err.respond(new Err(
269
+ 400, null, `Validation Error POST ${path}`
270
+ ), res, errors);
271
+ }
258
272
 
259
273
  const json = res.json;
260
274
  res.json = function(obj) {
261
275
  obj = JSON.parse(JSON.stringify(obj)) // Here as Date => String needs to happen
262
276
  if ((res.statusCode === null || res.statusCode === 200) && resValidation && !resValidation(obj)) {
263
277
  res.status(400);
278
+ console.error(`Response Validation Error: ${JSON.stringify(obj)}`);
264
279
  return json.call(this, { type: 'Response', errors: resValidation.errors as ErrorObject[] });
265
280
  } else {
266
281
  return json.call(this, obj);
@@ -302,13 +317,18 @@ export default class Schemas {
302
317
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
303
318
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
304
319
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
305
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
320
+ if (errors.length) {
321
+ return Err.respond(new Err(
322
+ 400, null, `Validation Error PATCH ${path}`
323
+ ), res, errors);
324
+ }
306
325
 
307
326
  const json = res.json;
308
327
  res.json = function(obj) {
309
328
  obj = JSON.parse(JSON.stringify(obj)) // Here as Date => String needs to happen
310
329
  if ((res.statusCode === null || res.statusCode === 200) && resValidation && !resValidation(obj)) {
311
330
  res.status(400);
331
+ console.error(`Response Validation Error: ${JSON.stringify(obj)}`);
312
332
  return json.call(this, { type: 'Response', errors: resValidation.errors as ErrorObject[] });
313
333
  } else {
314
334
  return json.call(this, obj);
@@ -350,13 +370,18 @@ export default class Schemas {
350
370
  if (paramsValidation && !paramsValidation(req.params)) errors.push({ type: 'Params', errors: paramsValidation.errors as ErrorObject[] });
351
371
  if (queryValidation && !queryValidation(req.query)) errors.push({ type: 'Query', errors: queryValidation.errors as ErrorObject[] });
352
372
  if (bodyValidation && !bodyValidation(req.body)) errors.push({ type: 'Body', errors: bodyValidation.errors as ErrorObject[] });
353
- if (errors.length) return Err.respond(new Err(400, null, 'Validation Error'), res, errors);
373
+ if (errors.length) {
374
+ return Err.respond(new Err(
375
+ 400, null, `Validation Error PUT ${path}`
376
+ ), res, errors);
377
+ }
354
378
 
355
379
  const json = res.json;
356
380
  res.json = function(obj) {
357
381
  obj = JSON.parse(JSON.stringify(obj)) // Here as Date => String needs to happen
358
382
  if ((res.statusCode === null || res.statusCode === 200) && resValidation && !resValidation(obj)) {
359
383
  res.status(400);
384
+ console.error(`Response Validation Error: ${JSON.stringify(obj)}`);
360
385
  return json.call(this, { type: 'Response', errors: resValidation.errors as ErrorObject[] });
361
386
  } else {
362
387
  return json.call(this, obj);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "root": true,
5
5
  "main": "dist/index.js",
6
6
  "types": "index.ts",
7
- "version": "10.19.0",
7
+ "version": "10.22.0",
8
8
  "description": "Strongly Validated JSON Schema support for address",
9
9
  "repository": "git@github.com:openaddresses/batch-schema",
10
10
  "author": "ingalls <nick@ingalls.ca>",
@@ -29,7 +29,7 @@
29
29
  "ajv-formats": "^3.0.1",
30
30
  "body-parser": "^2.2.0",
31
31
  "express": "^5.0.0",
32
- "glob": "^11.0.0",
32
+ "glob": "^13.0.0",
33
33
  "morgan": "^1.10.0",
34
34
  "openapi-types": "^12.1.3"
35
35
  },
@@ -48,7 +48,7 @@ test('GET: api/schema?method=FAKE', async (t) => {
48
48
 
49
49
  t.deepEquals(await res.json(), {
50
50
  status: 400,
51
- message: 'Validation Error',
51
+ message: 'Validation Error GET /schema',
52
52
  messages: [
53
53
  {"type":"Query","errors":[{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/0/const","keyword":"const","params":{"allowedValue":"GET"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/1/const","keyword":"const","params":{"allowedValue":"PUT"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/2/const","keyword":"const","params":{"allowedValue":"POST"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/3/const","keyword":"const","params":{"allowedValue":"DELETE"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/4/const","keyword":"const","params":{"allowedValue":"OPTIONS"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/5/const","keyword":"const","params":{"allowedValue":"HEAD"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/6/const","keyword":"const","params":{"allowedValue":"PATCH"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf/7/const","keyword":"const","params":{"allowedValue":"TRACE"},"message":"must be equal to constant"},{"instancePath":"/method","schemaPath":"#/properties/method/anyOf","keyword":"anyOf","params":{},"message":"must match a schema in anyOf"}]}
54
54
  ]