Sha256: da1f693707bfa784514a7fce5e75a13755c73934173433938fab442b186386bc

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path('../support/test_helper', __FILE__)

class RubySchemaTest < Minitest::Test
  def test_string_keys
    schema = {
      "type" => 'object',
      "required" => ["a"],
      "properties" => {
        "a" => {"type" => "integer", "default" => 42},
        "b" => {"type" => "integer"}
      }
    }

    assert_valid schema, { "a" => 5 }
  end

  def test_symbol_keys
    schema = {
      :type => 'object',
      :required => ["a"],
      :properties => {
        :a => {:type => "integer", :default => 42},
        :b => {:type => "integer"}
      }
    }

    assert_valid schema, { :a => 5 }
  end

  def test_symbol_keys_in_hash_within_array
    schema = {
      :type => 'object',
      :properties => {
        :a => {
          :type => "array",
          :items => [
            {
              :properties => {
                :b => {
                  :type => "integer"
                }
              }
            }
          ]
        }
      }
    }

    data = {
      :a => [
        {
          :b => 1
        }
      ]
    }

    assert_valid schema, data, :validate_schema => true
  end

  def test_schema_of_unrecognized_type
    assert_raises JSON::Schema::SchemaParseError do
      JSON::Validator.validate(Object.new, {})
    end
  end
end

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/test/ruby_schema_test.rb
mountapi-0.11.1 vendor/json-schema/test/ruby_schema_test.rb