govuk_schemas 5.0.0 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +0 -11
- data/.govuk_dependabot_merger.yml +7 -6
- data/CHANGELOG.md +8 -0
- data/govuk_schemas.gemspec +1 -1
- data/lib/govuk_schemas/random_example.rb +28 -12
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4a46de8726a08e51bbe527cfb95d351a24998bf9bc9b2f3fd273529cf5c080a
|
4
|
+
data.tar.gz: 615c093ccede2446126bef34dd2e64f9c325ba5f9ed212b160ec57e442054522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd2bba00a69249ae7b6e8dbc27ecbbb7a029d14dce3a9ce4c765ab3ca050dd68a1299a6263da238dc1759efcea6a74c83e95329fee9450655568ee9fbea98cc0
|
7
|
+
data.tar.gz: 29a6b200fc9c41c35961bbb6398878f59e8bc948d565c813df2a73051e179a16e05343a5e0821bc4c5624c2185a4233aeb41822a6792a869690fb081d73eefac
|
data/.github/workflows/ci.yml
CHANGED
@@ -11,17 +11,6 @@ on:
|
|
11
11
|
type: string
|
12
12
|
|
13
13
|
jobs:
|
14
|
-
snyk-security:
|
15
|
-
name: SNYK security analysis
|
16
|
-
uses: alphagov/govuk-infrastructure/.github/workflows/snyk-security.yml@main
|
17
|
-
with:
|
18
|
-
skip_sca: true
|
19
|
-
secrets: inherit
|
20
|
-
permissions:
|
21
|
-
contents: read
|
22
|
-
security-events: write
|
23
|
-
actions: read
|
24
|
-
|
25
14
|
codeql-sast:
|
26
15
|
name: CodeQL SAST scan
|
27
16
|
uses: alphagov/govuk-infrastructure/.github/workflows/codeql-analysis.yml@main
|
@@ -1,6 +1,7 @@
|
|
1
|
-
api_version:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
api_version: 2
|
2
|
+
defaults:
|
3
|
+
allowed_semver_bumps:
|
4
|
+
- patch
|
5
|
+
- minor
|
6
|
+
auto_merge: true
|
7
|
+
update_external_dependencies: true
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 5.0.2
|
2
|
+
|
3
|
+
* Fix issue where customised schema validation message was incorrect for a modified payload
|
4
|
+
|
5
|
+
# 5.0.1
|
6
|
+
|
7
|
+
* Improve speed of random schema generation for customised content items
|
8
|
+
|
1
9
|
# 5.0.0
|
2
10
|
|
3
11
|
* BREAKING: Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
|
data/govuk_schemas.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "pry-byebug"
|
26
26
|
spec.add_development_dependency "rake", "~> 13.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.4"
|
28
|
-
spec.add_development_dependency "rubocop-govuk", "4.
|
28
|
+
spec.add_development_dependency "rubocop-govuk", "4.17.1"
|
29
29
|
|
30
30
|
spec.required_ruby_version = ">= 3.1.4"
|
31
31
|
end
|
@@ -29,7 +29,8 @@ module GovukSchemas
|
|
29
29
|
# GovukSchemas::RandomExample.new(schema: schema, seed: 777).payload
|
30
30
|
# GovukSchemas::RandomExample.new(schema: schema, seed: 777).payload # returns same as above
|
31
31
|
#
|
32
|
-
# @param [Hash]
|
32
|
+
# @param [Hash] schema A JSON schema.
|
33
|
+
# @param [Integer, nil] seed A random number seed for deterministic results
|
33
34
|
# @return [GovukSchemas::RandomExample]
|
34
35
|
def initialize(schema:, seed: nil)
|
35
36
|
@schema = schema
|
@@ -54,8 +55,6 @@ module GovukSchemas
|
|
54
55
|
# @param [Block] the base payload is passed inton the block, with the block result then becoming
|
55
56
|
# the new payload. The new payload is then validated. (optional)
|
56
57
|
# @return [GovukSchemas::RandomExample]
|
57
|
-
# @param [Block] the base payload is passed inton the block, with the block result then becoming
|
58
|
-
# the new payload. The new payload is then validated. (optional)
|
59
58
|
def self.for_schema(schema_key_value, &block)
|
60
59
|
schema = GovukSchemas::Schema.find(schema_key_value)
|
61
60
|
GovukSchemas::RandomExample.new(schema:).payload(&block)
|
@@ -80,24 +79,41 @@ module GovukSchemas
|
|
80
79
|
# the new payload. The new payload is then validated. (optional)
|
81
80
|
# @return [Hash] A content item
|
82
81
|
# @raise [GovukSchemas::InvalidContentGenerated]
|
83
|
-
def payload
|
82
|
+
def payload(&block)
|
84
83
|
payload = @random_generator.payload
|
85
|
-
|
84
|
+
|
85
|
+
return customise_payload(payload, &block) if block
|
86
|
+
|
86
87
|
errors = validation_errors_for(payload)
|
87
88
|
raise InvalidContentGenerated, error_message(payload, errors) if errors.any?
|
88
89
|
|
89
|
-
if block_given?
|
90
|
-
payload = yield(payload)
|
91
|
-
# check the payload again after customisation
|
92
|
-
errors = validation_errors_for(payload)
|
93
|
-
raise InvalidContentGenerated, error_message(payload, errors, customised: true) if errors.any?
|
94
|
-
end
|
95
|
-
|
96
90
|
payload
|
97
91
|
end
|
98
92
|
|
99
93
|
private
|
100
94
|
|
95
|
+
def customise_payload(payload)
|
96
|
+
# Use Marshal to create a deep dup of the payload so the original can be mutated
|
97
|
+
original_payload = Marshal.load(Marshal.dump(payload))
|
98
|
+
customised_payload = yield(payload)
|
99
|
+
customised_errors = validation_errors_for(customised_payload)
|
100
|
+
|
101
|
+
if customised_errors.any?
|
102
|
+
# Check if the original payload had errors and report those over
|
103
|
+
# any from customisation. This is not done prior to generating the
|
104
|
+
# customised payload because validation is time expensive and we
|
105
|
+
# want to avoid it if possible.
|
106
|
+
original_errors = validation_errors_for(original_payload)
|
107
|
+
errors = original_errors.any? ? original_errors : customised_errors
|
108
|
+
payload = original_errors.any? ? original_payload : customised_payload
|
109
|
+
message = error_message(payload, errors, customised: original_errors.empty?)
|
110
|
+
|
111
|
+
raise InvalidContentGenerated, message
|
112
|
+
end
|
113
|
+
|
114
|
+
customised_payload
|
115
|
+
end
|
116
|
+
|
101
117
|
def validation_errors_for(item)
|
102
118
|
JSON::Validator.fully_validate(@schema, item, errors_as_objects: true)
|
103
119
|
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: 5.0.
|
4
|
+
version: 5.0.2
|
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: 2024-
|
11
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - '='
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 4.
|
95
|
+
version: 4.17.1
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - '='
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 4.
|
102
|
+
version: 4.17.1
|
103
103
|
description: Gem to generate test data based on GOV.UK content schemas
|
104
104
|
email:
|
105
105
|
- govuk-dev@digital.cabinet-office.gov.uk
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
|
-
rubygems_version: 3.5.
|
155
|
+
rubygems_version: 3.5.10
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Gem to generate test data based on GOV.UK content schemas
|