Module: OpenapiFirst

Defined in:
lib/openapi_first.rb,
lib/openapi_first/errors.rb,
lib/openapi_first/schema.rb,
lib/openapi_first/failure.rb,
lib/openapi_first/plugins.rb,
lib/openapi_first/version.rb,
lib/openapi_first/definition.rb,
lib/openapi_first/body_parser.rb,
lib/openapi_first/configuration.rb,
lib/openapi_first/error_response.rb,
lib/openapi_first/plugins/default.rb,
lib/openapi_first/plugins/jsonapi.rb,
lib/openapi_first/runtime_request.rb,
lib/openapi_first/runtime_response.rb,
lib/openapi_first/definition/response.rb,
lib/openapi_first/definition/operation.rb,
lib/openapi_first/definition/path_item.rb,
lib/openapi_first/definition/responses.rb,
lib/openapi_first/definition/request_body.rb,
lib/openapi_first/schema/validation_error.rb,
lib/openapi_first/schema/validation_result.rb,
lib/openapi_first/request_validation/validator.rb,
lib/openapi_first/response_validation/validator.rb,
lib/openapi_first/middlewares/request_validation.rb,
lib/openapi_first/plugins/default/error_response.rb,
lib/openapi_first/plugins/jsonapi/error_response.rb,
lib/openapi_first/middlewares/response_validation.rb,
lib/openapi_first/request_validation/request_body_validator.rb

Overview

OpenapiFirst is a toolchain to build HTTP APIS based on OpenAPI API descriptions.

Defined Under Namespace

Modules: ErrorResponse, Middlewares, RequestValidation, ResponseValidation Classes: Configuration, Definition, Failure, RuntimeRequest, RuntimeResponse, Schema

Constant Summary collapse

REQUEST =

Key in rack to find instance of RuntimeRequest

'openapi.request'
VERSION =
'1.3.0'

Constants included from Plugins

Plugins::PLUGINS

Class Method Summary collapse

Class Method Details

.configurationConfiguration

Returns:



21
22
23
# File 'lib/openapi_first.rb', line 21

def configuration
  @configuration ||= Configuration.new
end

.configure {|Configuration| ... } ⇒ Configuration

Yields:

Returns:



27
28
29
# File 'lib/openapi_first.rb', line 27

def configure
  yield configuration
end

.load(filepath, only: nil) ⇒ Definition

Load and dereference an OpenAPI spec file

Returns:



37
38
39
40
# File 'lib/openapi_first.rb', line 37

def self.load(filepath, only: nil)
  resolved = bundle(filepath)
  parse(resolved, only:, filepath:)
end

.parse(resolved, only: nil, filepath: nil) ⇒ Definition

Parse a dereferenced Hash

Returns:



44
45
46
47
# File 'lib/openapi_first.rb', line 44

def self.parse(resolved, only: nil, filepath: nil)
  resolved['paths'].filter!(&->(key, _) { only.call(key) }) if only
  Definition.new(resolved, filepath)
end