@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.js CHANGED
@@ -1535,6 +1535,66 @@ function generateCustomType(type, ctx) {
1535
1535
  }
1536
1536
  return registration.toJsonSchema(type.payload, ctx.vendorPrefix);
1537
1537
  }
1538
+ var JSON_SCHEMA_STRUCTURAL_KEYWORDS = /* @__PURE__ */ new Set([
1539
+ "$schema",
1540
+ "$ref",
1541
+ "$defs",
1542
+ "$id",
1543
+ "$anchor",
1544
+ "$dynamicRef",
1545
+ "$dynamicAnchor",
1546
+ "$vocabulary",
1547
+ "$comment",
1548
+ "type",
1549
+ "enum",
1550
+ "const",
1551
+ "properties",
1552
+ "patternProperties",
1553
+ "additionalProperties",
1554
+ "required",
1555
+ "items",
1556
+ "prefixItems",
1557
+ "additionalItems",
1558
+ "contains",
1559
+ "allOf",
1560
+ "oneOf",
1561
+ "anyOf",
1562
+ "not",
1563
+ "if",
1564
+ "then",
1565
+ "else",
1566
+ "minimum",
1567
+ "maximum",
1568
+ "exclusiveMinimum",
1569
+ "exclusiveMaximum",
1570
+ "multipleOf",
1571
+ "minLength",
1572
+ "maxLength",
1573
+ "pattern",
1574
+ "minItems",
1575
+ "maxItems",
1576
+ "uniqueItems",
1577
+ "minProperties",
1578
+ "maxProperties",
1579
+ "minContains",
1580
+ "maxContains",
1581
+ "format",
1582
+ "title",
1583
+ "description",
1584
+ "default",
1585
+ "deprecated",
1586
+ "readOnly",
1587
+ "writeOnly",
1588
+ "examples",
1589
+ "dependentRequired",
1590
+ "dependentSchemas",
1591
+ "propertyNames",
1592
+ "unevaluatedItems",
1593
+ "unevaluatedProperties",
1594
+ "contentEncoding",
1595
+ "contentMediaType",
1596
+ "contentSchema"
1597
+ ]);
1538
1598
  function applyCustomConstraint(schema, constraint, ctx) {
1539
1599
  const registration = ctx.extensionRegistry?.findConstraint(constraint.constraintId);
1540
1600
  if (registration === void 0) {
@@ -1542,12 +1602,25 @@ function applyCustomConstraint(schema, constraint, ctx) {
1542
1602
  `Cannot generate JSON Schema for custom constraint "${constraint.constraintId}" without a matching extension registration`
1543
1603
  );
1544
1604
  }
1545
- assignVendorPrefixedExtensionKeywords(
1546
- schema,
1547
- registration.toJsonSchema(constraint.payload, ctx.vendorPrefix),
1548
- ctx.vendorPrefix,
1549
- `custom constraint "${constraint.constraintId}"`
1550
- );
1605
+ const extensionSchema = registration.toJsonSchema(constraint.payload, ctx.vendorPrefix);
1606
+ if (registration.emitsVocabularyKeywords) {
1607
+ const target = schema;
1608
+ for (const [key, value] of Object.entries(extensionSchema)) {
1609
+ if (JSON_SCHEMA_STRUCTURAL_KEYWORDS.has(key)) {
1610
+ throw new Error(
1611
+ `Custom constraint "${constraint.constraintId}" with emitsVocabularyKeywords must not overwrite standard JSON Schema keyword "${key}"`
1612
+ );
1613
+ }
1614
+ target[key] = value;
1615
+ }
1616
+ } else {
1617
+ assignVendorPrefixedExtensionKeywords(
1618
+ schema,
1619
+ extensionSchema,
1620
+ ctx.vendorPrefix,
1621
+ `custom constraint "${constraint.constraintId}"`
1622
+ );
1623
+ }
1551
1624
  }
1552
1625
  function applyCustomAnnotation(schema, annotation, ctx) {
1553
1626
  const registration = ctx.extensionRegistry?.findAnnotation(annotation.annotationId);