Module: Committee::Drivers
- Defined in:
- lib/committee/drivers.rb,
lib/committee/drivers/driver.rb,
lib/committee/drivers/schema.rb,
lib/committee/drivers/open_api_2.rb,
lib/committee/drivers/open_api_3.rb,
lib/committee/drivers/hyper_schema.rb,
lib/committee/drivers/open_api_2/link.rb,
lib/committee/drivers/hyper_schema/link.rb,
lib/committee/drivers/open_api_2/driver.rb,
lib/committee/drivers/open_api_2/schema.rb,
lib/committee/drivers/open_api_3/driver.rb,
lib/committee/drivers/open_api_3/schema.rb,
lib/committee/drivers/hyper_schema/driver.rb,
lib/committee/drivers/hyper_schema/schema.rb,
lib/committee/drivers/open_api_2/schema_builder.rb,
lib/committee/drivers/open_api_2/header_schema_builder.rb,
lib/committee/drivers/open_api_2/parameter_schema_builder.rb
Defined Under Namespace
Modules: HyperSchema, OpenAPI2, OpenAPI3 Classes: Driver, Schema
Class Method Summary collapse
-
.driver_from_name(name) ⇒ Object
Gets a driver instance from the specified name.
-
.load_from_data(hash, schema_path = nil, parser_options: {}) ⇒ Committee::Driver
load and build drive from Hash object.
-
.load_from_file(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from file.
-
.load_from_json(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from JSON file.
-
.load_from_yaml(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from YAML file.
Class Method Details
.driver_from_name(name) ⇒ Object
Gets a driver instance from the specified name. Raises ArgumentError for an unknown driver name.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/committee/drivers.rb', line 7 def self.driver_from_name(name) case name when :hyper_schema Committee::Drivers::HyperSchema::Driver.new when :open_api_2 Committee::Drivers::OpenAPI2::Driver.new when :open_api_3 Committee::Drivers::OpenAPI3::Driver.new else raise ArgumentError, %{Committee: unknown driver "#{name}".} end end |
.load_from_data(hash, schema_path = nil, parser_options: {}) ⇒ Committee::Driver
load and build drive from Hash object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/committee/drivers.rb', line 52 def self.load_from_data(hash, schema_path = nil, parser_options: {}) if hash['openapi']&.start_with?('3.0.') # From the next major version, we want to ensure `{ strict_reference_validation: true }` # as a parser option here, but since it may break existing implementations, just warn # if it is not explicitly set. See: https://github.com/interagent/committee/issues/343#issuecomment-997400329 opts = .dup Committee.warn_deprecated_until_6(!opts.key?(:strict_reference_validation), 'openapi_parser will default to strict reference validation ' + 'from next version. Pass config `strict_reference_validation: true` (or false, if you must) ' + 'to quiet this warning.') opts[:strict_reference_validation] ||= false openapi = OpenAPIParser.parse_with_filepath(hash, schema_path, opts) return Committee::Drivers::OpenAPI3::Driver.new.parse(openapi) end driver = if hash['swagger'] == '2.0' Committee::Drivers::OpenAPI2::Driver.new else Committee::Drivers::HyperSchema::Driver.new end # TODO: in the future, pass `opts` here and allow optionality in other drivers? driver.parse(hash) end |
.load_from_file(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from file
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/committee/drivers.rb', line 38 def self.load_from_file(schema_path, parser_options: {}) case File.extname(schema_path) when '.json' load_from_json(schema_path, parser_options: ) when '.yaml', '.yml' load_from_yaml(schema_path, parser_options: ) else raise "Committee only supports the following file extensions: '.json', '.yaml', '.yml'" end end |
.load_from_json(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from JSON file
23 24 25 |
# File 'lib/committee/drivers.rb', line 23 def self.load_from_json(schema_path, parser_options: {}) load_from_data(JSON.parse(File.read(schema_path)), schema_path, parser_options: ) end |
.load_from_yaml(schema_path, parser_options: {}) ⇒ Committee::Driver
load and build drive from YAML file
30 31 32 33 |
# File 'lib/committee/drivers.rb', line 30 def self.load_from_yaml(schema_path, parser_options: {}) data = YAML.respond_to?(:unsafe_load_file) ? YAML.unsafe_load_file(schema_path) : YAML.load_file(schema_path) load_from_data(data, schema_path, parser_options: ) end |