How to specify a property can be null or a reference with swagger
<p><a href="https://stackoverflow.com/questions/23729973/how-to-specify-a-property-as-null-or-a-reference">How to specify a property as null or a reference?</a> discusses how to specify a property as null or a reference using jsonschema.</p>
<p>I'm looking to do the same thing with swagger.</p>
<p>To recap the answer to the above, with jsonschema, one could do this:</p>
<pre class="lang-json prettyprint-override"><code>{
   &quot;definitions&quot;: {
      &quot;Foo&quot;: {
         # some complex object
      }
   },

   &quot;type&quot;: &quot;object&quot;,
   &quot;properties&quot;: {
      &quot;foo&quot;: {
         &quot;oneOf&quot;: [
            {&quot;$ref&quot;: &quot;#/definitions/Foo&quot;},
            {&quot;type&quot;: &quot;null&quot;}
         ]
      }
   }
}
</code></pre>
<p>The key point to the answer was the use of <code>oneOf</code>.</p>
<p>The key points to my question:</p>
<ol>
<li><p>I have a complex object which I want to keep DRY so I put it in a
definitions section for reuse throughout my swagger spec: values of other properties; response objects, etc.</p>
</li>
<li><p>In various places in my spec a
property may be a reference to such an object OR be null.</p>
</li>
</ol>
<p>How do I specify this with Swagger which doesn't support <code>oneOf</code> or
<code>anyOf</code>?</p>
<p>Note: some swagger implementations use <code>x-nullable</code> (or some-such) to specify a property value can be null, however, <code>$ref</code> <em>replaces</em> the object with what it references, so it would appear any use of <code>x-nullable</code> is ignored.</p>