govuk_schemas 5.0.0 → 5.0.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: 16cd756005e490eac69ddd8f7024ae3260afe6299e0d9009b395ad005b5fe8e9
4
- data.tar.gz: abe105f133efc4f087bdace725d8f76ca1808b01f291dcb76379d1bd70aaa9b3
3
+ metadata.gz: 11fe25fadfae015a3a24eaf4abd396e618821351ce046f5102e3d25f8e2c1b1c
4
+ data.tar.gz: 3ec36c9783619553fbf7a8cafc92af1f6e7788bfb2c7b7b1146c0269a1cf5227
5
5
  SHA512:
6
- metadata.gz: 7470680c0017977714ad1f99ae51b2302b8849e06be64ed5dfc27cfcb6f63c501ed4b8f44fe4f58162601053b5e0744f05eb9694215329d64cc05037ca045fd0
7
- data.tar.gz: c0f18d2f243992f9fb3ba73090a39449b70ebdc4e45480d96da6b096584e4f3cd2f5b6786a71eb482d76e577167c738ba09debda7e6782a3890bb0b7d6cdaa38
6
+ metadata.gz: 51c8478cc3b921d0d6f97911f890705634acb7d4fca3d61cee5e3547b2e1ce82e69ac4fbb6df2a7224b3f7710b7a981df4006ec3d3474a8a980254da55af8a85
7
+ data.tar.gz: 14676e6b674e0cf8fbb0957ff9865dbfb91085ea49cffca3156dd15c2616eb15f7b2657679f6508ae28216cbbc95e5356e77f48d0b18f140656eb90a082b8ae1
@@ -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: 1
2
- auto_merge:
3
- - dependency: rubocop-govuk
4
- allowed_semver_bumps:
5
- - patch
6
- - minor
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,7 @@
1
+ # 5.0.1
2
+
3
+ * Improve speed of random schema generation for customised content items
4
+
1
5
  # 5.0.0
2
6
 
3
7
  * BREAKING: Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
@@ -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.16.1"
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] schema A JSON schema.
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,40 @@ 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
- # ensure the base payload is valid
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
+ original_payload = payload
97
+ customised_payload = yield(payload)
98
+ customised_errors = validation_errors_for(customised_payload)
99
+
100
+ if customised_errors.any?
101
+ # Check if the original payload had errors and report those over
102
+ # any from customisation. This is not done prior to generating the
103
+ # customised payload because validation is time expensive and we
104
+ # want to avoid it if possible.
105
+ original_errors = validation_errors_for(original_payload)
106
+ errors = original_errors.any? ? original_errors : customised_errors
107
+ payload = original_errors.any? ? original_payload : customised_payload
108
+ message = error_message(payload, errors, customised: original_errors.empty?)
109
+
110
+ raise InvalidContentGenerated, message
111
+ end
112
+
113
+ customised_payload
114
+ end
115
+
101
116
  def validation_errors_for(item)
102
117
  JSON::Validator.fully_validate(@schema, item, errors_as_objects: true)
103
118
  end
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "5.0.0".freeze
3
+ VERSION = "5.0.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: 5.0.0
4
+ version: 5.0.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: 2024-04-10 00:00:00.000000000 Z
11
+ date: 2024-05-22 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.16.1
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.16.1
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.7
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