@formspec/build 0.1.0-alpha.41 → 0.1.0-alpha.42

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/dist/browser.cjs CHANGED
@@ -1473,6 +1473,66 @@ function generateCustomType(type, ctx) {
1473
1473
  }
1474
1474
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
1475
1475
  }
1476
+ var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1477
+ "$schema",
1478
+ "$ref",
1479
+ "$defs",
1480
+ "$id",
1481
+ "$anchor",
1482
+ "$dynamicRef",
1483
+ "$dynamicAnchor",
1484
+ "$vocabulary",
1485
+ "$comment",
1486
+ "type",
1487
+ "enum",
1488
+ "const",
1489
+ "properties",
1490
+ "patternProperties",
1491
+ "additionalProperties",
1492
+ "required",
1493
+ "items",
1494
+ "prefixItems",
1495
+ "additionalItems",
1496
+ "contains",
1497
+ "allOf",
1498
+ "oneOf",
1499
+ "anyOf",
1500
+ "not",
1501
+ "if",
1502
+ "then",
1503
+ "else",
1504
+ "minimum",
1505
+ "maximum",
1506
+ "exclusiveMinimum",
1507
+ "exclusiveMaximum",
1508
+ "multipleOf",
1509
+ "minLength",
1510
+ "maxLength",
1511
+ "pattern",
1512
+ "minItems",
1513
+ "maxItems",
1514
+ "uniqueItems",
1515
+ "minProperties",
1516
+ "maxProperties",
1517
+ "minContains",
1518
+ "maxContains",
1519
+ "format",
1520
+ "title",
1521
+ "description",
1522
+ "default",
1523
+ "deprecated",
1524
+ "readOnly",
1525
+ "writeOnly",
1526
+ "examples",
1527
+ "dependentRequired",
1528
+ "dependentSchemas",
1529
+ "propertyNames",
1530
+ "unevaluatedItems",
1531
+ "unevaluatedProperties",
1532
+ "contentEncoding",
1533
+ "contentMediaType",
1534
+ "contentSchema"
1535
+ ]);
1476
1536
  function applyCustomConstraint(schema, constraint, ctx) {
1477
1537
  const registration = ctx.extensionRegistry?.findConstraint(constraint.constraintId);
1478
1538
  if (registration === void 0) {
@@ -1480,12 +1540,25 @@ function applyCustomConstraint(schema, constraint, ctx) {
1480
1540
  `Cannot generate JSON Schema for custom constraint "${constraint.constraintId}" without a matching extension registration`
1481
1541
  );
1482
1542
  }
1483
- assignVendorPrefixedExtensionKeywords(
1484
- schema,
1485
- registration.toJsonSchema(constraint.payload, ctx.vendorPrefix),
1486
- ctx.vendorPrefix,
1487
- `custom constraint "${constraint.constraintId}"`
1488
- );
1543
+ const extensionSchema = registration.toJsonSchema(constraint.payload, ctx.vendorPrefix);
1544
+ if (registration.emitsVocabularyKeywords) {
1545
+ const target = schema;
1546
+ for (const [key, value] of Object.entries(extensionSchema)) {
1547
+ if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1548
+ throw new Error(
1549
+ `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1550
+ );
1551
+ }
1552
+ target[key] = value;
1553
+ }
1554
+ } else {
1555
+ assignVendorPrefixedExtensionKeywords(
1556
+ schema,
1557
+ extensionSchema,
1558
+ ctx.vendorPrefix,
1559
+ `custom constraint "${constraint.constraintId}"`
1560
+ );
1561
+ }
1489
1562
  }
1490
1563
  function applyCustomAnnotation(schema, annotation, ctx) {
1491
1564
  const registration = ctx.extensionRegistry?.findAnnotation(annotation.annotationId);