class Apia::API
Public Class Methods
definition()
click to toggle source
Return the definition for this API
@return [Apia::Definitions::API]
# File lib/apia/api.rb, line 21 def definition @definition ||= Definitions::API.new(Helpers.class_name_to_id(name)) end
objects()
click to toggle source
Return all objects which are referenced by the API
. This list is used for the purposes of validating all objects and generating schemas.
@param include_apia_controller [Boolean] whether the schema/internal API
should be included @return [Apia::ObjectSet]
# File lib/apia/api.rb, line 30 def objects set = ObjectSet.new([self]) if definition.authenticator set.add_object(definition.authenticator) end definition.route_set.controllers.each do |con| set.add_object(con) end definition.route_set.endpoints.each do |endpoint| set.add_object(endpoint) end set end
schema(host:, namespace:)
click to toggle source
Return the schema hash for this API
@param host [String] @param namespace [String] @return [Hash]
# File lib/apia/api.rb, line 65 def schema(host:, namespace:) require 'apia/schema/controller' Schema::Controller.definition.endpoints[:schema].definition.fields.generate_hash({ schema_version: 1, host: host, namespace: namespace, api: definition.id, objects: objects.map(&:definition).select(&:schema?) }) end
test_endpoint(endpoint, controller: nil) { |r| ... }
click to toggle source
Execute a request for a given controller & endpoint
@param controller [Apia::Controller] @param endpoint_name [Symbol] @return [Apia::Response]
# File lib/apia/api.rb, line 81 def test_endpoint(endpoint, controller: nil) if controller && endpoint.is_a?(Symbol) || endpoint.is_a?(String) endpoint_name = endpoint endpoint = controller.definition.endpoints[endpoint.to_sym] if endpoint.nil? raise Apia::StandardError, "Invalid endpoint name '#{endpoint_name}' for '#{controller.name}'" end end endpoint.test do |r| r.api = self r.controller = controller yield r if block_given? end end
validate_all()
click to toggle source
Validate all objects in the API
and return details of any issues encountered
@return [Apia::ManifestErrors]
# File lib/apia/api.rb, line 50 def validate_all errors = ManifestErrors.new objects.each do |object| next unless object.respond_to?(:definition) object.definition.validate(errors) end errors end