json_schema 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/json_schema/validator.rb +9 -0
 - data/test/json_schema/parser_test.rb +4 -3
 - data/test/json_schema/validator_test.rb +26 -0
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 25771d5785cc8f1c249faf54a5cf959c52be83e4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f7e42165700c051f470a39490af317af95633ba5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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,  
     | 
| 
      
 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,  
     | 
| 
       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. 
     | 
| 
      
 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- 
     | 
| 
      
 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
         
     |