Search code examples
swaggerswagger-editor

Inheritance in swagger-editor throwing an error


Using swagger editor and getting a validation error when I try to inherit from a model contains an array. I am assuming that my definition is screwed up as I am new to swagger. But I do know that there is still work to be done to support swagger 2.0 in the editor. Not looking to point out a bug or deficiency in the editor, just want to know if my schema is valid.

This works in the editor (from simple petstore example):

definitions:
  pet:
    properties:
      name:
        type: string
  newPet:
    allOf:
      - $ref: '#/definitions/pet'

However I want to define pet as an array:

definitions:
  pet:
    type: array
    items:
      type: string
  newPet:
    allOf:
      - $ref: '#/definitions/pet'

Solution

  • Technically speaking, that's not inheritance, that's composition. There's no hierarchical relation between newPet and pet. For a inheritance, the definitions must both be objects, and there has to be a discriminator definition.

    As far as composition goes, that looks like a valid definition.