govuk_schemas 6.0.0 → 6.1.1

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: 5dfa122dda29dbe6408145d997c35a0d59694bebe06e94e804123eeeb8c69949
4
- data.tar.gz: 20378d4689077b168d2b7c9ea16198996c3064229f097593923f41739dc4b51f
3
+ metadata.gz: 64c90e4698b291270b8f17f181b16a974b8b96676dc843ed06c0f0468740154d
4
+ data.tar.gz: d0ce267bb1d49467f857669d22a3be4883cd97f745916d0aa5262eba2e7426cb
5
5
  SHA512:
6
- metadata.gz: c5458746961ae35f261806c9f83a995ad696fceb591345642520704d8e12616a142092464dfe7abca40ab7299343216c1c3bdcf61cf12519b84f53d2380d8783
7
- data.tar.gz: '09272215f8debc39696724c6ff775ea94ecf56776da71d85ec5b92a47bd74abb5bed7b151ea7e18691303697259fc7616cd6f2b4630c59b073e9bb0022b7da5c'
6
+ metadata.gz: 494d096ab78a444af350cb9f96ee1544299af5b1eaf1483c5221d9645f6227446639c3b8e1610e7fba2c9a1b15e57a57438bdfb91bff4c91c3cba6eb4d723f67
7
+ data.tar.gz: 76c0edd74cdc2fc01966bb603077028465cad8d136165984791f99eca69af3adeba13664f5d9f49a21c2c30fad2a2c052559da1587bf69662c5486b2b1bb6bcf
@@ -6,7 +6,7 @@ jobs:
6
6
  actionlint:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
- - uses: actions/checkout@v4
9
+ - uses: actions/checkout@v5
10
10
  with:
11
11
  show-progress: false
12
12
  - uses: alphagov/govuk-infrastructure/.github/actions/actionlint@main
@@ -1,3 +1,5 @@
1
+ name: CI
2
+
1
3
  on:
2
4
  push:
3
5
  branches:
@@ -20,20 +22,20 @@ jobs:
20
22
  dependency-review:
21
23
  name: Dependency Review scan
22
24
  uses: alphagov/govuk-infrastructure/.github/workflows/dependency-review.yml@main
23
-
25
+
24
26
  # This matrix job runs the test suite against multiple Ruby versions
25
27
  test_matrix:
26
28
  strategy:
27
29
  fail-fast: false
28
30
  matrix:
29
- ruby: [3.2, 3.3]
31
+ ruby: [3.2, 3.3, 3.4]
30
32
  runs-on: ubuntu-latest
31
33
  steps:
32
- - uses: actions/checkout@v4
34
+ - uses: actions/checkout@v5
33
35
  with:
34
36
  ref: ${{ inputs.ref || github.ref }}
35
37
  - name: Clone content-schemas
36
- uses: actions/checkout@v4
38
+ uses: actions/checkout@v5
37
39
  with:
38
40
  repository: alphagov/publishing-api
39
41
  ref: main
@@ -54,12 +56,3 @@ jobs:
54
56
  runs-on: ubuntu-latest
55
57
  steps:
56
58
  - run: echo "All matrix tests have passed 🚀"
57
-
58
- publish:
59
- needs: test
60
- if: ${{ github.ref == 'refs/heads/main' }}
61
- permissions:
62
- contents: write
63
- uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
64
- secrets:
65
- GEM_HOST_API_KEY: ${{ secrets.ALPHAGOV_RUBYGEMS_API_KEY }}
@@ -0,0 +1,17 @@
1
+ name: Publish
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ workflow_run:
6
+ workflows: [CI]
7
+ types: [completed]
8
+ branches: [main]
9
+
10
+ jobs:
11
+ publish:
12
+ if: ${{ github.ref == 'refs/heads/main' }}
13
+ permissions:
14
+ contents: write
15
+ uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
16
+ secrets:
17
+ GEM_HOST_API_KEY: ${{ secrets.ALPHAGOV_RUBYGEMS_API_KEY }}
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.7
1
+ 3.2.8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.1.1
4
+
5
+ * Add a new regex generator for a content block order item [PR](https://github.com/alphagov/govuk_schemas/pull/170)
6
+
7
+ ## 6.1.0
8
+
9
+ * Introduce a "one of everything" strategy for RandomSchemaGenerator https://github.com/alphagov/govuk_schemas/pull/168
10
+
3
11
  ## 6.0.0
4
12
 
5
13
  * BREAKING: Drop support for Ruby 3.1 [PR](https://github.com/alphagov/govuk_schemas/pull/141)
@@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "faker", ">= 3.4.1", "< 3.6.0"
22
22
  # This should be kept in sync with the json-schema version of publishing-api.
23
- spec.add_dependency "json-schema", ">= 2.8", "< 5.2"
23
+ spec.add_dependency "json-schema", ">= 2.8", "< 6.1"
24
24
 
25
25
  spec.add_development_dependency "climate_control"
26
26
  spec.add_development_dependency "pry-byebug"
27
27
  spec.add_development_dependency "rake", "~> 13.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.4"
29
- spec.add_development_dependency "rubocop-govuk", "5.1.1"
29
+ spec.add_development_dependency "rubocop-govuk", "5.1.20"
30
30
 
31
31
  spec.required_ruby_version = ">= 3.2"
32
32
  end
@@ -113,6 +113,8 @@ module GovukSchemas
113
113
  govuk_subdomain_url
114
114
  when '[a-z0-9\-_]'
115
115
  "#{hex}-#{hex}"
116
+ when "^addresses|contact_links|email_addresses|telephones.[a-z0-9]+(?:-[a-z0-9]+)*$"
117
+ content_block_order_item
116
118
  else
117
119
  raise <<~DOC
118
120
  Don't know how to generate random string for pattern #{pattern.inspect}
@@ -130,6 +132,14 @@ module GovukSchemas
130
132
 
131
133
  private
132
134
 
135
+ def content_block_order_item
136
+ [
137
+ %w[addresses contact_links email_addresses telephones].sample,
138
+ ".",
139
+ Faker::Internet.slug(glue: "-"),
140
+ ].join
141
+ end
142
+
133
143
  def random_letter
134
144
  letters = ("a".."f").to_a
135
145
  letters[@random.rand(0..letters.count - 1)]
@@ -31,10 +31,11 @@ module GovukSchemas
31
31
  #
32
32
  # @param [Hash] schema A JSON schema.
33
33
  # @param [Integer, nil] seed A random number seed for deterministic results
34
+ # @param [Symbol] strategy The generation strategy for RandomSchemaGenerator to use
34
35
  # @return [GovukSchemas::RandomExample]
35
- def initialize(schema:, seed: nil)
36
+ def initialize(schema:, seed: nil, strategy: nil)
36
37
  @schema = schema
37
- @random_generator = RandomSchemaGenerator.new(schema:, seed:)
38
+ @random_generator = RandomSchemaGenerator.new(schema:, seed:, strategy:)
38
39
  end
39
40
 
40
41
  # Returns a new `GovukSchemas::RandomExample` object.
@@ -52,12 +53,14 @@ module GovukSchemas
52
53
  # # => {"base_path"=>"Test base path", "title"=>"dolor est...", "publishing_app"=>"elit"...}
53
54
  #
54
55
  # @param schema_key_value [Hash]
56
+ # @param [Integer] seed The seed for RandomSchemaGenerator's random functions
57
+ # @param [Symbol] strategy The generation strategy for RandomSchemaGenerator to use
55
58
  # @param [Block] the base payload is passed inton the block, with the block result then becoming
56
59
  # the new payload. The new payload is then validated. (optional)
57
60
  # @return [GovukSchemas::RandomExample]
58
- def self.for_schema(schema_key_value, &block)
61
+ def self.for_schema(seed: nil, strategy: nil, **schema_key_value, &block)
59
62
  schema = GovukSchemas::Schema.find(schema_key_value)
60
- GovukSchemas::RandomExample.new(schema:).payload(&block)
63
+ GovukSchemas::RandomExample.new(schema:, seed:, strategy:).payload(&block)
61
64
  end
62
65
 
63
66
  # Return a content item merged with a hash and with the excluded fields removed.
@@ -10,10 +10,17 @@ module GovukSchemas
10
10
  #
11
11
  # @private
12
12
  class RandomSchemaGenerator
13
- def initialize(schema:, seed: nil)
13
+ DEFAULT_MIN_ITEMS = 0
14
+ DEFAULT_MAX_ITEMS = 10
15
+
16
+ ONE_OF_EVERYTHING_STRATEGY = :one_of_everything
17
+ TOTALLY_RANDOM_STRATEGY = :totally_random
18
+
19
+ def initialize(schema:, seed: nil, strategy: nil)
14
20
  @schema = schema
15
21
  @random = Random.new(seed || Random.new_seed)
16
22
  @generator = RandomContentGenerator.new(random: @random)
23
+ @strategy = strategy || TOTALLY_RANDOM_STRATEGY
17
24
  end
18
25
 
19
26
  def payload
@@ -22,6 +29,10 @@ module GovukSchemas
22
29
 
23
30
  private
24
31
 
32
+ def one_of_everything_strategy?
33
+ @strategy == ONE_OF_EVERYTHING_STRATEGY
34
+ end
35
+
25
36
  def generate_value(props)
26
37
  # TODO: #/definitions/nested_headers are recursively nested and can cause
27
38
  # infinite loops. We need to add something that detects and prevents the
@@ -94,11 +105,12 @@ module GovukSchemas
94
105
  # populate all of the keys in the hash. This isn't quite random, but I
95
106
  # haven't found a nice way yet to ensure there's at least n elements in
96
107
  # the hash.
97
- should_generate_value = @generator.bool \
98
- || subschema["required"].to_a.include?(attribute_name) \
99
- || (one_of_sample["required"] || {}).to_a.include?(attribute_name) \
100
- || (one_of_sample["properties"] || {}).keys.include?(attribute_name) \
101
- || subschema["minProperties"] \
108
+ should_generate_value = one_of_everything_strategy? ||
109
+ @generator.bool ||
110
+ subschema["required"].to_a.include?(attribute_name) ||
111
+ (one_of_sample["required"] || {}).to_a.include?(attribute_name) ||
112
+ (one_of_sample["properties"] || {}).keys.include?(attribute_name) ||
113
+ subschema["minProperties"]
102
114
 
103
115
  next unless should_generate_value
104
116
 
@@ -109,9 +121,25 @@ module GovukSchemas
109
121
  document
110
122
  end
111
123
 
124
+ def min_items_for_array(array_properties)
125
+ if one_of_everything_strategy?
126
+ 1
127
+ else
128
+ array_properties["minItems"] || DEFAULT_MIN_ITEMS
129
+ end
130
+ end
131
+
132
+ def max_items_for_array(array_properties)
133
+ if one_of_everything_strategy?
134
+ 1
135
+ else
136
+ array_properties["maxItems"] || DEFAULT_MAX_ITEMS
137
+ end
138
+ end
139
+
112
140
  def generate_random_array(props)
113
- min = props["minItems"] || 0
114
- max = props["maxItems"] || 10
141
+ min = min_items_for_array(props)
142
+ max = max_items_for_array(props)
115
143
  unique = props["uniqueItems"] == true
116
144
  num_items = @random.rand(min..max)
117
145
  items = []
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "6.0.0".freeze
3
+ VERSION = "6.1.1".freeze
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-26 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: faker
@@ -38,7 +38,7 @@ dependencies:
38
38
  version: '2.8'
39
39
  - - "<"
40
40
  - !ruby/object:Gem::Version
41
- version: '5.2'
41
+ version: '6.1'
42
42
  type: :runtime
43
43
  prerelease: false
44
44
  version_requirements: !ruby/object:Gem::Requirement
@@ -48,7 +48,7 @@ dependencies:
48
48
  version: '2.8'
49
49
  - - "<"
50
50
  - !ruby/object:Gem::Version
51
- version: '5.2'
51
+ version: '6.1'
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: climate_control
54
54
  requirement: !ruby/object:Gem::Requirement
@@ -111,14 +111,14 @@ dependencies:
111
111
  requirements:
112
112
  - - '='
113
113
  - !ruby/object:Gem::Version
114
- version: 5.1.1
114
+ version: 5.1.20
115
115
  type: :development
116
116
  prerelease: false
117
117
  version_requirements: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - '='
120
120
  - !ruby/object:Gem::Version
121
- version: 5.1.1
121
+ version: 5.1.20
122
122
  description: Gem to generate test data based on GOV.UK content schemas
123
123
  email:
124
124
  - govuk-dev@digital.cabinet-office.gov.uk
@@ -126,10 +126,10 @@ executables: []
126
126
  extensions: []
127
127
  extra_rdoc_files: []
128
128
  files:
129
- - ".github/dependabot.yml"
130
129
  - ".github/workflows/actionlint.yml"
131
130
  - ".github/workflows/autorelease.yml"
132
131
  - ".github/workflows/ci.yml"
132
+ - ".github/workflows/publish.yml"
133
133
  - ".gitignore"
134
134
  - ".govuk_dependabot_merger.yml"
135
135
  - ".rspec"
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  requirements: []
175
- rubygems_version: 3.6.6
175
+ rubygems_version: 3.7.2
176
176
  specification_version: 4
177
177
  summary: Gem to generate test data based on GOV.UK content schemas
178
178
  test_files: []
@@ -1,10 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: /
5
- schedule:
6
- interval: daily
7
- - package-ecosystem: "github-actions"
8
- directory: /
9
- schedule:
10
- interval: daily