module Apipie

Apipie DSL functions.

Middleware for rails app that adds checksum of JSON in the response headers which can help client to realize when JSON has changed

Add the following to your application.rb

require 'apipie/middleware/checksum_in_headers'
# Add JSON checksum in headers for smarter caching
config.middleware.use "Apipie::Middleware::ChecksumInHeaders"

And in your apipie initializer allow checksum calculation

Apipie.configuration.update_checksum = true

and reload documentation

Apipie.reload_documentation

By default the header is added to requests on /api and /apipie only It can be changed with

Apipie.configuration.checksum_path = ['/prefix/api']

If set to nil the header is added always

Constants

VERSION

Public Class Methods

additional_properties(yesno) click to toggle source
# File lib/apipie/response_description_adapter.rb, line 7
def self.additional_properties(yesno)
  Apipie::ResponseDescriptionAdapter::AdditionalPropertiesModifier.new(yesno)
end
api_base_url(version = nil) click to toggle source
# File lib/apipie/apipie_module.rb, line 62
def self.api_base_url(version = nil)
  if api_base_url_version_valid? version
    self.configuration.api_base_url[version]
  elsif api_base_url_version_valid? Apipie.configuration.default_version
    self.configuration.api_base_url[Apipie.configuration.default_version]
  else
    "/api"
  end
end
api_base_url_version_valid?(version) click to toggle source
# File lib/apipie/apipie_module.rb, line 76
def self.api_base_url_version_valid?(version)
  version && self.configuration.api_base_url.has_key?(version)
end
app() click to toggle source
# File lib/apipie/apipie_module.rb, line 7
def self.app
  @application ||= Apipie::Application.new
end
app_info(version = nil, lang = nil) click to toggle source

get application description for given or default version

# File lib/apipie/apipie_module.rb, line 50
def self.app_info(version = nil, lang = nil)
  info = if app_info_version_valid? version
    translate(self.configuration.app_info[version], lang)
  elsif app_info_version_valid? Apipie.configuration.default_version
    translate(self.configuration.app_info[Apipie.configuration.default_version], lang)
  else
    "Another API description"
  end

  Apipie.markup_to_html info
end
app_info_version_valid?(version) click to toggle source
# File lib/apipie/apipie_module.rb, line 72
def self.app_info_version_valid?(version)
  version && self.configuration.app_info.has_key?(version)
end
configuration() click to toggle source
# File lib/apipie/apipie_module.rb, line 41
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/apipie/apipie_module.rb, line 37
def self.configure
  yield configuration
end
debug(message) click to toggle source
# File lib/apipie/apipie_module.rb, line 45
def self.debug(message)
  puts message if Apipie.configuration.debug
end
json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls) click to toggle source
# File lib/apipie/apipie_module.rb, line 21
def self.json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls)
  # note: this does not support versions (only the default version is queried)!
  version ||= Apipie.configuration.default_version
  app.json_schema_for_method_response(version, controller_name, method_name, return_code, allow_nulls)
end
json_schema_for_self_describing_class(cls, allow_nulls=true) click to toggle source
# File lib/apipie/apipie_module.rb, line 27
def self.json_schema_for_self_describing_class(cls, allow_nulls=true)
  app.json_schema_for_self_describing_class(cls, allow_nulls)
end
method_missing(method, *args, &block) click to toggle source

all calls delegated to Apipie::Application instance

Calls superclass method
# File lib/apipie/apipie_module.rb, line 33
def self.method_missing(method, *args, &block)
  app.respond_to?(method) ? app.send(method, *args, &block) : super
end
print_validation_errors(validation_errors, schema, response, error_object=nil) click to toggle source
prop(name, expected_type, options={}, sub_properties=[]) click to toggle source
# File lib/apipie/response_description_adapter.rb, line 3
def self.prop(name, expected_type, options={}, sub_properties=[])
  Apipie::ResponseDescriptionAdapter::PropDesc.new(name, expected_type, options, sub_properties)
end
record(record) click to toggle source
# File lib/apipie/apipie_module.rb, line 80
def self.record(record)
  Apipie::Extractor.start record
end
to_json(version = nil, resource_name = nil, method_name = nil, lang = nil) click to toggle source
# File lib/apipie/apipie_module.rb, line 11
def self.to_json(version = nil, resource_name = nil, method_name = nil, lang = nil)
  version ||= Apipie.configuration.default_version
  app.to_json(version, resource_name, method_name, lang)
end
to_swagger_json(version = nil, resource_name = nil, method_name = nil, lang = nil, clear_warnings=true) click to toggle source
# File lib/apipie/apipie_module.rb, line 16
def self.to_swagger_json(version = nil, resource_name = nil, method_name = nil, lang = nil, clear_warnings=true)
  version ||= Apipie.configuration.default_version
  app.to_swagger_json(version, resource_name, method_name, lang, clear_warnings)
end