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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +5 -0
- data/lib/philiprehberger/json_schema/version.rb +1 -1
- data/lib/philiprehberger/json_schema.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3878362183aecd77cf0023b5317baf1c16da11a9dec7e668f337ec17ac4b4f18
|
|
4
|
+
data.tar.gz: 4312a4bb78e80baa4be65ac0ac110bac0fe9049b1090f56d748059a1bc6bf4e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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`
|
|
@@ -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.
|
|
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-
|
|
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,
|