voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

`uri` and `uri-reference` format validation #452

Open xlgmokha opened 3 years ago

xlgmokha commented 3 years ago

The json-schema docs suggest that a format keyword can be used to validate a string against different standard formats. I was wondering if this project supports either the uri or uri-reference format. A quick source dive seems to indicate that this project does support this feature. However, when I attempt to use specify the format keyword it doesn't seem to be validating a document the way that I expect.

Below is an example program:

#!/usr/bin/env ruby
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'json-schema', '2.8.1'
  gem 'minitest'
end

require 'json-schema'
require 'minitest/autorun'

class SchemaTest < Minitest::Test
  def test_uri_validation
    schema = {
      'type' => 'object',
      'required' => ['url'],
      'properties' => {
        'url' => {
          'type' => 'string',
          format: 'uri-reference'
        }
      }
    }
    refute_empty JSON::Validator.fully_validate(schema, { "url" => "100" })
  end
end

When I run this example it produces an empty array of errors.

モ ruby bin/example.rb
Run options: --seed 37477

# Running:

F

Finished in 0.001886s, 530.3236 runs/s, 1060.6473 assertions/s.

  1) Failure:
SchemaTest#test_uri_validation [bin/example.rb:26]:
Expected [] to not be empty.

1 runs, 2 assertions, 1 failures, 0 errors, 0 skips

I was expecting that the value of 100 would fail the format validation because it is specified as a uri-reference. Have I made a mistake?

rlucatuorto commented 3 years ago

Same issues also with uri format

amirali-ashraf commented 5 days ago

Is there any update on this?

bastelfreak commented 5 days ago

@amirali-ashraf this seems to be a bug, are you able to provide a patch?