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) ⇒ Committee::Driver
load and build drive from Hash object.
-
.load_from_file(schema_path) ⇒ Committee::Driver
load and build drive from file.
-
.load_from_json(schema_path) ⇒ Committee::Driver
load and build drive from JSON file.
-
.load_from_yaml(schema_path) ⇒ 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) ⇒ Committee::Driver
load and build drive from Hash object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/committee/drivers.rb', line 51 def self.load_from_data(hash, schema_path = nil) if hash['openapi']&.start_with?('3.0.') openapi = OpenAPIParser.parse_with_filepath(hash, schema_path) 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 driver.parse(hash) end |
.load_from_file(schema_path) ⇒ Committee::Driver
load and build drive from file
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/committee/drivers.rb', line 37 def self.load_from_file(schema_path) case File.extname(schema_path) when '.json' load_from_json(schema_path) when '.yaml', '.yml' load_from_yaml(schema_path) else raise "Committee only supports the following file extensions: '.json', '.yaml', '.yml'" end end |
.load_from_json(schema_path) ⇒ 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) load_from_data(JSON.parse(File.read(schema_path)), schema_path) end |
.load_from_yaml(schema_path) ⇒ Committee::Driver
load and build drive from YAML file
30 31 32 |
# File 'lib/committee/drivers.rb', line 30 def self.load_from_yaml(schema_path) load_from_data(YAML.load_file(schema_path), schema_path) end |