govuk_schemas 4.4.0 → 4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/govuk_schemas/validator.rb +11 -6
- data/lib/govuk_schemas/version.rb +1 -1
- 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: ad5834f6042340a4e2749eca28ebe9da5f3c7d4020aa8c80d4139b66b3cabf40
|
4
|
+
data.tar.gz: 9d3f754aeeb7e3628a5ee853d60c33c9cfd52c5440e874ab2e7ecdbd0ffd58f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1fa913598d9058f76c7406878043ad564bd1c443840af54e37a13130890a653abb9ab9725aa85368c449cb610782affc5d89a63e82e76255b130066217a779
|
7
|
+
data.tar.gz: d8e9fb819a1f85d3e287377382a1777688becbd2d18be394d7dc6b551f16e5dd1b31ded118c6b469c3240c6483660493c05fed1e6ffcf81648a9a68b15e21522
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 4.4.1
|
2
|
+
|
3
|
+
* Fix `Validator` module to handle JSON or other object types being passed as the payload ([#68](https://github.com/alphagov/govuk_schemas/pull/68))
|
4
|
+
|
1
5
|
# 4.4.0
|
2
6
|
|
3
7
|
* Adds support for applications that use Minitest by adding an `AssertMatchers` module ([#66](https://github.com/alphagov/govuk_schemas/pull/66))
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module GovukSchemas
|
2
2
|
class Validator
|
3
|
-
attr_reader :schema_name, :type
|
3
|
+
attr_reader :schema_name, :type
|
4
|
+
attr_accessor :payload
|
4
5
|
|
5
6
|
def initialize(schema_name, type, payload)
|
6
7
|
@schema_name = schema_name
|
7
8
|
@type = type
|
8
|
-
@payload = payload
|
9
|
+
@payload = ensure_json(payload)
|
9
10
|
end
|
10
11
|
|
11
12
|
def valid?
|
@@ -27,14 +28,12 @@ module GovukSchemas
|
|
27
28
|
|
28
29
|
def errors
|
29
30
|
schema = Schema.find("#{type}_schema": schema_name)
|
30
|
-
validator = JSON::Validator.fully_validate(schema, payload
|
31
|
+
validator = JSON::Validator.fully_validate(schema, payload)
|
31
32
|
validator.map { |message| "- " + humanized_error(message) }.join("\n")
|
32
33
|
end
|
33
34
|
|
34
35
|
def formatted_payload
|
35
|
-
|
36
|
-
|
37
|
-
JSON.pretty_generate(payload)
|
36
|
+
JSON.pretty_generate(JSON.parse(payload))
|
38
37
|
end
|
39
38
|
|
40
39
|
def humanized_error(message)
|
@@ -42,5 +41,11 @@ module GovukSchemas
|
|
42
41
|
.gsub(/in schema [0-9a-f\-]+/, "")
|
43
42
|
.strip
|
44
43
|
end
|
44
|
+
|
45
|
+
def ensure_json(payload)
|
46
|
+
return payload if payload.is_a?(String)
|
47
|
+
|
48
|
+
payload.to_json
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|