@takeshape/schema 8.188.2 → 8.189.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.
Files changed (74) hide show
  1. package/dist/migration/index.d.ts +1 -0
  2. package/dist/migration/index.d.ts.map +1 -1
  3. package/dist/migration/index.js +4 -1
  4. package/dist/migration/to/v3.18.1.d.ts +5 -0
  5. package/dist/migration/to/v3.18.1.d.ts.map +1 -0
  6. package/dist/migration/to/v3.18.1.js +28 -0
  7. package/dist/project-schema/index.d.ts +4 -1
  8. package/dist/project-schema/index.d.ts.map +1 -1
  9. package/dist/project-schema/index.js +20 -3
  10. package/dist/project-schema/latest.d.ts +1 -2
  11. package/dist/project-schema/latest.d.ts.map +1 -1
  12. package/dist/project-schema/migrate.d.ts.map +1 -1
  13. package/dist/project-schema/migrate.js +4 -0
  14. package/dist/project-schema/v3.18.1.d.ts +1333 -0
  15. package/dist/project-schema/v3.18.1.d.ts.map +1 -0
  16. package/dist/project-schema/v3.18.1.js +5 -0
  17. package/dist/schema-util.d.ts.map +1 -1
  18. package/dist/schema-util.js +13 -11
  19. package/dist/schemas/index.d.ts +2 -2
  20. package/dist/schemas/index.d.ts.map +1 -1
  21. package/dist/schemas/index.js +6 -4
  22. package/dist/schemas/index.ts +4 -2
  23. package/dist/schemas/project-schema/latest.json +4 -3
  24. package/dist/schemas/project-schema/v3.18.1.json +2351 -0
  25. package/dist/schemas/project-schema.json +3 -0
  26. package/dist/types/types.d.ts +2 -2
  27. package/dist/types/types.d.ts.map +1 -1
  28. package/dist/util/has-arg.d.ts +4 -2
  29. package/dist/util/has-arg.d.ts.map +1 -1
  30. package/dist/util/has-arg.js +6 -1
  31. package/dist/validate.d.ts.map +1 -1
  32. package/dist/validate.js +31 -2
  33. package/es/migration/index.js +3 -1
  34. package/es/migration/to/v3.18.1.js +16 -0
  35. package/es/project-schema/index.js +3 -1
  36. package/es/project-schema/migrate.js +5 -1
  37. package/es/project-schema/v3.18.1.js +1 -0
  38. package/es/schema-util.js +11 -9
  39. package/es/schemas/index.js +4 -3
  40. package/es/schemas/index.ts +4 -2
  41. package/es/schemas/project-schema/latest.json +4 -3
  42. package/es/schemas/project-schema/v3.18.1.json +2351 -0
  43. package/es/schemas/project-schema.json +3 -0
  44. package/es/util/has-arg.js +4 -1
  45. package/es/validate.js +28 -3
  46. package/examples/latest/betzino.json +2276 -2276
  47. package/examples/latest/blog-schema.json +44 -44
  48. package/examples/latest/brewery-schema.json +38 -38
  49. package/examples/latest/complex-project-schema.json +272 -272
  50. package/examples/latest/complex-schema.json +1 -1
  51. package/examples/latest/fabric-ecommerce.json +23 -23
  52. package/examples/latest/frank-and-fred-schema.json +1616 -1616
  53. package/examples/latest/klirr-schema.json +1951 -1951
  54. package/examples/latest/massive-schema.json +428 -428
  55. package/examples/latest/mill-components-schema.json +200 -200
  56. package/examples/latest/one-earth.json +613 -613
  57. package/examples/latest/pet-oneof-array.json +38 -38
  58. package/examples/latest/post-schema.json +38 -38
  59. package/examples/latest/pruned-shopify-product-schema.json +8 -8
  60. package/examples/latest/real-world-schema.json +80 -80
  61. package/examples/latest/recursive-repeater-schema.json +20 -20
  62. package/examples/latest/recursive-schema.json +20 -20
  63. package/examples/latest/rick-and-morty-ast.json +150 -150
  64. package/examples/latest/rick-and-morty-graphql.json +114 -114
  65. package/examples/latest/rick-and-morty-rest.json +5 -5
  66. package/examples/latest/schema-with-repeater-draftjs.json +20 -20
  67. package/examples/latest/shape-books-v3_2_0.json +122 -122
  68. package/examples/latest/shape-books.json +122 -122
  69. package/examples/latest/shopify-lookbook.json +44 -44
  70. package/examples/latest/shopify-store-with-widget.json +80 -80
  71. package/examples/latest/stripe-starter-resolved.json +83 -83
  72. package/examples/latest/user-schema-no-required.json +20 -20
  73. package/examples/latest/user-schema-with-defaults.json +20 -20
  74. package/package.json +4 -4
@@ -78,6 +78,9 @@
78
78
  {
79
79
  "$ref": "https://schema.takeshape.io/project-schema/v3.18.0#"
80
80
  },
81
+ {
82
+ "$ref": "https://schema.takeshape.io/project-schema/v3.18.1#"
83
+ },
81
84
  {
82
85
  "$ref": "https://schema.takeshape.io/project-schema/v4.0.0#"
83
86
  }
@@ -1,8 +1,11 @@
1
1
  import { findSchemaAtPath } from './find-shape-at-path';
2
+ export function getArgs(prop) {
3
+ return '@args' in prop ? prop['@args'] : 'args' in prop ? prop.args : undefined;
4
+ }
2
5
  export function hasArg(projectSchema, prop, argPath) {
3
6
  var _projectSchema$shapes;
4
7
 
5
- const args = 'args' in prop ? prop.args : prop['@args'];
8
+ const args = getArgs(prop);
6
9
 
7
10
  if (!args) {
8
11
  return false;
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 && !isUnionSchema(schema) && !isEnumLikeSchema(schema)) {
453
+ if (schema.oneOf && !relationship && !isUnion && !isEnumLikeSchema(schema)) {
437
454
  errors.push({
438
- type: 'json',
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
  }