function validateDiscriminatorSchemasForEncryption(parentSchema, childSchema) {
  if (parentSchema.encryptionType() == null && childSchema.encryptionType() == null) return;

  const allSharedNestedPaths = setIntersection(
    allNestedPaths(parentSchema),
    allNestedPaths(childSchema)
  );

  for (const path of allSharedNestedPaths) {
    if (parentSchema._hasEncryptedField(path) && childSchema._hasEncryptedField(path)) {
      throw new Error(`encrypted fields cannot be declared on both the base schema and the child schema in a discriminator. path=${path}`);
    }

    if (parentSchema._hasEncryptedField(path) || childSchema._hasEncryptedField(path)) {
      throw new Error(`encrypted fields cannot have the same path as a non-encrypted field for discriminators. path=${path}`);
    }
  }

  function allNestedPaths(schema) {
    return [...Object.keys(schema.paths), ...Object.keys(schema.singleNestedPaths)];
  }

  /**
   * @param {Iterable<string>} i1
   * @param {Iterable<string>} i2
   */
  function* setIntersection(i1, i2) {
    const s1 = new Set(i1);
    for (const item of i2) {
      if (s1.has(item)) {
        yield item;
      }
    }
  }
}
Validate fields declared on the child schema when either schema is configured for encryption.  Specifically, this function ensures that:

- any encrypted fields are declared on exactly one of the schemas (not both)
- encrypted fields cannot be declared on either the parent or child schema, where the other schema declares the same field without encryption.

@param {Schema} parentSchema
@param {Schema} childSchema