json_skooma 0.2.2 → 0.2.4
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/CHANGELOG.md +18 -2
- data/README.md +40 -1
- data/lib/json_skooma/keywords/validation/required.rb +13 -2
- data/lib/json_skooma/sources.rb +1 -1
- data/lib/json_skooma/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 590937fba1ba290810ef51644d7f56126aee04b76ab7ded47b3f8175ccaa2eb5
         | 
| 4 | 
            +
              data.tar.gz: 4c9c91d0ea350ad63dbec27730cbb66841e8aa54886d74ad492d7445dde3bd45
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: fb845c9b702a338437a195ac5511b1a9abb18177a7ec7be314571f6a2c2f089495bc1449d9afd293babab77ef333c963dc1f8a49d4568f674a59e4bd8606bf23
         | 
| 7 | 
            +
              data.tar.gz: 4f100d96e00e5e01cfdffe7d38192c19446f1ea901858139903a75598b1413ea5c0887b170fec16b52b1950139a1f006af0a527ec6aef6a96c91ec0b660aeddb
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -7,7 +7,19 @@ and this project adheres to [Semantic Versioning]. | |
| 7 7 |  | 
| 8 8 | 
             
            ## [Unreleased]
         | 
| 9 9 |  | 
| 10 | 
            -
            ## [0.2. | 
| 10 | 
            +
            ## [0.2.4] - 2024-10-31
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ### Added
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            - Improve error messages for missing required keys ([@alexkalderimis])
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ## [0.2.3] - 2024-04-28
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ### Fixed
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            - Fix `JSONSkooma::Sources::Remote` to allow remote refs. ([@killondark])
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            ## [0.2.2] - 2024-04-09
         | 
| 11 23 |  | 
| 12 24 | 
             
            ### Fixed
         | 
| 13 25 |  | 
| @@ -41,9 +53,13 @@ and this project adheres to [Semantic Versioning]. | |
| 41 53 |  | 
| 42 54 | 
             
            - Initial implementation. ([@skryukov])
         | 
| 43 55 |  | 
| 56 | 
            +
            [@alexkalderimis]: https://github.com/alexkalderimis
         | 
| 57 | 
            +
            [@killondark]: https://github.com/killondark
         | 
| 44 58 | 
             
            [@skryukov]: https://github.com/skryukov
         | 
| 45 59 |  | 
| 46 | 
            -
            [Unreleased]: https://github.com/skryukov/json_skooma/compare/v0.2. | 
| 60 | 
            +
            [Unreleased]: https://github.com/skryukov/json_skooma/compare/v0.2.4...HEAD
         | 
| 61 | 
            +
            [0.2.4]: https://github.com/skryukov/json_skooma/compare/v0.2.3...v0.2.4
         | 
| 62 | 
            +
            [0.2.3]: https://github.com/skryukov/json_skooma/compare/v0.2.2...v0.2.3
         | 
| 47 63 | 
             
            [0.2.2]: https://github.com/skryukov/json_skooma/compare/v0.2.1...v0.2.2
         | 
| 48 64 | 
             
            [0.2.1]: https://github.com/skryukov/json_skooma/compare/v0.2.0...v0.2.1
         | 
| 49 65 | 
             
            [0.2.0]: https://github.com/skryukov/json_skooma/compare/v0.1.0...v0.2.0
         | 
    
        data/README.md
    CHANGED
    
    | @@ -14,7 +14,7 @@ JSONSkooma is a Ruby library for validating JSONs against JSON Schemas. | |
| 14 14 | 
             
            - Supports custom schema resolvers
         | 
| 15 15 |  | 
| 16 16 | 
             
            <a href="https://evilmartians.com/?utm_source=json_skooma&utm_campaign=project_page">
         | 
| 17 | 
            -
            <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt=" | 
| 17 | 
            +
            <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Built by Evil Martians" width="236" height="54">
         | 
| 18 18 | 
             
            </a>
         | 
| 19 19 |  | 
| 20 20 | 
             
            ## Installation
         | 
| @@ -117,6 +117,45 @@ result.output(:basic) | |
| 117 117 | 
             
            #     "error"=>"The instance value \"bar\" must be equal to one of the elements in the defined enumeration: [\"baz\"]"}]}
         | 
| 118 118 | 
             
            ```
         | 
| 119 119 |  | 
| 120 | 
            +
            ### Handling External `$ref`s in JSON Schemas
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            In `JSONSkooma`, you can map `$ref` identifiers in your JSON schemas to local or remote sources.
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            This configuration allows `JSONSkooma` to automatically link `$ref` URIs to their corresponding schemas from specified sources:
         | 
| 125 | 
            +
             | 
| 126 | 
            +
            ```yaml
         | 
| 127 | 
            +
            # schema.yml
         | 
| 128 | 
            +
            $schema: https://json-schema.org/draft/2020-12/schema
         | 
| 129 | 
            +
            type: object
         | 
| 130 | 
            +
            properties:
         | 
| 131 | 
            +
              user:
         | 
| 132 | 
            +
                $ref: http://local.example/user_definition.yaml
         | 
| 133 | 
            +
              product:
         | 
| 134 | 
            +
                $ref: http://remote.example/product_definition.yaml
         | 
| 135 | 
            +
            ```
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            ```ruby
         | 
| 138 | 
            +
            # Initialize the JSONSkooma registry
         | 
| 139 | 
            +
            schema_registry = JSONSkooma.create_registry("2020-12")
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            # Add a local source for user definitions
         | 
| 142 | 
            +
            local_schemas_path = File.join(__dir__, "schemas", "local")
         | 
| 143 | 
            +
            schema_registry.add_source(
         | 
| 144 | 
            +
              "http://local.example/",
         | 
| 145 | 
            +
              JSONSkooma::Sources::Local.new(local_schemas_path)
         | 
| 146 | 
            +
            )
         | 
| 147 | 
            +
             | 
| 148 | 
            +
            # Add a remote source for product definitions
         | 
| 149 | 
            +
            schema_registry.add_source(
         | 
| 150 | 
            +
              "http://remote.example/",
         | 
| 151 | 
            +
              JSONSkooma::Sources::Remote.new("http://example.com/schemas/")
         | 
| 152 | 
            +
            )
         | 
| 153 | 
            +
             | 
| 154 | 
            +
            # JSONSkooma now automatically resolves `$refs` to the appropriate schemas:
         | 
| 155 | 
            +
            # - http://local.example/user_definition.yaml -> ./schemas/local/user_definition.yaml
         | 
| 156 | 
            +
            # - http://remote.example/product_definition.yaml -> http://example.com/schemas/product_definition.yaml
         | 
| 157 | 
            +
            ```
         | 
| 158 | 
            +
             | 
| 120 159 | 
             
            ## Alternatives
         | 
| 121 160 |  | 
| 122 161 | 
             
            - [json_schemer](https://github.com/davishmcclurg/json_schemer) – Draft 4, 6, 7, 2019-09 and 2020-12 compliant
         | 
| @@ -8,9 +8,20 @@ module JSONSkooma | |
| 8 8 | 
             
                    self.instance_types = "object"
         | 
| 9 9 |  | 
| 10 10 | 
             
                    def evaluate(instance, result)
         | 
| 11 | 
            -
                       | 
| 11 | 
            +
                      missing = required_keys.reject { |key| instance.key?(key) }
         | 
| 12 | 
            +
                      return if missing.none?
         | 
| 12 13 |  | 
| 13 | 
            -
                      result.failure( | 
| 14 | 
            +
                      result.failure(missing_keys_message(missing))
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    def required_keys
         | 
| 20 | 
            +
                      json.value
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    def missing_keys_message(missing)
         | 
| 24 | 
            +
                      "The object requires the following keys: #{required_keys.join(", ")}. Missing keys: #{missing.join(", ")}"
         | 
| 14 25 | 
             
                    end
         | 
| 15 26 | 
             
                  end
         | 
| 16 27 | 
             
                end
         | 
    
        data/lib/json_skooma/sources.rb
    CHANGED
    
    | @@ -46,7 +46,7 @@ module JSONSkooma | |
| 46 46 | 
             
                  def read(relative_path)
         | 
| 47 47 | 
             
                    path = suffix ? relative_path + suffix : relative_path
         | 
| 48 48 | 
             
                    url = URI.join(base, path)
         | 
| 49 | 
            -
                     | 
| 49 | 
            +
                    url.read
         | 
| 50 50 | 
             
                  rescue OpenURI::HTTPError, SocketError
         | 
| 51 51 | 
             
                    raise Error, "Could not fetch #{url}"
         | 
| 52 52 | 
             
                  end
         | 
    
        data/lib/json_skooma/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: json_skooma
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Svyatoslav Kryukov
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-10-31 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: zeitwerk
         | 
| @@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 237 237 | 
             
                - !ruby/object:Gem::Version
         | 
| 238 238 | 
             
                  version: '0'
         | 
| 239 239 | 
             
            requirements: []
         | 
| 240 | 
            -
            rubygems_version: 3. | 
| 240 | 
            +
            rubygems_version: 3.5.17
         | 
| 241 241 | 
             
            signing_key:
         | 
| 242 242 | 
             
            specification_version: 4
         | 
| 243 243 | 
             
            summary: I bring some sugar for your JSONs.
         |