philiprehberger-json_schema 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a67bbf9af3550800b697cffb7061d297e1cc4d4d658b1db1f4c3eb3133c5125
4
- data.tar.gz: a805669bc1f806de5fd76ac8ff9b28414676b2772ef71c67bdbad40ba5ebf66d
3
+ metadata.gz: 3878362183aecd77cf0023b5317baf1c16da11a9dec7e668f337ec17ac4b4f18
4
+ data.tar.gz: 4312a4bb78e80baa4be65ac0ac110bac0fe9049b1090f56d748059a1bc6bf4e2
5
5
  SHA512:
6
- metadata.gz: f14027b317fc2d9b1f36dd79351e5da1ef2b43ebe14a00877cff83221db2e2e63d5802f5142389147285fd020992d5338583850947edb49f244383157710aa17
7
- data.tar.gz: 4290e58110711d0ad8e9ed236d4d7dbea255621ca7dd985a48e63fe2c20b100545fbca3b5437406653fd448a54b74f44cfcdbb45a4ed22ffcd1c4f49b8fad3fe
6
+ metadata.gz: cc5ba7df69818c016c0c5bb4234962ca3708a1ec6792a5d771f9730a6ec27efe871ba9864805006f4941dcc340191c2b78eab4aefcb3e0d064191bd2ab051d08
7
+ data.tar.gz: 8d7ada27d85454c1c729a67bfb1f56a0eadc16eab6c48b590da21f2cf50d8342bc1c7ae2d509442c441c51edc0ee7c5f45f9732a4596d3ad6cc4cb305a5fc1b9
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-05-07
11
+
12
+ ### Added
13
+ - `JsonSchema.validate!(data, schema)` — bang variant that returns the data on success and raises `JsonSchema::Error` with joined error messages on failure. Pairs with the existing `validate` (returns errors) and `valid?` (boolean).
14
+
10
15
  ## [0.3.0] - 2026-04-17
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -43,6 +43,10 @@ errors = Philiprehberger::JsonSchema.validate({ 'name' => 'Alice', 'age' => 30 }
43
43
 
44
44
  Philiprehberger::JsonSchema.valid?({ 'name' => 'Alice', 'age' => 30 }, schema)
45
45
  # => true
46
+
47
+ payload = { 'name' => 'Alice', 'age' => 30 }
48
+ data = Philiprehberger::JsonSchema.validate!(payload, schema)
49
+ # raises Philiprehberger::JsonSchema::Error if invalid; returns payload otherwise
46
50
  ```
47
51
 
48
52
  ### Schema Composition (allOf, anyOf, oneOf)
@@ -195,6 +199,7 @@ compiled.validate({ 'id' => 'x' }) # => ["$.id: expected type integer..."]
195
199
  |--------|-------------|
196
200
  | `.validate(data, schema)` | Validate data against a schema, returns array of error strings |
197
201
  | `.valid?(data, schema)` | Returns `true` if data passes validation |
202
+ | `.validate!(data, schema)` | Validates and returns the data; raises Error on validation failure |
198
203
  | `.compile(schema)` | Returns a `CompiledSchema` for repeated validation |
199
204
 
200
205
  ### `Philiprehberger::JsonSchema::CompiledSchema`
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module JsonSchema
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -25,6 +25,19 @@ module Philiprehberger
25
25
  validate(data, schema).empty?
26
26
  end
27
27
 
28
+ # Validate data against a JSON Schema; raise on failure.
29
+ #
30
+ # @param data [Object] the data to validate
31
+ # @param schema [Hash] the JSON Schema definition
32
+ # @return [Object] the validated data, unchanged
33
+ # @raise [Error] when validation fails (message is the joined errors)
34
+ def self.validate!(data, schema)
35
+ errors = validate(data, schema)
36
+ raise Error, errors.join('; ') unless errors.empty?
37
+
38
+ data
39
+ end
40
+
28
41
  # Compile a schema for repeated validation
29
42
  #
30
43
  # @param schema [Hash] the JSON Schema definition
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-17 00:00:00.000000000 Z
11
+ date: 2026-05-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Validate Ruby data structures against JSON Schema definitions with support
14
14
  for type checking, required properties, pattern matching, numeric ranges, enums,