@openaddresses/batch-schema 7.2.0 → 7.3.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,10 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v7.3.0
14
+
15
+ - :arrow_up: `res.json` will automatically serialize Generic objects
16
+
13
17
  ### v7.2.0
14
18
 
15
19
  - :tada: Preliminary support for automatically generated an APIDoc definitions file
package/lib/middleware.js CHANGED
@@ -3,6 +3,7 @@ import Param from './param.js';
3
3
  import Ajv from 'ajv';
4
4
  import addFormats from 'ajv-formats';
5
5
  import { ValidationError } from 'express-json-validator-middleware';
6
+ import Generic from '@openaddresses/batch-generic';
6
7
 
7
8
  const ajv = addFormats(new Ajv({
8
9
  allErrors: true,
@@ -99,6 +100,7 @@ export default class Middleware {
99
100
 
100
101
  /**
101
102
  * Express middleware to validate the response body
103
+ * and optionally serialize Generic object to JSON
102
104
  *
103
105
  * @param {Object} schema JSON Schema
104
106
  *
@@ -110,6 +112,10 @@ export default class Middleware {
110
112
  return function (req, res, next) {
111
113
  const json = res.json;
112
114
  res.json = function(obj) {
115
+ if (obj instanceof Generic && typeof obj.serialize === 'function') {
116
+ obj = obj.serialize();
117
+ }
118
+
113
119
  if (res.statusCode === null || res.statusCode === 200) {
114
120
  validate(obj);
115
121
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "root": true,
5
5
  "main": "index.js",
6
- "version": "7.2.0",
6
+ "version": "7.3.0",
7
7
  "description": "Strongly Validated JSON Schema support for address",
8
8
  "repository": "git@github.com:openaddresses/batch-schema",
9
9
  "author": "ingalls <nick@ingalls.ca>",
@@ -29,6 +29,9 @@
29
29
  "morgan": "^1.10.0",
30
30
  "tape": "^5.3.1"
31
31
  },
32
+ "peerDependencies": {
33
+ "@openaddresses/batch-generic": "x.x.x"
34
+ },
32
35
  "devDependencies": {
33
36
  "documentation": "^13.2.5",
34
37
  "eslint": "^8.0.1",