govuk_schemas 5.0.4 → 6.1.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: 3dd91e9517ca0bd0ff1f983378aadc0f2cba54f12706b90649105c1e2ffadb64
4
- data.tar.gz: 41d7ad98aecd4d2e4dd875e3c538edc881415f259b4ea48ed5bffbf345b9422f
3
+ metadata.gz: 5588184b2f2aac015bf79217e0311d165ab849fea5ef83ba4d0ce683b300ad46
4
+ data.tar.gz: 16b97e02ee44db9130f44cc96ef7796a5e5eb087567a0f353cbbe3d33dad2938
5
5
  SHA512:
6
- metadata.gz: 0a4fd9a1aebf731f35d4763031e9578b40d365cb6b97102328a9f7945275d2ce4d1ccb1d16b4a77d6f5702b9005cf5d77592fe76cf542ce669421d1512c3143f
7
- data.tar.gz: 964968fa54d8849052e6d53b141786f07f6b819df891ea81d493c9b75e988a80f0855e2cd8ea6973336dc98a2038b70b446c1e70873bca998385e1cad8c451ed
6
+ metadata.gz: 18dd2ba2f2fcd59f0b45c6583aa7a78c8ea2599303bff5c4d787aef5a4d22f3631dafaab75830564068317e777e15b96c0ad9d3b8e5ac2b92bed9cfd1cd2746a
7
+ data.tar.gz: 4d00b406e14eb8f044d13a27e8d1a120efca36d3e4e96df59869cf9666985cbd642a335239ab2a66ec7baba79077c19a425165f6476c547db1d4699155a8d560
@@ -0,0 +1,12 @@
1
+ name: Lint GitHub Actions
2
+ on:
3
+ push:
4
+ paths: ['.github/**']
5
+ jobs:
6
+ actionlint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v5
10
+ with:
11
+ show-progress: false
12
+ - uses: alphagov/govuk-infrastructure/.github/actions/actionlint@main
@@ -0,0 +1,10 @@
1
+ on:
2
+ workflow_dispatch: {}
3
+ schedule:
4
+ - cron: '30 10 * * 1-5' # 10:30am UTC, Mon-Fri.
5
+
6
+ jobs:
7
+ autorelease:
8
+ uses: alphagov/govuk-infrastructure/.github/workflows/autorelease-rubygem.yml@main
9
+ secrets:
10
+ GH_TOKEN: ${{ secrets.GOVUK_CI_GITHUB_API_TOKEN }}
@@ -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.1, 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.1.4
1
+ 3.2.8
data/CHANGELOG.md CHANGED
@@ -1,128 +1,135 @@
1
- # 5.0.4
1
+ # Changelog
2
2
 
3
- * Ensure `Faker` is added as a non-development dependency
3
+ ## 6.1.0
4
4
 
5
- # 5.0.3
5
+ * Introduce a "one of everything" strategy for RandomSchemaGenerator https://github.com/alphagov/govuk_schemas/pull/168
6
+
7
+ ## 6.0.0
8
+
9
+ * BREAKING: Drop support for Ruby 3.1 [PR](https://github.com/alphagov/govuk_schemas/pull/141)
10
+
11
+ ## 5.0.4
12
+
13
+ * Ensure `Faker` is added as a non-development dependency
14
+
15
+ ## 5.0.3
6
16
 
7
17
  * Add support for `email` string types
8
18
  * Use `Faker` gem to generate emails and URLs
9
19
  * Improve error messages when an unknown type is given in `GovukSchemas::RandomContentGenerator#string_for_type`
10
20
 
11
- # 5.0.2
21
+ ## 5.0.2
12
22
 
13
23
  * Fix issue where customised schema validation message was incorrect for a modified payload
14
24
 
15
- # 5.0.1
25
+ ## 5.0.1
16
26
 
17
27
  * Improve speed of random schema generation for customised content items
18
28
 
19
- # 5.0.0
29
+ ## 5.0.0
20
30
 
21
31
  * BREAKING: Drop support for Ruby 3.0. The minimum required Ruby version is now 3.1.4.
22
32
  * Add support for Ruby 3.3.
23
33
  * Add support for `json-schema` 3.3.
24
34
 
25
- # 4.7.0
35
+ ## 4.7.0
26
36
 
27
37
  * Update `json-schema` dependency.
28
38
 
29
- # 4.6.0
39
+ ## 4.6.0
30
40
 
31
41
  * Drop support for Ruby 2.7.
32
42
  * Fix guidance on fixing a regex issue to reference correct filename.
33
43
  * Add support for `^[1-9][0-9]{3}$` regex to resolve exceptions randomly generating specialist_documents.
34
44
 
35
- # 4.5.0
45
+ ## 4.5.0
36
46
 
37
- General support for content schemas in publishing api:
38
- * Update default content schemas url to point to publishing api rather than govuk-content-schemas. This is because we are merging schemas into publishing api.
39
- * Update path of allowed_document_types.yml to reflect new location in publishing api, allowing us to remove a symlink.
40
- * Introduce a setter method for manually configuring the path to schemas, outside of an env variable
47
+ * General support for content schemas in Publishing API:
48
+ * Update default content schemas url to point to publishing api rather than govuk-content-schemas. This is because we are merging schemas into publishing api.
49
+ * Update path of allowed_document_types.yml to reflect new location in publishing api, allowing us to remove a symlink.
50
+ * Introduce a setter method for manually configuring the path to schemas, outside of an env variable
41
51
 
42
- # 4.4.1
52
+ ## 4.4.1
43
53
 
44
54
  * Fix `Validator` module to handle JSON or other object types being passed as the payload ([#68](https://github.com/alphagov/govuk_schemas/pull/68))
45
55
 
46
- # 4.4.0
56
+ ## 4.4.0
47
57
 
48
58
  * Adds support for applications that use Minitest by adding an `AssertMatchers` module ([#66](https://github.com/alphagov/govuk_schemas/pull/66))
49
59
 
50
- # 4.3.0
60
+ ## 4.3.0
51
61
 
52
62
  * Generate unique items for arrays with the "uniqueItems" property. ([#63](https://github.com/alphagov/govuk_schemas/pull/63))
53
63
 
54
- # 4.2.0
64
+ ## 4.2.0
55
65
 
56
66
  * Add support for generating random HH:MM time strings that match a regex. ([#62](https://github.com/alphagov/govuk_schemas/pull/62))
57
67
 
58
- # 4.1.1
68
+ ## 4.1.1
59
69
 
60
70
  * Fix RandomSchemaGenerator.new always returning equivalent generators ([#60](https://github.com/alphagov/govuk_schemas/pull/60))
61
71
 
62
- # 4.1.0
72
+ ## 4.1.0
63
73
 
64
74
  * Add `seed` parameter to `GovukSchemas::RandomExample` to make the random behaviour deterministic. Given the same seed, the same randomised outputs will be returned ([#56](https://github.com/alphagov/govuk_schemas/pull/56)).
65
75
 
66
- # 4.0.1
76
+ ## 4.0.1
67
77
 
68
78
  * Bump the required Ruby version to >= 2.6.x.
69
79
 
70
- # 4.0.0
80
+ ## 4.0.0
71
81
 
72
- * Change RSpec::Matchers, rename `be_valid_against_schema` to
73
- `be_valid_against_publisher_schema` and add
74
- `be_valid_against_frontend_schema` plus
75
- `be_valid_against_notification_schema`.
82
+ * Change RSpec::Matchers, rename `be_valid_against_schema` to `be_valid_against_publisher_schema` and add `be_valid_against_frontend_schema` plus `be_valid_against_notification_schema`.
76
83
 
77
- # 3.3.0
84
+ ## 3.3.0
78
85
 
79
86
  * Support generating objects with an `oneOf` property.
80
87
 
81
- # 3.2.0
88
+ ## 3.2.0
82
89
 
83
90
  * Add `GovukSchemas::DocumentTypes.valid_document_types` (PR #48)
84
91
 
85
- # 3.1.0
92
+ ## 3.1.0
86
93
 
87
94
  * Update json-schema dependency
88
95
 
89
- # 3.0.1
96
+ ## 3.0.1
90
97
 
91
- * change order of output when validation errors occur during random example generation
98
+ * Change order of output when validation errors occur during random example generation
92
99
 
93
- # 3.0.0
100
+ ## 3.0.0
94
101
 
95
102
  * Move to block based customisation of randomly generated payloads. This removes the existing methods: `customise_and_validate` and `merge_and_validate`. In addition `GovukSchemas::RandomExample.for_schema(schema)` now returns the payload hash directly.
96
103
 
97
- # 2.3.0
104
+ ## 2.3.0
98
105
 
99
106
  * Allow looking up examples to work with schemas stored in `formats/{format}/{schema_type}/examples/` and `examples/{format}/{schema_type}/` to allow schema examples to move.
100
107
 
101
- # 2.2.0
108
+ ## 2.2.0
102
109
 
103
110
  * Add RSpec test helpers
104
111
  * Add `customise_and_validate` to bring the functionality to remove fields from a payload which has been generated as a random example
105
112
 
106
- # 2.1.1
113
+ ## 2.1.1
107
114
 
108
115
  * Support for a new regex in GOV.UK content schemas
109
116
 
110
- # 2.1.0
117
+ ## 2.1.0
111
118
 
112
119
  * Add `Schema.schema_names` to return all schema names
113
120
  * Add functionality to work with examples
114
121
 
115
- # 2.0.0
122
+ ## 2.0.0
116
123
 
117
124
  * Change GovukSchemas::Schema.find to take { links_schema: 'detailded_guide' }
118
125
  * Add regex for lowercase-underscore strings
119
126
 
120
- # 1.0.0
127
+ ## 1.0.0
121
128
 
122
129
  * Add regex for GOV.UK campaign URLs
123
130
  * Improve error messages
124
131
 
125
- # 0.2.0
132
+ ## 0.2.0
126
133
 
127
134
  * Add a new regex for the new application validation in the schema
128
135
  * Add documentation for the gem
@@ -130,6 +137,6 @@ General support for content schemas in publishing api:
130
137
  * Now tests all available schema (a problem with specialist docs has been solved)
131
138
  * Drops active-support dependency, pins json-schema dependency
132
139
 
133
- # 0.1.0
140
+ ## 0.1.0
134
141
 
135
142
  * First release. Allows random content generation.
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = %w[lib]
20
20
 
21
- spec.add_dependency "faker", "~> 3.4.1"
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", "< 4.4"
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", "4.18.0"
29
+ spec.add_development_dependency "rubocop-govuk", "5.1.20"
30
30
 
31
- spec.required_ruby_version = ">= 3.1.4"
31
+ spec.required_ruby_version = ">= 3.2"
32
32
  end
@@ -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 = "5.0.4".freeze
3
+ VERSION = "6.1.0".freeze
4
4
  end
metadata CHANGED
@@ -1,29 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.4
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faker
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: 3.4.1
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.6.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
28
  version: 3.4.1
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: 3.6.0
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: json-schema
29
34
  requirement: !ruby/object:Gem::Requirement
@@ -33,7 +38,7 @@ dependencies:
33
38
  version: '2.8'
34
39
  - - "<"
35
40
  - !ruby/object:Gem::Version
36
- version: '4.4'
41
+ version: '6.1'
37
42
  type: :runtime
38
43
  prerelease: false
39
44
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +48,7 @@ dependencies:
43
48
  version: '2.8'
44
49
  - - "<"
45
50
  - !ruby/object:Gem::Version
46
- version: '4.4'
51
+ version: '6.1'
47
52
  - !ruby/object:Gem::Dependency
48
53
  name: climate_control
49
54
  requirement: !ruby/object:Gem::Requirement
@@ -106,14 +111,14 @@ dependencies:
106
111
  requirements:
107
112
  - - '='
108
113
  - !ruby/object:Gem::Version
109
- version: 4.18.0
114
+ version: 5.1.20
110
115
  type: :development
111
116
  prerelease: false
112
117
  version_requirements: !ruby/object:Gem::Requirement
113
118
  requirements:
114
119
  - - '='
115
120
  - !ruby/object:Gem::Version
116
- version: 4.18.0
121
+ version: 5.1.20
117
122
  description: Gem to generate test data based on GOV.UK content schemas
118
123
  email:
119
124
  - govuk-dev@digital.cabinet-office.gov.uk
@@ -122,7 +127,10 @@ extensions: []
122
127
  extra_rdoc_files: []
123
128
  files:
124
129
  - ".github/dependabot.yml"
130
+ - ".github/workflows/actionlint.yml"
131
+ - ".github/workflows/autorelease.yml"
125
132
  - ".github/workflows/ci.yml"
133
+ - ".github/workflows/publish.yml"
126
134
  - ".gitignore"
127
135
  - ".govuk_dependabot_merger.yml"
128
136
  - ".rspec"
@@ -151,7 +159,6 @@ homepage: https://github.com/alphagov/govuk_schemas_gem
151
159
  licenses:
152
160
  - MIT
153
161
  metadata: {}
154
- post_install_message:
155
162
  rdoc_options: []
156
163
  require_paths:
157
164
  - lib
@@ -159,15 +166,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
166
  requirements:
160
167
  - - ">="
161
168
  - !ruby/object:Gem::Version
162
- version: 3.1.4
169
+ version: '3.2'
163
170
  required_rubygems_version: !ruby/object:Gem::Requirement
164
171
  requirements:
165
172
  - - ">="
166
173
  - !ruby/object:Gem::Version
167
174
  version: '0'
168
175
  requirements: []
169
- rubygems_version: 3.5.14
170
- signing_key:
176
+ rubygems_version: 3.7.1
171
177
  specification_version: 4
172
178
  summary: Gem to generate test data based on GOV.UK content schemas
173
179
  test_files: []