function propagateManifestVersionRestrictions()

in src/schema/firefox-schemas-import.js [315:348]


function propagateManifestVersionRestrictions({
  definition,
  max_manifest_version,
  min_manifest_version,
}) {
  if (min_manifest_version == null && max_manifest_version == null) {
    return;
  }
  for (const prop of Object.values(definition.properties || {})) {
    let target = prop;
    // a property using $ref has to be rewritten into an allOf
    // form to be valid from a JSONSchema perspective (adding any
    // other prop would make $ref to be ignored):
    //
    //   {
    //     allOf: [
    //       { $ref: '...' },
    //       {min/max_manifest_version}
    //     ]
    //   }
    //
    if ('$ref' in prop) {
      target = {};
      prop.allOf = [{ $ref: prop.$ref }, target];
      delete prop.$ref;
    }
    if (max_manifest_version != null && target.max_manifest_version == null) {
      target.max_manifest_version = max_manifest_version;
    }
    if (min_manifest_version != null && target.min_manifest_version == null) {
      target.min_manifest_version = min_manifest_version;
    }
  }
}