Module: Apipie
- Extended by:
- Helpers
- Defined in:
- lib/apipie/dsl_definition.rb,
lib/apipie/errors.rb,
lib/apipie/markup.rb,
lib/apipie/helpers.rb,
lib/apipie/railtie.rb,
lib/apipie/routing.rb,
lib/apipie/version.rb,
lib/apipie/extractor.rb,
lib/apipie/validator.rb,
lib/apipie/application.rb,
lib/apipie/apipie_module.rb,
lib/apipie/configuration.rb,
lib/apipie/core_ext/route.rb,
lib/apipie/see_description.rb,
lib/apipie/extractor/writer.rb,
lib/apipie/generator/config.rb,
lib/apipie/routes_formatter.rb,
lib/apipie/error_description.rb,
lib/apipie/param_description.rb,
lib/apipie/static_dispatcher.rb,
lib/apipie/swagger_generator.rb,
lib/apipie/extractor/recorder.rb,
lib/apipie/method_description.rb,
lib/apipie/extractor/collector.rb,
lib/apipie/resource_description.rb,
lib/apipie/response_description.rb,
lib/apipie/tag_list_description.rb,
lib/apipie/generator/swagger/config.rb,
lib/generators/apipie/views_generator.rb,
lib/apipie/response_description_adapter.rb,
lib/apipie/param_description/deprecation.rb,
app/controllers/apipie/apipies_controller.rb,
lib/apipie/middleware/checksum_in_headers.rb,
lib/generators/apipie/install/install_generator.rb,
lib/apipie/rspec/response_validation_helper.rb
Overview
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'
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
Defined Under Namespace
Modules: BaseUrlExtension, ControllerValidationHelpers, DSL, Extractor, Generator, Helpers, Markup, Middleware, Routing, Validator
Classes: ApipiesController, Application, Configuration, DefinedParamError, Error, ErrorDescription, FileHandler, InstallGenerator, MethodDescription, NoDocumentedMethod, ParamDescription, ParamError, ParamInvalid, ParamMissing, ParamMultipleMissing, Railtie, ResourceDescription, ResponseDescription, ResponseDescriptionAdapter, ResponseDoesNotMatchSwaggerSchema, ReturnsMultipleDefinitionError, RoutesFormatter, SeeDescription, StaticDispatcher, SwaggerGenerator, TagListDescription, UnknownCode, UnknownParam, ViewsGenerator
Constant Summary
collapse
- VERSION =
"1.4.2".freeze
Instance Attribute Summary
Attributes included from Helpers
#url_prefix
Class Method Summary
collapse
-
.additional_properties(yesno) ⇒ Object
-
.api_base_url(version = nil) ⇒ Object
-
.api_base_url_version_valid?(version) ⇒ Boolean
-
.app ⇒ Object
-
.app_info(version = nil, lang = nil) ⇒ Object
get application description for given or default version.
-
.app_info_version_valid?(version) ⇒ Boolean
-
.configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
-
.debug(message) ⇒ Object
-
.json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls) ⇒ Object
-
.json_schema_for_self_describing_class(cls, allow_nulls = true) ⇒ Object
-
.method_missing(method, *args, &block) ⇒ Object
all calls delegated to Apipie::Application instance.
-
.print_validation_errors(validation_errors, schema, response, error_object = nil) ⇒ Object
-
.prop(name, expected_type, options = {}, sub_properties = []) ⇒ Object
-
.record(record) ⇒ Object
-
.to_json(version = nil, resource_id = nil, method_name = nil, lang = nil) ⇒ Object
-
.to_swagger_json(version = nil, resource_id = nil, method_name = nil, lang = nil, clear_warnings = true) ⇒ Object
Methods included from Helpers
full_url, include_javascripts, include_stylesheets, label_class_for_error, markup_to_html, request_script_name, request_script_name=
Class Method Details
.additional_properties(yesno) ⇒ Object
.api_base_url(version = nil) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# 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) ⇒ Boolean
76
77
78
|
# File 'lib/apipie/apipie_module.rb', line 76
def self.api_base_url_version_valid?(version)
version && self.configuration.api_base_url.key?(version)
end
|
.app ⇒ Object
7
8
9
|
# File 'lib/apipie/apipie_module.rb', line 7
def self.app
@application ||= Apipie::Application.new
end
|
.app_info(version = nil, lang = nil) ⇒ Object
get application description for given or default version
50
51
52
53
54
55
56
57
58
59
60
|
# 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) ⇒ Boolean
72
73
74
|
# File 'lib/apipie/apipie_module.rb', line 72
def self.app_info_version_valid?(version)
version && self.configuration.app_info.key?(version)
end
|
.configuration ⇒ Object
41
42
43
|
# File 'lib/apipie/apipie_module.rb', line 41
def self.configuration
@configuration ||= Configuration.new
end
|
37
38
39
|
# File 'lib/apipie/apipie_module.rb', line 37
def self.configure
yield configuration
end
|
.debug(message) ⇒ Object
45
46
47
|
# 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) ⇒ Object
21
22
23
24
25
|
# File 'lib/apipie/apipie_module.rb', line 21
def self.json_schema_for_method_response(controller_name, method_name, return_code, allow_nulls)
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) ⇒ Object
27
28
29
|
# 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) ⇒ Object
all calls delegated to Apipie::Application instance
33
34
35
|
# 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) ⇒ Object
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/apipie/rspec/response_validation_helper.rb', line 115
def self.print_validation_errors(validation_errors, schema, response, error_object = nil)
Rails.logger.warn(validation_errors.to_s)
if Rails.env.test?
puts "schema validation errors:"
validation_errors.each { |e| puts "--> #{e.to_s}" }
puts "schema: #{schema.nil? ? '<none>' : JSON(schema)}"
puts "response: #{response.body}"
raise error_object if error_object
end
end
|
.prop(name, expected_type, options = {}, sub_properties = []) ⇒ Object
3
4
5
|
# 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) ⇒ Object
80
81
82
|
# File 'lib/apipie/apipie_module.rb', line 80
def self.record(record)
Apipie::Extractor.start record
end
|
.to_json(version = nil, resource_id = nil, method_name = nil, lang = nil) ⇒ Object
11
12
13
14
|
# File 'lib/apipie/apipie_module.rb', line 11
def self.to_json(version = nil, resource_id = nil, method_name = nil, lang = nil)
version ||= Apipie.configuration.default_version
app.to_json(version, resource_id, method_name, lang)
end
|
.to_swagger_json(version = nil, resource_id = nil, method_name = nil, lang = nil, clear_warnings = true) ⇒ Object
16
17
18
19
|
# File 'lib/apipie/apipie_module.rb', line 16
def self.to_swagger_json(version = nil, resource_id = nil, method_name = nil, lang = nil, clear_warnings = true)
version ||= Apipie.configuration.default_version
app.to_swagger_json(version, resource_id, method_name, lang, clear_warnings)
end
|