title: "discriminator" in polymorphism, OpenAPI 2.0 (Swagger 2.0)
body: <p>Referencing <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schema-object" rel="nofollow noreferrer">OpenAPI 2.0, Schema Object</a>, or <a href="http://web.archive.org/web/20160320181209/http://swagger.io/specification/#schemaObject" rel="nofollow noreferrer">Swagger 2.0, Schema Object</a>, and the definition of <code>discriminator</code> field as:</p>
  
  <blockquote>
    <p>Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the <code>required</code> property list. When used, the value MUST be the name of this schema or any schema that inherits it.</p>
  </blockquote>
  
  <p><strong>My confusions/ questions:</strong></p>
  
  <ul>
  <li>It is ambiguous to me, what role exactly it plays in inheritance or polymorphism. Could some one please explain <code>discriminator</code> with a working example showing what it exactly does and what if we do not use it? Any errors, warnings or any tools that depends on it for some operations?</li>
  <li>Is it the case that <a href="http://editor.swagger.io/" rel="nofollow noreferrer">swagger-editor</a> does not support <code>discriminator</code>, and this field is used in some other tools?</li>
  </ul>
  
  <p><strong>What I have tried so far:</strong></p>
  
  <ul>
  <li>I have tried to use <a href="http://editor.swagger.io/" rel="nofollow noreferrer">swagger-editor</a> and the example from the same documentation (also mentioned below), to play around with this property to see if I can see any of its special behaviors. I changed the property, removed it, and extend the <code>Dog</code> model to one level deeper and tried the same on the new sub-model, but I did not see any changes in the preview of <a href="http://editor.swagger.io/" rel="nofollow noreferrer">swagger-editor</a>.</li>
  <li>I tried searching online, and specially stackoverflow questions, but did not find any relevant information.</li>
  </ul>
  
  <p><strong>The sample code I used to do experiments:</strong></p>
  
  <pre><code>definitions:
    Pet:
      type: object
      discriminator: petType
      properties:
        name:
          type: string
        petType:
          type: string
      required:
      - name
      - petType
    Cat:
      description: A representation of a cat
      allOf:
      - $ref: '#/definitions/Pet'
      - type: object
        properties:
          huntingSkill:
            type: string
            description: The measured skill for hunting
            default: lazy
            enum:
            - clueless
            - lazy
            - adventurous
            - aggressive
        required:
        - huntingSkill
    Dog:
      description: A representation of a dog
      allOf:
      - $ref: '#/definitions/Pet'
      - type: object
        properties:
          packSize:
            type: integer
            format: int32
            description: the size of the pack the dog is from
            default: 0
            minimum: 0
        required:
        - packSize
  </code></pre>