publishing_platform_schemas 0.1.2 → 0.3.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: 0b9908506b494629e6db1c0e9f7913926bb57d7e7bba972b9cca8f688ee48a3f
4
- data.tar.gz: ae8b12485e1e19ad35971943ca96b50b4703b43d6e16aebcfbb904fa2ab670f9
3
+ metadata.gz: 28b746e71aa3fa2da5fcd6b25cd398f315c7ca830f6462e688529faaa3144241
4
+ data.tar.gz: 3a99432a8668c48a09f021017c8a526eea1dc8af84bbb4945975f932d1b37bbe
5
5
  SHA512:
6
- metadata.gz: 12f1ac7e89d3353f4f83a1f95629022c19328ac7d8942dd95914d7447ef3b2832b1ec89351f12e05300a1bd70698c4b823de8b9c69775957ba58b2c7c6fb9ab4
7
- data.tar.gz: c8da8abc17516ec011c1fa469080b6955513b1b0cc36bbba3a28ac16cbbe40c09851b7573b7e1fa234913869c17960d0972c107887f29de6959113ba12c8c6c6
6
+ metadata.gz: 978b46ca15a78589c0cbf2b4fb6c16ba00c343b4181957383ab3619e0c4fa54554738f3b252418fbd7f1cbd683ded8d39bc575fc0cd7a3b339408c340c03e6d7
7
+ data.tar.gz: 940423b9ace1f728c42cca4741557d1bc8d82aa53969cab09d4d2d7da3e8bdfdfcaba9b2eda21603fbeb4d485cdba2592291bb7d4cd3a12c9e785cb295aae9bf
@@ -0,0 +1,16 @@
1
+ require "publishing_platform_schemas/validator"
2
+
3
+ module PublishingPlatformSchemas
4
+ module RSpecMatchers
5
+ %w[links frontend publisher notification].each do |schema_type|
6
+ RSpec::Matchers.define "be_valid_against_#{schema_type}_schema".to_sym do |schema_name|
7
+ match do |item|
8
+ @validator = PublishingPlatformSchemas::Validator.new(schema_name, schema_type, item)
9
+ @validator.valid?
10
+ end
11
+
12
+ failure_message { @validator.error_message }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ require "json-schema"
2
+
3
+ module PublishingPlatformSchemas
4
+ class Validator
5
+ attr_reader :schema_name, :type
6
+ attr_accessor :payload
7
+
8
+ def initialize(schema_name, type, payload)
9
+ @schema_name = schema_name
10
+ @type = type
11
+ @payload = ensure_json(payload)
12
+ end
13
+
14
+ def valid?
15
+ errors.empty?
16
+ end
17
+
18
+ def error_message
19
+ <<~DOC
20
+ expected the payload to be valid against the '#{schema_name}' schema:
21
+
22
+ #{formatted_payload}
23
+
24
+ Validation errors:
25
+ #{errors}
26
+ DOC
27
+ end
28
+
29
+ private
30
+
31
+ def errors
32
+ schema = Schema.find("#{type}_schema": schema_name)
33
+ validator = JSON::Validator.fully_validate(schema, payload)
34
+ validator.map { |message| "- #{humanized_error(message)}" }.join("\n")
35
+ end
36
+
37
+ def formatted_payload
38
+ JSON.pretty_generate(JSON.parse(payload))
39
+ end
40
+
41
+ def humanized_error(message)
42
+ message.gsub("The property '#/'", "The item")
43
+ .gsub(/in schema [0-9a-f-]+/, "")
44
+ .strip
45
+ end
46
+
47
+ def ensure_json(payload)
48
+ return payload if payload.is_a?(String)
49
+
50
+ payload.to_json
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PublishingPlatformSchemas
4
- VERSION = "0.1.2"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = %w[lib]
19
19
 
20
20
  # This should be kept in sync with the json-schema version of publishing-api.
21
- spec.add_dependency "json-schema", ">= 2.8", "< 4.4"
21
+ spec.add_dependency "json-schema", ">= 2.8", "< 5.2"
22
22
 
23
23
  spec.add_development_dependency "climate_control"
24
24
  spec.add_development_dependency "publishing_platform_rubocop"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: json-schema
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: '2.8'
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: '4.4'
21
+ version: '5.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  version: '2.8'
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
- version: '4.4'
31
+ version: '5.2'
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: climate_control
34
34
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +90,9 @@ files:
90
90
  - bin/setup
91
91
  - lib/publishing_platform_schemas.rb
92
92
  - lib/publishing_platform_schemas/example.rb
93
+ - lib/publishing_platform_schemas/rspec_matchers.rb
93
94
  - lib/publishing_platform_schemas/schema.rb
95
+ - lib/publishing_platform_schemas/validator.rb
94
96
  - lib/publishing_platform_schemas/version.rb
95
97
  - publishing_platform_schemas.gemspec
96
98
  licenses:
@@ -110,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  - !ruby/object:Gem::Version
111
113
  version: '0'
112
114
  requirements: []
113
- rubygems_version: 3.6.6
115
+ rubygems_version: 3.6.8
114
116
  specification_version: 4
115
117
  summary: Gem to work with the Publishing Platform content schemas
116
118
  test_files: []