Implement self-describing classes with describe_own_properties
masterIf your JSON response logic is encapsulated in a class, you can make that class 'self-describing' by implementing a self.describe_own_properties class method. This method must return an array of Apipie::prop objects. When you use the class name in a returns statement, Apipie will automatically call this method to build the documentation.
This is particularly useful for reflection-based JSON generators.
class Pet
def self.describe_own_properties
[
Apipie::prop(:pet_name, 'string', {:description => 'Name of pet', :required => false}),
Apipie::prop(:animal_type, 'string', {:description => 'Type of pet', :values => ["dog", "cat", "iguana", "kangaroo"]}),
Apipie::additional_properties(false)
]
end
end
class PetsController
api :GET, "/index", "Get all pets"
returns :array_of => Pet
def index
# ...
end
end