@openaddresses/batch-schema 2.3.2 → 2.4.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 +12 -0
- package/README.md +19 -1
- package/index.js +2 -4
- package/lib/schema.js +13 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
+
### v2.4.0
|
|
14
|
+
|
|
15
|
+
- :tada: Add `schema.not_found()`
|
|
16
|
+
|
|
17
|
+
### v2.3.4
|
|
18
|
+
|
|
19
|
+
- :arrow_up: Update base deps
|
|
20
|
+
|
|
21
|
+
### v2.3.3
|
|
22
|
+
|
|
23
|
+
- :rocket: Name exports explicitly instead of returning object for ES module compat.
|
|
24
|
+
|
|
13
25
|
### v2.3.2
|
|
14
26
|
|
|
15
27
|
- :bug: Fix a status code error handling bug which would crash express
|
package/README.md
CHANGED
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
|
|
8
|
+
yarn add @openaddresses/batch-schema
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i @openaddresses/batch-schema
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
## Example Usage
|
|
@@ -37,6 +43,9 @@ async function server() {
|
|
|
37
43
|
});
|
|
38
44
|
});
|
|
39
45
|
|
|
46
|
+
// Handle Unmatched Routes
|
|
47
|
+
schema.not_found();
|
|
48
|
+
|
|
40
49
|
// Handle Validation Errors => JSON Middleware
|
|
41
50
|
schema.error();
|
|
42
51
|
}
|
|
@@ -66,6 +75,15 @@ Adds a route called `GET /schema` which allows the caller to get a list of endpo
|
|
|
66
75
|
as well as full schema details for every route. If your API is public we recommend enabling this feature, however
|
|
67
76
|
if you do not wish for API routes to be published, this feature is disabled unless called.
|
|
68
77
|
|
|
78
|
+
### schema.not_found
|
|
79
|
+
|
|
80
|
+
Adds a middlware which will catch all routes that have not been defined and return
|
|
81
|
+
a standard error object.
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
schema.not_found()
|
|
85
|
+
```
|
|
86
|
+
|
|
69
87
|
### schema.error
|
|
70
88
|
|
|
71
89
|
Adds a middlware which will convert validation errors into a standard JSON error format.
|
package/index.js
CHANGED
package/lib/schema.js
CHANGED
|
@@ -236,6 +236,19 @@ class Schemas {
|
|
|
236
236
|
return schema;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Catch all for unmatched routes
|
|
241
|
+
*/
|
|
242
|
+
not_found() {
|
|
243
|
+
this.router.all('*', (req, res) => {
|
|
244
|
+
return res.status(404).json({
|
|
245
|
+
status: 404,
|
|
246
|
+
message: 'API endpoint does not exist!',
|
|
247
|
+
messages: []
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
239
252
|
/**
|
|
240
253
|
* Convert validation errors into standardized JSON Error Messages
|
|
241
254
|
*/
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openaddresses/batch-schema",
|
|
3
3
|
"root": true,
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "Strongly Validated JSON Schema support for address",
|
|
6
|
-
"repository": "git@github.com:openaddresses/batch",
|
|
6
|
+
"repository": "git@github.com:openaddresses/batch-schema",
|
|
7
7
|
"author": "ingalls <nick@ingalls.ca>",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"private": false,
|