'use strict';

const { omit, deepMerge } = require('../../../utilities');

// Shallow copy nested models from the `model.id` they refer to
const mergeNestedModel = function (attr, { idl: { models } }) {
  if (!attr.model) { return; }

  const [, model] = Object.entries(models)
    .find(([name, mod]) => mod.model === attr.model || name === attr.model);
  const modelId = model.properties.id;

  const modelIdA = omit(modelId, metadataProps);
  const validate = omit(modelIdA.validate, ['required']);
  const modelIdB = { ...modelIdA, validate };

  const modelIdC = deepMerge(modelIdB, attr);
  return modelIdC;
};

const metadataProps = [
  'description',
  'deprecated',
  'examples',
];

module.exports = {
  mergeNestedModel,
};

@@ -484,20 +484,27 @@
 te, 
-%5B'required'%5D
+nestedValidateProps
 );%0A 
@@ -618,16 +618,65 @@
 dC;%0A%7D;%0A%0A
+// Never using target model for those properties%0A
 const me
@@ -724,16 +724,16 @@
 cated',%0A
-
   'examp
@@ -742,16 +742,82 @@
 s',%0A%5D;%0A%0A
+const nestedValidateProps = %5B%0A  'required',%0A  'dependencies',%0A%5D;%0A%0A
 module.e

Improve model nesting