@openaddresses/batch-schema 7.1.0 → 7.2.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 +4 -0
- package/lib/docs.js +36 -0
- package/lib/schema.js +14 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/docs.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class Docs
|
|
3
|
+
*/
|
|
4
|
+
export default class Docs extends Array {
|
|
5
|
+
push(parsed, schemas) {
|
|
6
|
+
const apiParams = [];
|
|
7
|
+
for (const key in schemas) {
|
|
8
|
+
if (key[0] === ':') {
|
|
9
|
+
apiParams.push(`* @apiParam {${schemas[key]}} ${key.slice(1)} param`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
super.push(
|
|
14
|
+
`
|
|
15
|
+
/**
|
|
16
|
+
* @api {${parsed[0].toLowerCase()}} ${parsed[1]} ${schemas.name || parsed.join(' ')}
|
|
17
|
+
* @apiVersion ${schemas.version || '1.0.0'}
|
|
18
|
+
* @apiName ${parsed.join('-')}
|
|
19
|
+
* @apiGroup ${schemas.group || 'Default'}
|
|
20
|
+
* @apiPermission ${schemas.auth || 'Unknown'}
|
|
21
|
+
*
|
|
22
|
+
* @apidescription
|
|
23
|
+
* ${schemas.description || 'No Description'}
|
|
24
|
+
*
|
|
25
|
+
${apiParams.join('\n')}
|
|
26
|
+
*
|
|
27
|
+
* ${schemas.query_url ? `@apiSchema (Query) {jsonschema=${schemas.query_url}} apiParam` : ''}
|
|
28
|
+
* ${schemas.body_url ? `@apiSchema (Body) {jsonschema=${schemas.body_url}} apiParam` : ''}
|
|
29
|
+
* ${schemas.res_url ? `@apiSchema {jsonschema=${schemas.res_url}} apiSuccess` : ''}
|
|
30
|
+
*/
|
|
31
|
+
`.split('\n')
|
|
32
|
+
.map((l) => l.trim())
|
|
33
|
+
.join('\n')
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/lib/schema.js
CHANGED
|
@@ -7,6 +7,7 @@ import bodyparser from 'body-parser';
|
|
|
7
7
|
|
|
8
8
|
import SchemaRoute from '../routes/schema.js';
|
|
9
9
|
import Param from './param.js';
|
|
10
|
+
import Docs from './docs.js';
|
|
10
11
|
import Middleware from './middleware.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -17,6 +18,8 @@ import Middleware from './middleware.js';
|
|
|
17
18
|
* @param {String} opts.schemas Schemas Path
|
|
18
19
|
* @param {boolean|string} [opts.logging=true] disable logging with false
|
|
19
20
|
* @param {number} [opts.limit=50] body size limit in mb
|
|
21
|
+
*
|
|
22
|
+
* @param {URL} [opts.apidoc] apidoc file location
|
|
20
23
|
*/
|
|
21
24
|
export default class Schemas {
|
|
22
25
|
constructor(router, opts = {}) {
|
|
@@ -45,6 +48,8 @@ export default class Schemas {
|
|
|
45
48
|
|
|
46
49
|
this.schemas = new Map();
|
|
47
50
|
this.validate = this.validator.validate;
|
|
51
|
+
|
|
52
|
+
this.docs = new Docs();
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
async api() {
|
|
@@ -121,6 +126,8 @@ export default class Schemas {
|
|
|
121
126
|
for (const type of ['body', 'query', 'res']) {
|
|
122
127
|
if (!schemas[type]) continue;
|
|
123
128
|
|
|
129
|
+
// TODO: Write schemas to a tmp directory so blueprints & main schemas are in the same place
|
|
130
|
+
schemas[`${type}_url`] = '../schema/' + schemas[type];
|
|
124
131
|
try {
|
|
125
132
|
schemas[type] = await $RefParser.dereference((new URL(`../schema/${schemas[type]}`, import.meta.url)).pathname);
|
|
126
133
|
} catch (err) {
|
|
@@ -128,6 +135,8 @@ export default class Schemas {
|
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
|
|
138
|
+
this.docs.push(parsed, schemas);
|
|
139
|
+
|
|
131
140
|
this.schemas.set(parsed.join(' '), schemas);
|
|
132
141
|
|
|
133
142
|
const opts = {};
|
|
@@ -178,7 +187,11 @@ export default class Schemas {
|
|
|
178
187
|
if (!schema.body) schema.body = null;
|
|
179
188
|
if (!schema.res) schema.res = null;
|
|
180
189
|
|
|
181
|
-
return
|
|
190
|
+
return {
|
|
191
|
+
query: schema.query,
|
|
192
|
+
body: schema.body,
|
|
193
|
+
res: schema.res
|
|
194
|
+
};
|
|
182
195
|
}
|
|
183
196
|
|
|
184
197
|
/**
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"root": true,
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"version": "7.
|
|
6
|
+
"version": "7.2.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>",
|