govuk_schemas 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/govuk_schemas/random_schema_generator.rb +17 -2
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b1010c2e3fc4d2b11f832cb7fc987d93bc31e911847ec6d18231e47a29a605f
|
4
|
+
data.tar.gz: 1c7c41a441859658c3f2e53ba4399374227120611150d14ca9a0d0f850e24c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44e53cbd69991f6882e7d9a371257bef45fc100c75f945048e8700fdb9c17c9a69727219206e7ce720b5007c5412d7139472d370f856cc46fc1387453432f09b
|
7
|
+
data.tar.gz: 8ad00bb818a94cb75c5ae2d0e99ab754a204655a966a11c4acbed2e937c3015794a2847c9c5b6eb8567d2f724893c03a98fe2252c14b2499cc8d9a93b7b2e26b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# 4.3.0
|
2
|
+
|
3
|
+
* Generate unique items for arrays with the "uniqueItems" property. ([#63](https://github.com/alphagov/govuk_schemas/pull/63))
|
4
|
+
|
1
5
|
# 4.2.0
|
2
6
|
|
3
7
|
* Add support for generating random HH:MM time strings that match a regex. ([#62](https://github.com/alphagov/govuk_schemas/pull/62))
|
@@ -116,12 +116,27 @@ module GovukSchemas
|
|
116
116
|
def generate_random_array(props)
|
117
117
|
min = props["minItems"] || 0
|
118
118
|
max = props["maxItems"] || 10
|
119
|
+
unique = props["uniqueItems"] == true
|
119
120
|
num_items = @random.rand(min..max)
|
121
|
+
items = []
|
122
|
+
attempts = 0
|
123
|
+
max_attempts = num_items * 100
|
120
124
|
|
121
|
-
|
125
|
+
until items.length == num_items
|
122
126
|
# sometimes arrays don't have `items` specified, not sure if this is a bug
|
123
|
-
generate_value(props["items"] || {})
|
127
|
+
new_value = generate_value(props["items"] || {})
|
128
|
+
|
129
|
+
if unique && items.include?(new_value)
|
130
|
+
attempts += 1
|
131
|
+
raise "Failed to create a unique array item after #{max_attempts} attempts" if attempts >= max_attempts
|
132
|
+
next
|
133
|
+
end
|
134
|
+
|
135
|
+
attempts = 0
|
136
|
+
items << new_value
|
124
137
|
end
|
138
|
+
|
139
|
+
items
|
125
140
|
end
|
126
141
|
|
127
142
|
def generate_random_string(props)
|
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: 4.
|
4
|
+
version: 4.3.0
|
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:
|
11
|
+
date: 2021-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|