Implement Inheritance with allOf and discriminator
masterYou can model inheritance in Swagger by using the is_discriminator: true option on a field in the base entity. This will generate allOf definitions in the resulting Swagger JSON, allowing child entities to inherit properties from the parent.
module Entities
class Pet < Grape::Entity
expose :type, documentation: {
type: 'string',
is_discriminator: true,
required: true
}
expose :name, documentation: { type: 'string', required: true }
end
class Cat < Pet
expose :huntingSkill, documentation: {
type: 'string',
description: 'The measured skill for hunting',
default: 'lazy',
values: %w[clueless lazy adventurous aggressive]
}
end
end