govuk_schemas 6.0.0 → 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 +4 -4
- data/.github/workflows/actionlint.yml +1 -1
- data/.github/workflows/ci.yml +6 -13
- data/.github/workflows/publish.yml +17 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/govuk_schemas.gemspec +2 -2
- data/lib/govuk_schemas/random_example.rb +7 -4
- data/lib/govuk_schemas/random_schema_generator.rb +36 -8
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5588184b2f2aac015bf79217e0311d165ab849fea5ef83ba4d0ce683b300ad46
|
4
|
+
data.tar.gz: 16b97e02ee44db9130f44cc96ef7796a5e5eb087567a0f353cbbe3d33dad2938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18dd2ba2f2fcd59f0b45c6583aa7a78c8ea2599303bff5c4d787aef5a4d22f3631dafaab75830564068317e777e15b96c0ad9d3b8e5ac2b92bed9cfd1cd2746a
|
7
|
+
data.tar.gz: 4d00b406e14eb8f044d13a27e8d1a120efca36d3e4e96df59869cf9666985cbd642a335239ab2a66ec7baba79077c19a425165f6476c547db1d4699155a8d560
|
data/.github/workflows/ci.yml
CHANGED
@@ -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@
|
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@
|
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
|
+
3.2.8
|
data/CHANGELOG.md
CHANGED
data/govuk_schemas.gemspec
CHANGED
@@ -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", "<
|
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.
|
29
|
+
spec.add_development_dependency "rubocop-govuk", "5.1.20"
|
30
30
|
|
31
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
|
-
|
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 =
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
114
|
-
max = props
|
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 = []
|
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.
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
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: '
|
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: '
|
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.
|
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.
|
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
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- ".github/workflows/actionlint.yml"
|
131
131
|
- ".github/workflows/autorelease.yml"
|
132
132
|
- ".github/workflows/ci.yml"
|
133
|
+
- ".github/workflows/publish.yml"
|
133
134
|
- ".gitignore"
|
134
135
|
- ".govuk_dependabot_merger.yml"
|
135
136
|
- ".rspec"
|
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
- !ruby/object:Gem::Version
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
+
rubygems_version: 3.7.1
|
176
177
|
specification_version: 4
|
177
178
|
summary: Gem to generate test data based on GOV.UK content schemas
|
178
179
|
test_files: []
|