@loopback/repository-json-schema 1.11.0 → 1.11.4
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 +32 -0
- package/dist/build-schema.js +18 -11
- package/dist/build-schema.js.map +1 -1
- package/package.json +10 -10
- package/src/build-schema.ts +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.11.4](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.3...@loopback/repository-json-schema@1.11.4) (2020-01-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.11.3](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.2...@loopback/repository-json-schema@1.11.3) (2019-12-09)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [1.11.2](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.1...@loopback/repository-json-schema@1.11.2) (2019-11-25)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [1.11.1](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.11.0...@loopback/repository-json-schema@1.11.1) (2019-11-12)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @loopback/repository-json-schema
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
# [1.11.0](https://github.com/strongloop/loopback-next/compare/@loopback/repository-json-schema@1.10.3...@loopback/repository-json-schema@1.11.0) (2019-10-24)
|
|
7
39
|
|
|
8
40
|
|
package/dist/build-schema.js
CHANGED
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
// Node module: @loopback/repository-json-schema
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
const context_1 = require("@loopback/context");
|
|
8
11
|
const repository_1 = require("@loopback/repository");
|
|
9
|
-
const
|
|
12
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
13
|
const util_1 = require("util");
|
|
11
14
|
const keys_1 = require("./keys");
|
|
12
|
-
const debug =
|
|
15
|
+
const debug = debug_1.default('loopback:repository-json-schema:build-schema');
|
|
13
16
|
/**
|
|
14
17
|
* @internal
|
|
15
18
|
*/
|
|
16
19
|
function buildModelCacheKey(options = {}) {
|
|
20
|
+
var _a;
|
|
17
21
|
// Backwards compatibility: preserve cache key "modelOnly"
|
|
18
22
|
if (Object.keys(options).length === 0) {
|
|
19
23
|
return "modelOnly" /* ModelOnly */;
|
|
@@ -21,7 +25,7 @@ function buildModelCacheKey(options = {}) {
|
|
|
21
25
|
// New key schema: use the same suffix as we use for schema title
|
|
22
26
|
// For example: "modelPartialWithRelations"
|
|
23
27
|
// Note this new key schema preserves the old key "modelWithRelations"
|
|
24
|
-
return 'model' + (options.title
|
|
28
|
+
return 'model' + (_a = options.title, (_a !== null && _a !== void 0 ? _a : '')) + getTitleSuffix(options);
|
|
25
29
|
}
|
|
26
30
|
exports.buildModelCacheKey = buildModelCacheKey;
|
|
27
31
|
/**
|
|
@@ -30,11 +34,12 @@ exports.buildModelCacheKey = buildModelCacheKey;
|
|
|
30
34
|
* @param ctor - Contructor of class to get JSON Schema from
|
|
31
35
|
*/
|
|
32
36
|
function getJsonSchema(ctor, options) {
|
|
37
|
+
var _a;
|
|
33
38
|
// In the near future the metadata will be an object with
|
|
34
39
|
// different titles as keys
|
|
35
40
|
const cached = context_1.MetadataInspector.getClassMetadata(keys_1.JSON_SCHEMA_KEY, ctor);
|
|
36
41
|
const key = buildModelCacheKey(options);
|
|
37
|
-
let schema = cached
|
|
42
|
+
let schema = (_a = cached) === null || _a === void 0 ? void 0 : _a[key];
|
|
38
43
|
if (!schema) {
|
|
39
44
|
// Create new json schema from model
|
|
40
45
|
// if not found in cache for specific key
|
|
@@ -271,9 +276,10 @@ function getDescriptionSuffix(rawOptions = {}) {
|
|
|
271
276
|
* @param ctor - Constructor of class to convert from
|
|
272
277
|
*/
|
|
273
278
|
function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
279
|
+
var _a, _b, _c, _d, _e;
|
|
274
280
|
const options = Object.assign({}, jsonSchemaOptions);
|
|
275
|
-
options.visited = options.visited
|
|
276
|
-
options.optional = options.optional
|
|
281
|
+
options.visited = (_a = options.visited, (_a !== null && _a !== void 0 ? _a : {}));
|
|
282
|
+
options.optional = (_b = options.optional, (_b !== null && _b !== void 0 ? _b : []));
|
|
277
283
|
const partial = options.partial && !options.optional.length;
|
|
278
284
|
if (options.partial && !partial) {
|
|
279
285
|
debug('Overriding "partial" option with "optional" option');
|
|
@@ -307,7 +313,7 @@ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
|
307
313
|
if (!meta.properties[p].type) {
|
|
308
314
|
continue;
|
|
309
315
|
}
|
|
310
|
-
result.properties = result.properties
|
|
316
|
+
result.properties = (_c = result.properties, (_c !== null && _c !== void 0 ? _c : {}));
|
|
311
317
|
result.properties[p] = result.properties[p] || {};
|
|
312
318
|
const metaProperty = Object.assign({}, meta.properties[p]);
|
|
313
319
|
// populating "properties" key
|
|
@@ -315,7 +321,7 @@ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
|
315
321
|
// handling 'required' metadata
|
|
316
322
|
const optional = options.optional.includes(p);
|
|
317
323
|
if (metaProperty.required && !(partial || optional)) {
|
|
318
|
-
result.required = result.required
|
|
324
|
+
result.required = (_d = result.required, (_d !== null && _d !== void 0 ? _d : []));
|
|
319
325
|
result.required.push(p);
|
|
320
326
|
}
|
|
321
327
|
// populating JSON Schema 'definitions'
|
|
@@ -337,7 +343,7 @@ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
|
337
343
|
debug(' additionalProperties?', result.additionalProperties);
|
|
338
344
|
if (options.includeRelations) {
|
|
339
345
|
for (const r in meta.relations) {
|
|
340
|
-
result.properties = result.properties
|
|
346
|
+
result.properties = (_e = result.properties, (_e !== null && _e !== void 0 ? _e : {}));
|
|
341
347
|
const relMeta = meta.relations[r];
|
|
342
348
|
const targetType = repository_1.resolveType(relMeta.target);
|
|
343
349
|
const targetSchema = getJsonSchema(targetType, options);
|
|
@@ -349,6 +355,7 @@ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
|
349
355
|
}
|
|
350
356
|
}
|
|
351
357
|
function includeReferencedSchema(name, schema) {
|
|
358
|
+
var _a, _b;
|
|
352
359
|
if (!schema || !Object.keys(schema).length)
|
|
353
360
|
return;
|
|
354
361
|
// promote nested definition to the top level
|
|
@@ -356,13 +363,13 @@ function modelToJsonSchema(ctor, jsonSchemaOptions = {}) {
|
|
|
356
363
|
for (const key in schema.definitions) {
|
|
357
364
|
if (key === title)
|
|
358
365
|
continue;
|
|
359
|
-
result.definitions = result.definitions
|
|
366
|
+
result.definitions = (_a = result.definitions, (_a !== null && _a !== void 0 ? _a : {}));
|
|
360
367
|
result.definitions[key] = schema.definitions[key];
|
|
361
368
|
}
|
|
362
369
|
delete schema.definitions;
|
|
363
370
|
}
|
|
364
371
|
if (result !== schema) {
|
|
365
|
-
result.definitions = result.definitions
|
|
372
|
+
result.definitions = (_b = result.definitions, (_b !== null && _b !== void 0 ? _b : {}));
|
|
366
373
|
result.definitions[name] = schema;
|
|
367
374
|
}
|
|
368
375
|
}
|
package/dist/build-schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-schema.js","sourceRoot":"","sources":["../src/build-schema.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,gDAAgD;AAChD,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"build-schema.js","sourceRoot":"","sources":["../src/build-schema.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,gDAAgD;AAChD,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,+CAAoD;AACpD,qDAO8B;AAC9B,kDAAiC;AAEjC,+BAA6B;AAC7B,iCAAwD;AACxD,MAAM,KAAK,GAAG,eAAY,CAAC,8CAA8C,CAAC,CAAC;AA0C3E;;GAEG;AACH,SAAgB,kBAAkB,CAChC,UAAgC,EAAE;;IAElC,0DAA0D;IAC1D,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,mCAAiC;KAClC;IAED,iEAAiE;IACjE,2CAA2C;IAC3C,sEAAsE;IACtE,OAAO,OAAO,GAAG,MAAC,OAAO,CAAC,KAAK,uCAAI,EAAE,EAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AACnE,CAAC;AAZD,gDAYC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAC3B,IAA+B,EAC/B,OAA8B;;IAE9B,yDAAyD;IACzD,2BAA2B;IAC3B,MAAM,MAAM,GAAG,2BAAiB,CAAC,gBAAgB,CAAC,sBAAe,EAAE,IAAI,CAAC,CAAC;IACzE,MAAM,GAAG,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,MAAM,SAAG,MAAM,0CAAG,GAAG,CAAC,CAAC;IAE3B,IAAI,CAAC,MAAM,EAAE;QACX,oCAAoC;QACpC,yCAAyC;QACzC,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,SAAG,MAAM,CAAC,WAAW,uCAAI,EAAE,EAAA,CAAC;YAC9C,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;SACnC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AA5HD,8CA4HC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/repository-json-schema",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.4",
|
|
4
4
|
"description": "Converts TS classes into JSON Schemas using TypeScript's reflection API",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@loopback/context": "^1.
|
|
27
|
-
"@loopback/metadata": "^1.3.
|
|
28
|
-
"@loopback/repository": "^1.
|
|
29
|
-
"@types/json-schema": "^7.0.
|
|
26
|
+
"@loopback/context": "^1.25.1",
|
|
27
|
+
"@loopback/metadata": "^1.3.10",
|
|
28
|
+
"@loopback/repository": "^1.17.0",
|
|
29
|
+
"@types/json-schema": "^7.0.4",
|
|
30
30
|
"debug": "^4.1.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@loopback/build": "^
|
|
34
|
-
"@loopback/eslint-config": "^
|
|
35
|
-
"@loopback/testlab": "^1.
|
|
33
|
+
"@loopback/build": "^3.0.1",
|
|
34
|
+
"@loopback/eslint-config": "^5.0.1",
|
|
35
|
+
"@loopback/testlab": "^1.10.1",
|
|
36
36
|
"@types/debug": "^4.1.5",
|
|
37
|
-
"@types/node": "^10.17.
|
|
37
|
+
"@types/node": "^10.17.13",
|
|
38
38
|
"ajv": "^6.10.2"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
51
51
|
"directory": "packages/repository-json-schema"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "598baf6e84de3917bb67aff47a1ab1cb1111e3d2"
|
|
54
54
|
}
|
package/src/build-schema.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
RelationMetadata,
|
|
13
13
|
resolveType,
|
|
14
14
|
} from '@loopback/repository';
|
|
15
|
-
import
|
|
15
|
+
import debugFactory from 'debug';
|
|
16
16
|
import {JSONSchema6 as JSONSchema} from 'json-schema';
|
|
17
17
|
import {inspect} from 'util';
|
|
18
18
|
import {JSON_SCHEMA_KEY, MODEL_TYPE_KEYS} from './keys';
|
|
@@ -72,7 +72,7 @@ export function buildModelCacheKey<T extends object>(
|
|
|
72
72
|
// New key schema: use the same suffix as we use for schema title
|
|
73
73
|
// For example: "modelPartialWithRelations"
|
|
74
74
|
// Note this new key schema preserves the old key "modelWithRelations"
|
|
75
|
-
return 'model' + (options.title
|
|
75
|
+
return 'model' + (options.title ?? '') + getTitleSuffix(options);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -88,7 +88,7 @@ export function getJsonSchema<T extends object>(
|
|
|
88
88
|
// different titles as keys
|
|
89
89
|
const cached = MetadataInspector.getClassMetadata(JSON_SCHEMA_KEY, ctor);
|
|
90
90
|
const key = buildModelCacheKey(options);
|
|
91
|
-
let schema = cached
|
|
91
|
+
let schema = cached?.[key];
|
|
92
92
|
|
|
93
93
|
if (!schema) {
|
|
94
94
|
// Create new json schema from model
|
|
@@ -357,8 +357,8 @@ export function modelToJsonSchema<T extends object>(
|
|
|
357
357
|
jsonSchemaOptions: JsonSchemaOptions<T> = {},
|
|
358
358
|
): JSONSchema {
|
|
359
359
|
const options = {...jsonSchemaOptions};
|
|
360
|
-
options.visited = options.visited
|
|
361
|
-
options.optional = options.optional
|
|
360
|
+
options.visited = options.visited ?? {};
|
|
361
|
+
options.optional = options.optional ?? [];
|
|
362
362
|
const partial = options.partial && !options.optional.length;
|
|
363
363
|
|
|
364
364
|
if (options.partial && !partial) {
|
|
@@ -404,7 +404,7 @@ export function modelToJsonSchema<T extends object>(
|
|
|
404
404
|
continue;
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
result.properties = result.properties
|
|
407
|
+
result.properties = result.properties ?? {};
|
|
408
408
|
result.properties[p] = result.properties[p] || {};
|
|
409
409
|
|
|
410
410
|
const metaProperty = Object.assign({}, meta.properties[p]);
|
|
@@ -416,7 +416,7 @@ export function modelToJsonSchema<T extends object>(
|
|
|
416
416
|
const optional = options.optional.includes(p as keyof T);
|
|
417
417
|
|
|
418
418
|
if (metaProperty.required && !(partial || optional)) {
|
|
419
|
-
result.required = result.required
|
|
419
|
+
result.required = result.required ?? [];
|
|
420
420
|
result.required.push(p);
|
|
421
421
|
}
|
|
422
422
|
|
|
@@ -444,7 +444,7 @@ export function modelToJsonSchema<T extends object>(
|
|
|
444
444
|
|
|
445
445
|
if (options.includeRelations) {
|
|
446
446
|
for (const r in meta.relations) {
|
|
447
|
-
result.properties = result.properties
|
|
447
|
+
result.properties = result.properties ?? {};
|
|
448
448
|
const relMeta = meta.relations[r];
|
|
449
449
|
const targetType = resolveType(relMeta.target);
|
|
450
450
|
const targetSchema = getJsonSchema(targetType, options);
|
|
@@ -464,14 +464,14 @@ export function modelToJsonSchema<T extends object>(
|
|
|
464
464
|
if (result !== schema && schema.definitions) {
|
|
465
465
|
for (const key in schema.definitions) {
|
|
466
466
|
if (key === title) continue;
|
|
467
|
-
result.definitions = result.definitions
|
|
467
|
+
result.definitions = result.definitions ?? {};
|
|
468
468
|
result.definitions[key] = schema.definitions[key];
|
|
469
469
|
}
|
|
470
470
|
delete schema.definitions;
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
if (result !== schema) {
|
|
474
|
-
result.definitions = result.definitions
|
|
474
|
+
result.definitions = result.definitions ?? {};
|
|
475
475
|
result.definitions[name] = schema;
|
|
476
476
|
}
|
|
477
477
|
}
|