@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/index.cjs CHANGED
@@ -1594,6 +1594,66 @@ function generateCustomType(type, ctx) {
1594
1594
  }
1595
1595
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
1596
1596
  }
1597
+ var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1598
+ "$schema",
1599
+ "$ref",
1600
+ "$defs",
1601
+ "$id",
1602
+ "$anchor",
1603
+ "$dynamicRef",
1604
+ "$dynamicAnchor",
1605
+ "$vocabulary",
1606
+ "$comment",
1607
+ "type",
1608
+ "enum",
1609
+ "const",
1610
+ "properties",
1611
+ "patternProperties",
1612
+ "additionalProperties",
1613
+ "required",
1614
+ "items",
1615
+ "prefixItems",
1616
+ "additionalItems",
1617
+ "contains",
1618
+ "allOf",
1619
+ "oneOf",
1620
+ "anyOf",
1621
+ "not",
1622
+ "if",
1623
+ "then",
1624
+ "else",
1625
+ "minimum",
1626
+ "maximum",
1627
+ "exclusiveMinimum",
1628
+ "exclusiveMaximum",
1629
+ "multipleOf",
1630
+ "minLength",
1631
+ "maxLength",
1632
+ "pattern",
1633
+ "minItems",
1634
+ "maxItems",
1635
+ "uniqueItems",
1636
+ "minProperties",
1637
+ "maxProperties",
1638
+ "minContains",
1639
+ "maxContains",
1640
+ "format",
1641
+ "title",
1642
+ "description",
1643
+ "default",
1644
+ "deprecated",
1645
+ "readOnly",
1646
+ "writeOnly",
1647
+ "examples",
1648
+ "dependentRequired",
1649
+ "dependentSchemas",
1650
+ "propertyNames",
1651
+ "unevaluatedItems",
1652
+ "unevaluatedProperties",
1653
+ "contentEncoding",
1654
+ "contentMediaType",
1655
+ "contentSchema"
1656
+ ]);
1597
1657
  function applyCustomConstraint(schema, constraint, ctx) {
1598
1658
  const registration = ctx.extensionRegistry?.findConstraint(constraint.constraintId);
1599
1659
  if (registration === void 0) {
@@ -1601,12 +1661,25 @@ function applyCustomConstraint(schema, constraint, ctx) {
1601
1661
  `Cannot generate JSON Schema for custom constraint "${constraint.constraintId}" without a matching extension registration`
1602
1662
  );
1603
1663
  }
1604
- assignVendorPrefixedExtensionKeywords(
1605
- schema,
1606
- registration.toJsonSchema(constraint.payload, ctx.vendorPrefix),
1607
- ctx.vendorPrefix,
1608
- `custom constraint "${constraint.constraintId}"`
1609
- );
1664
+ const extensionSchema = registration.toJsonSchema(constraint.payload, ctx.vendorPrefix);
1665
+ if (registration.emitsVocabularyKeywords) {
1666
+ const target = schema;
1667
+ for (const [key, value] of Object.entries(extensionSchema)) {
1668
+ if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1669
+ throw new Error(
1670
+ `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1671
+ );
1672
+ }
1673
+ target[key] = value;
1674
+ }
1675
+ } else {
1676
+ assignVendorPrefixedExtensionKeywords(
1677
+ schema,
1678
+ extensionSchema,
1679
+ ctx.vendorPrefix,
1680
+ `custom constraint "${constraint.constraintId}"`
1681
+ );
1682
+ }
1610
1683
  }
1611
1684
  function applyCustomAnnotation(schema, annotation, ctx) {
1612
1685
  const registration = ctx.extensionRegistry?.findAnnotation(annotation.annotationId);