lostintranslation
lostintranslation

Reputation: 24583

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'

Upvotes: 0

Views: 805

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81539

Here is an example: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore-expanded.yaml

So it looks like this:

definitions:
  Pet:
    allOf:
      - $ref: '#/definitions/NewPet'
    required:
      - id
    properties:
      id:
        type: integer
        format: int64

  NewPet:
    required:
      - name  
    properties:
      name:
        type: string
      tag:
        type: string

Upvotes: 0

Ron
Ron

Reputation: 14830

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.

Upvotes: 2

Related Questions