@takeshape/schema 8.186.0 → 8.189.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template-shapes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAuB,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAmChD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAChB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/template-shapes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAuB,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAmChD,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAChB,gBAAgB,CAWlB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -32,6 +32,10 @@ function resolveTemplate(projectSchema, templateName, shapeName) {
|
|
|
32
32
|
throw new Error(`Invalid shape template ${templateName}`);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
if (projectSchema.shapes[shapeName] === undefined) {
|
|
36
|
+
throw new Error(`Unknown shape "${shapeName}" in template "${templateName}"`);
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
return mapping({
|
|
36
40
|
projectSchema
|
|
37
41
|
}, projectSchema.shapes[shapeName]);
|
package/dist/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts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MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,sBAAsB,CAAC;CAClF;AACD,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,iBAAiB,GAAG,SAAS,CAAC;CACnE;AAqKD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,sBAAsB,CAqB9F;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAgBnE;AAgBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,OAAO,GAAG,SAAS,CAQpE;AAgBD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,CAQlE;AAqBD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,OAAO,GAAG,mBAAmB,CAarF"}
|
package/dist/validate.js
CHANGED
|
@@ -60,8 +60,16 @@ var _util = require("@takeshape/util");
|
|
|
60
60
|
|
|
61
61
|
var _forOwn = _interopRequireDefault(require("lodash/forOwn"));
|
|
62
62
|
|
|
63
|
+
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
|
|
64
|
+
|
|
65
|
+
var _initial = _interopRequireDefault(require("lodash/initial"));
|
|
66
|
+
|
|
67
|
+
var _last = _interopRequireDefault(require("lodash/last"));
|
|
68
|
+
|
|
63
69
|
var _relationships = require("./relationships");
|
|
64
70
|
|
|
71
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
72
|
+
|
|
65
73
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
66
74
|
|
|
67
75
|
function findDuplicates(items) {
|
|
@@ -412,6 +420,18 @@ function validateRefs(projectSchema, additionalShapeNames = builtInShapeNames) {
|
|
|
412
420
|
message: `allOf cannot be self-referential`
|
|
413
421
|
});
|
|
414
422
|
}
|
|
423
|
+
|
|
424
|
+
const parentPath = (0, _initial.default)(item.path);
|
|
425
|
+
const parentSchema = (0, _get.default)(projectSchema, parentPath);
|
|
426
|
+
const propName = (0, _last.default)(item.path);
|
|
427
|
+
|
|
428
|
+
if (propName === '@ref' && parentSchema.$ref) {
|
|
429
|
+
errors.push({
|
|
430
|
+
type: 'conflict',
|
|
431
|
+
path: parentPath,
|
|
432
|
+
message: `Ref cannot have both @ref and $ref`
|
|
433
|
+
});
|
|
434
|
+
}
|
|
415
435
|
});
|
|
416
436
|
}
|
|
417
437
|
|
|
@@ -471,14 +491,23 @@ function validateOneOfs(projectSchema) {
|
|
|
471
491
|
const oneOfPath = property.items ? ['items', 'oneOf'] : ['oneOf'];
|
|
472
492
|
const relationship = (0, _relationships.getRelationship)(property);
|
|
473
493
|
const schema = property.items ? property.items : property;
|
|
494
|
+
const isUnion = (0, _unions.isUnionSchema)(schema);
|
|
474
495
|
|
|
475
|
-
if (schema.oneOf && !relationship && !
|
|
496
|
+
if (schema.oneOf && !relationship && !isUnion && !(0, _enum.isEnumLikeSchema)(schema)) {
|
|
476
497
|
errors.push({
|
|
477
|
-
type: '
|
|
498
|
+
type: 'conflict',
|
|
478
499
|
path: propertyPath.concat(oneOfPath),
|
|
479
500
|
message: `Invalid oneOf must contain only @ref or title + enum/const schemas`
|
|
480
501
|
});
|
|
481
502
|
}
|
|
503
|
+
|
|
504
|
+
if (isUnion && schema.oneOf.length !== (0, _uniqBy.default)(schema.oneOf, refSchema => (0, _refs.getRefShapeName)(projectSchema, refSchema)).length) {
|
|
505
|
+
errors.push({
|
|
506
|
+
type: 'conflict',
|
|
507
|
+
path: propertyPath.concat(oneOfPath),
|
|
508
|
+
message: `Invalid oneOf must not contain duplicate references`
|
|
509
|
+
});
|
|
510
|
+
}
|
|
482
511
|
});
|
|
483
512
|
return errors;
|
|
484
513
|
}
|
|
@@ -22,6 +22,10 @@ export function resolveTemplate(projectSchema, templateName, shapeName) {
|
|
|
22
22
|
throw new Error(`Invalid shape template ${templateName}`);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
if (projectSchema.shapes[shapeName] === undefined) {
|
|
26
|
+
throw new Error(`Unknown shape "${shapeName}" in template "${templateName}"`);
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
return mapping({
|
|
26
30
|
projectSchema
|
|
27
31
|
}, projectSchema.shapes[shapeName]);
|
package/es/validate.js
CHANGED
|
@@ -16,14 +16,18 @@ import { getAllNamespaceShapes, getAllRefsInShapes } from './schema-util';
|
|
|
16
16
|
import { builtInShapes } from './builtin-schema';
|
|
17
17
|
import { isValidTemplate } from './template-shapes';
|
|
18
18
|
import { isBasicResolver, isComposeResolver } from './types/utils';
|
|
19
|
-
import { refItemToAtRef, refItemToShapeName, parseReturnShape } from './refs';
|
|
19
|
+
import { refItemToAtRef, refItemToShapeName, parseReturnShape, getRefShapeName } from './refs';
|
|
20
20
|
import { scalars } from './scalars';
|
|
21
21
|
import { isUnionSchema } from './unions';
|
|
22
22
|
import { isEnumLikeSchema } from './enum';
|
|
23
23
|
import metaSchemaV3_9_0 from './schemas/project-schema/meta-schema-v3.9.0.json';
|
|
24
24
|
import { isIntegerLike } from '@takeshape/util';
|
|
25
25
|
import forOwn from 'lodash/forOwn';
|
|
26
|
+
import uniqBy from 'lodash/uniqBy';
|
|
27
|
+
import initial from 'lodash/initial';
|
|
28
|
+
import last from 'lodash/last';
|
|
26
29
|
import { getRelationship } from './relationships';
|
|
30
|
+
import get from 'lodash/get';
|
|
27
31
|
|
|
28
32
|
function findDuplicates(items) {
|
|
29
33
|
const seen = {};
|
|
@@ -373,6 +377,18 @@ function validateRefs(projectSchema, additionalShapeNames = builtInShapeNames) {
|
|
|
373
377
|
message: `allOf cannot be self-referential`
|
|
374
378
|
});
|
|
375
379
|
}
|
|
380
|
+
|
|
381
|
+
const parentPath = initial(item.path);
|
|
382
|
+
const parentSchema = get(projectSchema, parentPath);
|
|
383
|
+
const propName = last(item.path);
|
|
384
|
+
|
|
385
|
+
if (propName === '@ref' && parentSchema.$ref) {
|
|
386
|
+
errors.push({
|
|
387
|
+
type: 'conflict',
|
|
388
|
+
path: parentPath,
|
|
389
|
+
message: `Ref cannot have both @ref and $ref`
|
|
390
|
+
});
|
|
391
|
+
}
|
|
376
392
|
});
|
|
377
393
|
}
|
|
378
394
|
|
|
@@ -432,14 +448,23 @@ function validateOneOfs(projectSchema) {
|
|
|
432
448
|
const oneOfPath = property.items ? ['items', 'oneOf'] : ['oneOf'];
|
|
433
449
|
const relationship = getRelationship(property);
|
|
434
450
|
const schema = property.items ? property.items : property;
|
|
451
|
+
const isUnion = isUnionSchema(schema);
|
|
435
452
|
|
|
436
|
-
if (schema.oneOf && !relationship && !
|
|
453
|
+
if (schema.oneOf && !relationship && !isUnion && !isEnumLikeSchema(schema)) {
|
|
437
454
|
errors.push({
|
|
438
|
-
type: '
|
|
455
|
+
type: 'conflict',
|
|
439
456
|
path: propertyPath.concat(oneOfPath),
|
|
440
457
|
message: `Invalid oneOf must contain only @ref or title + enum/const schemas`
|
|
441
458
|
});
|
|
442
459
|
}
|
|
460
|
+
|
|
461
|
+
if (isUnion && schema.oneOf.length !== uniqBy(schema.oneOf, refSchema => getRefShapeName(projectSchema, refSchema)).length) {
|
|
462
|
+
errors.push({
|
|
463
|
+
type: 'conflict',
|
|
464
|
+
path: propertyPath.concat(oneOfPath),
|
|
465
|
+
message: `Invalid oneOf must not contain duplicate references`
|
|
466
|
+
});
|
|
467
|
+
}
|
|
443
468
|
});
|
|
444
469
|
return errors;
|
|
445
470
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.189.0",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"examples"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@takeshape/errors": "8.
|
|
25
|
-
"@takeshape/json-schema": "8.
|
|
26
|
-
"@takeshape/util": "8.
|
|
24
|
+
"@takeshape/errors": "8.189.0",
|
|
25
|
+
"@takeshape/json-schema": "8.189.0",
|
|
26
|
+
"@takeshape/util": "8.189.0",
|
|
27
27
|
"ajv": "^8.10.0",
|
|
28
28
|
"ajv-formats": "^2.1.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|