Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uri and uri-reference format validation #452

Open
xlgmokha opened this issue Apr 1, 2021 · 3 comments
Open

uri and uri-reference format validation #452

xlgmokha opened this issue Apr 1, 2021 · 3 comments

Comments

@xlgmokha
Copy link

xlgmokha commented Apr 1, 2021

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
Copy link

Same issues also with uri format

@amirali-ashraf
Copy link

Is there any update on this?

@bastelfreak
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants