jedison 1.22.3 → 1.23.1

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.
@@ -3126,7 +3126,11 @@ class InstanceObject extends Instance {
3126
3126
  const initialValue = clone(this.value);
3127
3127
  if (isSet(schemaProperties)) {
3128
3128
  Object.keys(schemaProperties).forEach((key) => {
3129
- const schema = schemaProperties[key];
3129
+ let schema = schemaProperties[key];
3130
+ if (isObject$1(schema) && this.jedison.refParser && this.jedison.refParser.hasRef(schema) && !schema["x-recursive"]) {
3131
+ schema = this.jedison.refParser.expand(schema);
3132
+ schemaProperties[key] = schema;
3133
+ }
3130
3134
  this.properties[key] = { schema };
3131
3135
  let musstCreateChild = true;
3132
3136
  const isRecursive = isSet(schema["x-recursive"]);
@@ -3364,10 +3368,15 @@ class InstanceObject extends Instance {
3364
3368
  this.createChild(schema, propertyName, value[propertyName], true);
3365
3369
  }
3366
3370
  });
3371
+ const keepMissingSchemaFields = this.jedison.getOption("keepMissingSchemaFields");
3367
3372
  for (let i = this.children.length - 1; i >= 0; i--) {
3368
3373
  const instance = this.children[i];
3369
3374
  const propertyName = instance.getKey();
3370
3375
  if (notSet(value[propertyName])) {
3376
+ const isSchemaProperty = hasOwn(this.properties, propertyName);
3377
+ if (isSchemaProperty && keepMissingSchemaFields) {
3378
+ continue;
3379
+ }
3371
3380
  if (childMap.has(propertyName)) {
3372
3381
  instance.deactivate();
3373
3382
  } else {
@@ -4362,7 +4371,8 @@ class EditorObject extends Editor {
4362
4371
  getObjectControlConfig() {
4363
4372
  let addProperty = true;
4364
4373
  const additionalProperties2 = getSchemaAdditionalProperties(this.instance.schema);
4365
- if (isSet(additionalProperties2) && additionalProperties2 === false) {
4374
+ const patternProperties2 = getSchemaPatternProperties(this.instance.schema);
4375
+ if (isSet(additionalProperties2) && additionalProperties2 === false && !isSet(patternProperties2)) {
4366
4376
  addProperty = false;
4367
4377
  }
4368
4378
  const objectAdd = getSchemaXOption(this.instance.schema, "objectAdd") ?? this.instance.jedison.getOption("objectAdd");
@@ -4421,10 +4431,38 @@ class EditorObject extends Editor {
4421
4431
  ariaLiveMessage.textContent = label + " " + this.instance.jedison.translator.translate("objectPropertyAdded");
4422
4432
  this.control.ariaLive.appendChild(ariaLiveMessage);
4423
4433
  }
4434
+ /**
4435
+ * A name is only rejected when `additionalProperties: false` is enforced and the
4436
+ * name matches neither `properties` nor `patternProperties` (issue #82) - mirrors
4437
+ * the check InstanceObject.removeNotListedPropertiesFromValue() applies on setValue.
4438
+ */
4439
+ isAddPropertyNameAllowed(propertyName) {
4440
+ const additionalProperties2 = getSchemaAdditionalProperties(this.instance.schema);
4441
+ if (!isSet(additionalProperties2) || additionalProperties2 !== false) {
4442
+ return true;
4443
+ }
4444
+ const schemaEnforceAdditionalProperties = getSchemaXOption(this.instance.schema, "enforceAdditionalProperties");
4445
+ const enforceAdditionalProperties = isSet(schemaEnforceAdditionalProperties) ? schemaEnforceAdditionalProperties : this.instance.jedison.getOption("enforceAdditionalProperties");
4446
+ if (!enforceAdditionalProperties) {
4447
+ return true;
4448
+ }
4449
+ const declaredProperties = getSchemaProperties(this.instance.schema) || {};
4450
+ if (hasOwn(declaredProperties, propertyName)) {
4451
+ return true;
4452
+ }
4453
+ const patternProperties2 = getSchemaPatternProperties(this.instance.schema) || {};
4454
+ return Object.keys(patternProperties2).some((pattern2) => new RegExp(pattern2).test(propertyName));
4455
+ }
4424
4456
  addProperty(input, postAction) {
4425
4457
  const propertyName = input.value.split(" ").join("");
4426
4458
  if (propertyName.length === 0) return;
4427
4459
  if (isSet(this.instance.value[propertyName])) return;
4460
+ this.control.quickAddPropertyControl.messages.replaceChildren();
4461
+ if (!this.isAddPropertyNameAllowed(propertyName)) {
4462
+ const message = compileTemplate(this.instance.jedison.translator.translate("errorAddPropertyPatternMismatch"), { property: propertyName });
4463
+ this.control.quickAddPropertyControl.messages.appendChild(this.getErrorFeedback({ message }));
4464
+ return;
4465
+ }
4428
4466
  const schema = this.instance.getPropertySchema(propertyName);
4429
4467
  const child = this.instance.createChild(schema, propertyName);
4430
4468
  child.activate();
@@ -7236,6 +7274,7 @@ class UiResolver {
7236
7274
  }
7237
7275
  }
7238
7276
  const defaultTranslations = {
7277
+ errorAddPropertyPatternMismatch: 'Property name "{{ property }}" does not match any allowed property or pattern.',
7239
7278
  errorAdditionalProperties: 'Has additional property "{{ property }}" but no additional properties are allowed.',
7240
7279
  errorAnyOf: "Must validate against at least one of the provided schemas.",
7241
7280
  errorConst: "Must have value of: {{ const }}.",
@@ -7284,6 +7323,7 @@ const defaultTranslations = {
7284
7323
  };
7285
7324
  const translations = {
7286
7325
  en: {
7326
+ errorAddPropertyPatternMismatch: 'Property name "{{ property }}" does not match any allowed property or pattern.',
7287
7327
  errorAdditionalProperties: 'Has additional property "{{ property }}" but no additional properties are allowed.',
7288
7328
  errorAnyOf: "Must validate against at least one of the provided schemas.",
7289
7329
  errorConst: "Must have value of: {{ const }}.",
@@ -7330,6 +7370,7 @@ const translations = {
7330
7370
  collapseToggle: "Collapse"
7331
7371
  },
7332
7372
  de: {
7373
+ errorAddPropertyPatternMismatch: 'Der Eigenschaftsname "{{ property }}" entspricht keiner erlaubten Eigenschaft oder keinem erlaubten Muster.',
7333
7374
  errorAdditionalProperties: 'Hat die zusätzliche Eigenschaft "{{ property }}", aber keine zusätzlichen Eigenschaften sind erlaubt.',
7334
7375
  errorAnyOf: "Muss mindestens einem der bereitgestellten Schemata entsprechen.",
7335
7376
  errorConst: "Muss den Wert {{ const }} haben.",
@@ -7376,6 +7417,7 @@ const translations = {
7376
7417
  collapseToggle: "Einklappen"
7377
7418
  },
7378
7419
  it: {
7420
+ errorAddPropertyPatternMismatch: 'Il nome della proprietà "{{ property }}" non corrisponde a nessuna proprietà o modello consentito.',
7379
7421
  errorAdditionalProperties: 'Ha la proprietà aggiuntiva "{{ property }}" ma non sono consentite proprietà aggiuntive.',
7380
7422
  errorAnyOf: "Deve rispettare almeno uno degli schemi forniti.",
7381
7423
  errorConst: "Deve avere il valore: {{ const }}.",
@@ -7422,6 +7464,7 @@ const translations = {
7422
7464
  collapseToggle: "Comprimi"
7423
7465
  },
7424
7466
  es: {
7467
+ errorAddPropertyPatternMismatch: 'El nombre de propiedad "{{ property }}" no coincide con ninguna propiedad o patrón permitido.',
7425
7468
  errorAdditionalProperties: 'Tiene la propiedad adicional "{{ property }}" pero no se permiten propiedades adicionales.',
7426
7469
  errorAnyOf: "Debe cumplir con al menos uno de los esquemas proporcionados.",
7427
7470
  errorConst: "Debe tener el valor: {{ const }}.",
@@ -7515,7 +7558,7 @@ class JsonWalker {
7515
7558
  }
7516
7559
  }
7517
7560
  }
7518
- const version = "1.22.3";
7561
+ const version = "1.23.1";
7519
7562
  class Jedison extends EventEmitter {
7520
7563
  /**
7521
7564
  * Creates a Jedison instance.
@@ -7578,7 +7621,9 @@ class Jedison extends EventEmitter {
7578
7621
  subErrors: false,
7579
7622
  debug: false,
7580
7623
  audacity: true,
7581
- switcherTypeLabels: {}
7624
+ switcherTypeLabels: {},
7625
+ keepMissingSchemaFields: false
7626
+ // for backwards compatibility
7582
7627
  }, options);
7583
7628
  this.rootName = "#";
7584
7629
  this.pathSeparator = "/";