lib/pacto/meta_schema.rb in pacto-0.3.1 vs lib/pacto/meta_schema.rb in pacto-0.4.0.rc1
- old
+ new
@@ -1,19 +1,25 @@
+# -*- encoding : utf-8 -*-
module Pacto
class MetaSchema
attr_accessor :schema, :engine
def initialize(engine = JSON::Validator)
@schema = File.join(File.dirname(File.expand_path(__FILE__)), '../../resources/contract_schema.json')
- @base_schema = File.join(File.dirname(File.expand_path(__FILE__)), '../../resources/draft-03.json')
- JSON::Validator.validate!(@base_schema, @schema)
+ base_schemas = ['../../resources/draft-03.json', '../../resources/draft-04.json']
+ validatable = false
+ base_schemas.each do |base_schema|
+ base_schema_file = File.join(File.dirname(File.expand_path(__FILE__)), base_schema)
+ # This has a side-effect of caching local schemas, so we don't
+ # look up json-schemas over HTTP.
+ validatable ||= JSON::Validator.validate(base_schema_file, @schema)
+ end
+ fail 'Could not validate metaschema against any known version of json-schema' unless validatable
@engine = engine
end
def validate(definition)
- errors = engine.fully_validate(schema, definition, :version => :draft3)
- unless errors.empty?
- fail InvalidContract, errors
- end
+ errors = engine.fully_validate(schema, definition)
+ fail InvalidContract, errors unless errors.empty?
end
end
end