title: How to properly define an object within definition and reference in multiple places for Json Schema
body: <p>I am trying to create a json schema wherein I have an object within a definition &amp; this definition is called within multiple places.
  I see an error saying <code>UnhandledPromiseRejectionWarning: Error: duplicate type name: Location</code></p>
  <p>I have the below code.</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;$schema&quot;: &quot;http://json-schema.org/draft-07/schema&quot;,
    &quot;definitions&quot;: {
      &quot;holiday&quot;: {
        &quot;description&quot;: &quot;A collection of time off associated with the employee.&quot;,
        &quot;required&quot;: [],
        &quot;properties&quot;: {
          &quot;location&quot;: {
            &quot;type&quot;: &quot;object&quot;,
            &quot;nullable&quot;: true,
            &quot;title&quot;: &quot;Location&quot;,
            &quot;properties&quot;: {
              &quot;city&quot;: {
                &quot;type&quot;: &quot;string&quot;,
                &quot;nullable&quot;: true,
                &quot;tsType&quot;: &quot;string | null&quot;,
                &quot;description&quot;: &quot;&quot;
              }
            }
          }
        },
        &quot;type&quot;: &quot;object&quot;
      }
  
    },
    &quot;description&quot;: &quot;The model for the employee object received on the Ingress API.&quot;,
    &quot;properties&quot;: {
      &quot;eventType&quot;: {
        &quot;avroType&quot;: &quot;string&quot;,
        &quot;enum&quot;: [&quot;EMPLOYEE_TIMEOFF_CREATED&quot;, &quot;EMPLOYEE_CREATED_OR_UPDATED&quot;],
        &quot;tsEnumNames&quot;: [&quot;EmployeeTimeOffCreated&quot;, &quot;EmployeeCreatedOrUpdated&quot;],
        &quot;type&quot;: &quot;string&quot;
      },
      &quot;employeeCreatedOrUpdated&quot;: {
        &quot;description&quot;: &quot;Event data for a employee create request.&quot;,
        &quot;required&quot;: [&quot;code&quot;, &quot;firstName&quot;, &quot;lastName&quot;],
        &quot;properties&quot;: {
          &quot;code&quot;: {
            &quot;description&quot;: &quot;A unique code for an employee.&quot;,
            &quot;minLength&quot;: 1,
            &quot;type&quot;: &quot;string&quot;
          },
          &quot;firstName&quot;: {
            &quot;description&quot;: &quot;This field describes the first name of the employee.&quot;,
            &quot;minLength&quot;: 1,
            &quot;type&quot;: &quot;string&quot;
          },
          &quot;middleName&quot;: {
            &quot;description&quot;: &quot;This field describes the middle name of the employee.&quot;,
            &quot;nullable&quot;: true,
            &quot;tsType&quot;: &quot;string | null&quot;,
            &quot;type&quot;: &quot;string&quot;
          },
          &quot;lastName&quot;: {
            &quot;description&quot;: &quot;This field describes the last name of the employee.&quot;,
            &quot;minLength&quot;: 1,
            &quot;type&quot;: &quot;string&quot;
          },
          &quot;timeOff&quot;: {
            &quot;description&quot;: &quot;A collection of employee time off associated with the employee.&quot;,
            &quot;items&quot;: {
              &quot;$ref&quot;: &quot;#/definitions/holiday&quot;
            },
            &quot;nullable&quot;: true,
            &quot;type&quot;: &quot;array&quot;
          }
        },
        &quot;title&quot;: &quot;EmployeeCreatedOrUpdated&quot;,
        &quot;type&quot;: &quot;object&quot;
      },
  
      &quot;employeeTimeOffCreated&quot;: {
        &quot;description&quot;: &quot;Event data for an employee time off created request.&quot;,
        &quot;required&quot;: [&quot;timeOffCreated&quot;, &quot;employeeCode&quot;],
        &quot;$id&quot;: &quot;https://io.something/v2/employee/employeeTimeOffCreated&quot;,
        &quot;properties&quot;: {
          &quot;timeOffCreated&quot;: {
            &quot;$ref&quot;: &quot;#/definitions/holiday&quot;
          },
          &quot;employeeCode&quot;: {
            &quot;description&quot;: &quot;A unique code for an employee.&quot;,
            &quot;minLength&quot;: 1,
            &quot;type&quot;: &quot;string&quot;
          }
        },
        &quot;title&quot;: &quot;EmployeeTimeOffCreated&quot;,
        &quot;type&quot;: &quot;object&quot;
      }
    },
    &quot;required&quot;: [&quot;eventType&quot;],
    &quot;title&quot;: &quot;EmployeeEvent&quot;,
    &quot;type&quot;: &quot;object&quot;
  }
  </code></pre>
  <p>So, I use the <code>holiday</code> definition at two places. I tried to have an <code>id</code> within <code>$ref</code> but that doesn't work. Any help is highly appreciated. Thanks.</p>