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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e46784ff30a78aee2321e3defb7e2b31ea6eb751c96ddec7ba2ebe695a42b29a
4
- data.tar.gz: 3f6d24f1c5afb4f175d9157f84ced30b20e475b76958c7128872c179aa7bb62d
3
+ metadata.gz: ad5834f6042340a4e2749eca28ebe9da5f3c7d4020aa8c80d4139b66b3cabf40
4
+ data.tar.gz: 9d3f754aeeb7e3628a5ee853d60c33c9cfd52c5440e874ab2e7ecdbd0ffd58f6
5
5
  SHA512:
6
- metadata.gz: c2d875e00eaf8440b82c7a9173dbf23a708aabb49157bd960c7c7a94e715ba6429b43864f6b168b2e8fe1c3daa8743a76e6662f02fdf0db86e59e5af585b7b1d
7
- data.tar.gz: 166c8ecb0f9f850e682eba2181ba6187321428fcee4f9dd1e707a6791ee8b5da3d422aef3c404d5d8a175d3601c0fc6388bb8c995dd72c6353a3628886a0ea81
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, :payload
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.to_json)
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
- return payload if payload.is_a?(String)
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
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "4.4.0".freeze
3
+ VERSION = "4.4.1".freeze
4
4
  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.0
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-21 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema