Module: SchemaTest
- Defined in:
- lib/schema_test.rb,
lib/schema_test/version.rb,
lib/schema_test/minitest.rb,
lib/schema_test/property.rb,
lib/schema_test/rewriter.rb,
lib/schema_test/validator.rb,
lib/schema_test/collection.rb,
lib/schema_test/definition.rb,
lib/schema_test/test_helper.rb,
lib/schema_test/configuration.rb
Defined Under Namespace
Modules: Minitest Classes: Collection, Configuration, Definition, Error, Property, Rewriter, TestHelper, Validator
Constant Summary collapse
- SCHEMA_VERSION =
"http://json-schema.org/draft-07/schema#"- VERSION =
"0.1.0"- OPENING_COMMENT =
'# EXPANDED'.freeze
- CLOSING_COMMENT =
'# END EXPANDED'.freeze
Class Method Summary collapse
-
.collection(name, of:, **attributes) ⇒ Object
Explicitly define a new schema collection (an array of other schema objects).
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Yields a configuration object, which can be used to set up various aspects of the library.
-
.define(name, collection: nil, **attributes, &block) ⇒ Object
Define a new schema.
-
.load! ⇒ Object
Recursively loads all files under the ‘definition_paths` directories.
- .reset! ⇒ Object
-
.validate_json(json, definition_or_schema) ⇒ Object
Validate some JSON data against a schema or schema definition.
Class Method Details
.collection(name, of:, **attributes) ⇒ Object
Explicitly define a new schema collection (an array of other schema objects)
45 46 47 |
# File 'lib/schema_test.rb', line 45 def collection(name, of:, **attributes) SchemaTest::Collection.new(name, of, attributes) end |
.configuration ⇒ Object
25 26 27 |
# File 'lib/schema_test.rb', line 25 def configuration @configuration ||= SchemaTest::Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Yields a configuration object, which can be used to set up various aspects of the library
21 22 23 |
# File 'lib/schema_test.rb', line 21 def configure yield configuration end |
.define(name, collection: nil, **attributes, &block) ⇒ Object
Define a new schema
35 36 37 38 39 40 41 |
# File 'lib/schema_test.rb', line 35 def define(name, collection: nil, **attributes, &block) definition = SchemaTest::Definition.new(name, attributes, &block) if collection collection(collection, of: name, version: attributes[:version]) end definition end |
.load! ⇒ Object
Recursively loads all files under the ‘definition_paths` directories
30 31 32 |
# File 'lib/schema_test.rb', line 30 def load! load_definitions end |
.reset! ⇒ Object
14 15 16 17 |
# File 'lib/schema_test.rb', line 14 def reset! @configuration = nil SchemaTest::Definition.reset! end |
.validate_json(json, definition_or_schema) ⇒ Object
Validate some JSON data against a schema or schema definition
50 51 52 53 54 55 56 57 |
# File 'lib/schema_test.rb', line 50 def validate_json(json, definition_or_schema) validator = SchemaTest::Validator.new(json) if definition_or_schema.is_a?(SchemaTest::Property::Object) validator.validate_using_definition(definition_or_schema) else validator.validate_using_json_schema(definition_or_schema) end end |