Class: Committee::Drivers::OpenAPI2
- Defined in:
- lib/committee/drivers/open_api_2.rb
Defined Under Namespace
Classes: HeaderSchemaBuilder, Link, ParameterSchemaBuilder, Schema, SchemaBuilder
Instance Method Summary collapse
- #default_allow_get_body ⇒ Object
- #default_coerce_date_times ⇒ Object
-
#default_coerce_form_params ⇒ Object
Whether parameters that were form-encoded will be coerced by default.
-
#default_path_params ⇒ Object
Whether parameters in a request’s path will be considered and coerced by default.
-
#default_query_params ⇒ Object
Whether parameters in a request’s query string will be considered and coerced by default.
- #default_validate_success_only ⇒ Object
- #name ⇒ Object
-
#parse(data) ⇒ Object
Parses an API schema and builds a set of route definitions for use with Committee.
- #schema_class ⇒ Object
Instance Method Details
#default_allow_get_body ⇒ Object
12 13 14 |
# File 'lib/committee/drivers/open_api_2.rb', line 12 def default_allow_get_body true end |
#default_coerce_date_times ⇒ Object
3 4 5 |
# File 'lib/committee/drivers/open_api_2.rb', line 3 def default_coerce_date_times false end |
#default_coerce_form_params ⇒ Object
Whether parameters that were form-encoded will be coerced by default.
8 9 10 |
# File 'lib/committee/drivers/open_api_2.rb', line 8 def default_coerce_form_params true end |
#default_path_params ⇒ Object
Whether parameters in a request’s path will be considered and coerced by default.
18 19 20 |
# File 'lib/committee/drivers/open_api_2.rb', line 18 def default_path_params true end |
#default_query_params ⇒ Object
Whether parameters in a request’s query string will be considered and coerced by default.
24 25 26 |
# File 'lib/committee/drivers/open_api_2.rb', line 24 def default_query_params true end |
#default_validate_success_only ⇒ Object
28 29 30 |
# File 'lib/committee/drivers/open_api_2.rb', line 28 def default_validate_success_only true end |
#name ⇒ Object
32 33 34 |
# File 'lib/committee/drivers/open_api_2.rb', line 32 def name :open_api_2 end |
#parse(data) ⇒ Object
Parses an API schema and builds a set of route definitions for use with Committee.
The expected input format is a data hash with keys as strings (as opposed to symbols) like the kind produced by JSON.parse or YAML.load.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/committee/drivers/open_api_2.rb', line 41 def parse(data) REQUIRED_FIELDS.each do |field| if !data[field] raise ArgumentError, "Committee: no #{field} section in spec data." end end if data['swagger'] != '2.0' raise ArgumentError, "Committee: driver requires OpenAPI 2.0." end schema = Schema.new schema.driver = self schema.base_path = data['basePath'] || '' # Arbitrarily choose the first media type found in these arrays. This # appraoch could probably stand to be improved, but at least users will # for now have the option of turning media type validation off if they so # choose. schema.consumes = data['consumes'].first schema.produces = data['produces'].first schema.definitions, store = parse_definitions!(data) schema.routes = parse_routes!(data, schema, store) schema end |