json_schema 0.16.2 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09b4fb3d188de13d0b3cf40da40e254f7bcd3773
4
- data.tar.gz: afb180eca27353b2b0333fa275e187e3761d4b60
3
+ metadata.gz: 25771d5785cc8f1c249faf54a5cf959c52be83e4
4
+ data.tar.gz: f7e42165700c051f470a39490af317af95633ba5
5
5
  SHA512:
6
- metadata.gz: edc47bca46cb7d902ee9214c6e6964ba29e0f581f599c53402178bb4d539d9898bc9a0d3a18e7fac9bfb5dcc85c787199c73b16547d19ae0a72048ff58875c00
7
- data.tar.gz: 8e37fd7f32820b37f842332916272092eef00f10880670dc197c158662554172949359fbc2adc42e33814ffd7b26dfef829e4a9d7c16d3f42b5115e99868c606
6
+ metadata.gz: 447291afc762715084fd14582b23aa8ec113e71ee03ad6750fd2b0a50efecb258064714b74f37814b0a6647e64741566c0f8c5aa02b42282aef95a606f2c6177
7
+ data.tar.gz: 0c4fa419f94ace1a55a3bd8ec8268ad93704139372868a0cd4c421c72f94c46eafdfa92e1c5b1e9e51dfca27307ce4ef8c9147774eee97e7b58d1d35b40a1bf3
@@ -567,6 +567,15 @@ module JsonSchema
567
567
  "ipv6" => ->(data) { data =~ IPV6_PATTERN },
568
568
  "regex" => ->(data) { Regexp.new(data) rescue false },
569
569
  "uri" => ->(data) { URI.parse(data) rescue false },
570
+
571
+ # From the spec: a string instance is valid URI Reference (either a URI
572
+ # or a relative-reference), according to RFC3986.
573
+ #
574
+ # URI.parse will a handle a relative reference as well as an absolute
575
+ # one. Really though we should try to make "uri" more restrictive, and
576
+ # both of these could do to be more robust.
577
+ "uri-reference" => ->(data) { URI.parse(data) rescue false },
578
+
570
579
  "uuid" => ->(data) { data =~ UUID_PATTERN },
571
580
  }.freeze
572
581
 
@@ -285,7 +285,8 @@ describe JsonSchema::Parser do
285
285
  refute parse
286
286
  assert_includes error_messages, '"obscure-thing" is not a valid format, ' \
287
287
  'must be one of date, date-time, email, ' \
288
- 'hostname, ipv4, ipv6, regex, uri, uuid.'
288
+ 'hostname, ipv4, ipv6, regex, uri, ' \
289
+ 'uri-reference, uuid.'
289
290
  assert_includes error_types, :unknown_format
290
291
  end
291
292
 
@@ -321,8 +322,8 @@ describe JsonSchema::Parser do
321
322
  refute parse
322
323
  assert_includes error_messages, '"not-a-format" is not a valid format, ' \
323
324
  'must be one of date, date-time, email, ' \
324
- 'hostname, ipv4, ipv6, regex, uri, uuid, ' \
325
- 'the-answer.'
325
+ 'hostname, ipv4, ipv6, regex, uri, ' \
326
+ 'uri-reference, uuid, the-answer.'
326
327
  assert_includes error_types, :unknown_format
327
328
  end
328
329
 
@@ -867,6 +867,32 @@ describe JsonSchema::Validator do
867
867
  assert_includes error_types, :invalid_format
868
868
  end
869
869
 
870
+ it "validates absolute uri-reference format successfully" do
871
+ pointer("#/definitions/app/definitions/owner").merge!(
872
+ "format" => "uri-reference"
873
+ )
874
+ data_sample["owner"] = "https://example.com"
875
+ assert validate
876
+ end
877
+
878
+ it "validates relative uri format successfully" do
879
+ pointer("#/definitions/app/definitions/owner").merge!(
880
+ "format" => "uri"
881
+ )
882
+ data_sample["owner"] = "#hello"
883
+ assert validate
884
+ end
885
+
886
+ it "validates uri format unsuccessfully" do
887
+ pointer("#/definitions/app/definitions/owner").merge!(
888
+ "format" => "uri-reference"
889
+ )
890
+ data_sample["owner"] = "http://example.com[]"
891
+ refute validate
892
+ assert_includes error_messages, %{http://example.com[] is not a valid uri-reference.}
893
+ assert_includes error_types, :invalid_format
894
+ end
895
+
870
896
  it "validates uuid format successfully" do
871
897
  pointer("#/definitions/app/definitions/owner").merge!(
872
898
  "format" => "uuid"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecma-re-validator