class Fictium::OpenApi::V3Exporter
Constants
- DEFAULT_PROPERTIES
- FIXTURE_TYPES
- INFO_OPTIONS
Public Instance Methods
export(document)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 17 def export(document) result = DEFAULT_PROPERTIES .merge(create_fixtures) .merge(info: create_info, paths: create_paths(document)) validate!(result) FileUtils.mkdir_p(File.dirname(export_file)) File.write(export_file, pretty_print? ? JSON.pretty_generate(result) : result.to_json) end
Private Instance Methods
create_fixtures()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 33 def create_fixtures {}.tap do |fixtures| FIXTURE_TYPES.each do |name| result = load_fixtures(name) fixtures[name.camelize(:lower)] = result if result.present? end end end
create_info()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 42 def create_info {}.tap do |info| INFO_OPTIONS.each do |option| value = Fictium.configuration.info.public_send(option) info[option.camelize(:lower)] = value if value.present? end end end
create_paths(document)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 51 def create_paths(document) V3Exporter::PathGenerator.new(document).generate end
export_file()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 28 def export_file @export_file ||= File.join(Fictium.configuration.export_path, 'open_api', '3.0.0', 'swagger.json') end
fixture_path()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 62 def fixture_path Fictium.configuration.fixture_path end
load_fixtures(name)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 55 def load_fixtures(name) fixture_file = File.join(fixture_path, "#{name}.json") return unless File.exist?(fixture_file) JSON.parse(File.read(fixture_file)) end
pretty_print?()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 74 def pretty_print? Fictium.configuration.pretty_print end
schema()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 70 def schema @schema ||= JSON.parse(File.read(File.join(__dir__, 'schemas', '3.0.0.json'))) end
validate!(result)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter.rb, line 66 def validate!(result) JSON::Validator.validate!(schema, result) end