module Apipie::ControllerValidationHelpers
Public Instance Methods
schema_validation_errors_for_response()
click to toggle source
this method is injected into ActionController::Base
in order to get access to the names of the current controller, current action, as well as to the response
# File lib/apipie/rspec/response_validation_helper.rb, line 91 def schema_validation_errors_for_response unprocessed_schema = Apipie::json_schema_for_method_response(controller_name, action_name, response.code, true) if unprocessed_schema.nil? err = "no schema defined for #{controller_name}##{action_name}[#{response.code}]" return [nil, [err], RuntimeError.new(err)] end schema = JSON.parse(JSON(unprocessed_schema)) error_list = JSON::Validator.fully_validate(schema, response.body, :strict => false, :version => :draft4, :json => true) error_object = Apipie::ResponseDoesNotMatchSwaggerSchema.new(controller_name, action_name, response.code, error_list, schema, response.body) [schema, error_list, error_object] rescue Apipie::NoDocumentedMethod [nil, [], nil] end
validate_response_and_abort_with_info_if_errors()
click to toggle source
# File lib/apipie/rspec/response_validation_helper.rb, line 182 def validate_response_and_abort_with_info_if_errors (schema, validation_errors, error_object) = schema_validation_errors_for_response valid = (validation_errors == []) if !valid Apipie::print_validation_errors(validation_errors, schema, response, error_object) end end