Class: Apicraft::Validator
- Inherits:
-
Object
- Object
- Apicraft::Validator
- Defined in:
- lib/apicraft/validator.rb
Overview
Recursively loads and processes YAML files from the application’s contract folder during the application boot. This class is responsible for loading and initializing the contracts defined in the YAML files.
Class Method Summary collapse
Class Method Details
.config ⇒ Object
37 38 39 |
# File 'lib/apicraft/validator.rb', line 37 def self.config Apicraft.config end |
.validate! ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/apicraft/validator.rb', line 9 def self.validate! contracts_path = Apicraft.config.contracts_path raise Errors::InvalidContractsPath if contracts_path.blank? || !Dir.exist?(contracts_path) Find.find(contracts_path) do |path| next unless File.file?(path) && %w[.yaml .yml .json].include?(File.extname(path)) validate_file!(path) end end |
.validate_file!(file) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apicraft/validator.rb', line 20 def self.validate_file!(file) ext = File.extname(file) parsed = if ext == ".json" JSON.parse(File.read(file)) else YAML.load_file(file) end OpenAPIParser.parse( parsed, { strict_reference_validation: config.strict_reference_validation } ) end |