govuk_schemas 4.4.1 → 4.6.0

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: ad5834f6042340a4e2749eca28ebe9da5f3c7d4020aa8c80d4139b66b3cabf40
4
- data.tar.gz: 9d3f754aeeb7e3628a5ee853d60c33c9cfd52c5440e874ab2e7ecdbd0ffd58f6
3
+ metadata.gz: b56e593e5917f8ddee82d27bb4e446b485cd42d7e8fdd1efb7490ffd2c644f70
4
+ data.tar.gz: 4f4af57bb338fdf2f28d17094c3d2c027eafc550a5dac0053754aa1026821d44
5
5
  SHA512:
6
- metadata.gz: 3d1fa913598d9058f76c7406878043ad564bd1c443840af54e37a13130890a653abb9ab9725aa85368c449cb610782affc5d89a63e82e76255b130066217a779
7
- data.tar.gz: d8e9fb819a1f85d3e287377382a1777688becbd2d18be394d7dc6b551f16e5dd1b31ded118c6b469c3240c6483660493c05fed1e6ffcf81648a9a68b15e21522
6
+ metadata.gz: e1293b1587fca1140157c6d774b5d26fb1a1fdb6365ad47b5582ac8178fa3bcef85dfe97b2c64ca597cf2aa6f1a44b25fdc663ad39bf510072338edee8a1be02
7
+ data.tar.gz: d9d84be3bdeff138ba5424561b488bec0c5c722abd25e2463b5b3eca7ef90c53b8a89c14b8faacef3b07588a213bbbd4367a8dfe761829da9c7bf1ad4e2a4faa
@@ -4,14 +4,7 @@ updates:
4
4
  directory: /
5
5
  schedule:
6
6
  interval: daily
7
- allow:
8
- # Internal gems
9
- - dependency-name: "govuk*"
10
- dependency-type: direct
11
- - dependency-name: rubocop-govuk
12
- dependency-type: direct
13
- # Framework gems
14
- - dependency-name: rake
15
- dependency-type: direct
16
- - dependency-name: rspec
17
- dependency-type: direct
7
+ - package-ecosystem: "github-actions"
8
+ directory: /
9
+ schedule:
10
+ interval: daily
@@ -1,4 +1,14 @@
1
- on: [push, pull_request]
1
+ on:
2
+ push:
3
+ branches:
4
+ - main
5
+ pull_request:
6
+ workflow_dispatch:
7
+ inputs:
8
+ ref:
9
+ description: 'The branch, tag or SHA to checkout'
10
+ default: main
11
+ type: string
2
12
 
3
13
  jobs:
4
14
  # This matrix job runs the test suite against multiple Ruby versions
@@ -7,23 +17,25 @@ jobs:
7
17
  fail-fast: false
8
18
  matrix:
9
19
  # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
10
- ruby: [ 2.7, '3.0', 3.1 ]
20
+ ruby: ['3.0', 3.1, 3.2]
11
21
  runs-on: ubuntu-latest
12
22
  steps:
13
- - uses: actions/checkout@v2
14
- - name: Clone govuk-content-schemas
15
- uses: actions/checkout@v2
23
+ - uses: actions/checkout@v3
16
24
  with:
17
- repository: alphagov/govuk-content-schemas
18
- ref: deployed-to-production
19
- path: tmp/govuk-content-schemas
25
+ ref: ${{ inputs.ref || github.ref }}
26
+ - name: Clone content-schemas
27
+ uses: actions/checkout@v3
28
+ with:
29
+ repository: alphagov/publishing-api
30
+ ref: main
31
+ path: tmp/publishing-api
20
32
  - uses: ruby/setup-ruby@v1
21
33
  with:
22
34
  ruby-version: ${{ matrix.ruby }}
23
35
  bundler-cache: true
24
36
  - run: bundle exec rake
25
37
  env:
26
- GOVUK_CONTENT_SCHEMAS_PATH: tmp/govuk-content-schemas
38
+ GOVUK_CONTENT_SCHEMAS_PATH: tmp/publishing-api/content_schemas
27
39
 
28
40
  # Branch protection rules cannot directly depend on status checks from matrix jobs.
29
41
  # So instead we define `test` as a dummy job which only runs after the preceding `test_matrix` checks have passed.
@@ -39,6 +51,6 @@ jobs:
39
51
  if: ${{ github.ref == 'refs/heads/main' }}
40
52
  permissions:
41
53
  contents: write
42
- uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yaml@main
54
+ uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
43
55
  secrets:
44
56
  GEM_HOST_API_KEY: ${{ secrets.ALPHAGOV_RUBYGEMS_API_KEY }}
data/.gitignore CHANGED
@@ -1,7 +1,5 @@
1
1
  /.bundle/
2
- /.yardoc
3
2
  /Gemfile.lock
4
- /_yardoc/
5
3
  /coverage/
6
4
  /doc/
7
5
  /pkg/
data/.rubocop.yml CHANGED
@@ -1,6 +1,3 @@
1
1
  inherit_gem:
2
2
  rubocop-govuk:
3
3
  - config/default.yml
4
-
5
- AllCops:
6
- TargetRubyVersion: 2.6
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.6
1
+ 3.0.5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 4.6.0
2
+
3
+ * Drop support for Ruby 2.7.
4
+ * Fix guidance on fixing a regex issue to reference correct filename.
5
+ * Add support for `^[1-9][0-9]{3}$` regex to resolve exceptions randomly generating specialist_documents.
6
+
7
+ # 4.5.0
8
+
9
+ General support for content schemas in publishing api:
10
+ * 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.
11
+ * Update path of allowed_document_types.yml to reflect new location in publishing api, allowing us to remove a symlink.
12
+ * Introduce a setter method for manually configuring the path to schemas, outside of an env variable
13
+
1
14
  # 4.4.1
2
15
 
3
16
  * Fix `Validator` module to handle JSON or other object types being passed as the payload ([#68](https://github.com/alphagov/govuk_schemas/pull/68))
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GOV.UK Schemas
2
2
 
3
- Gem to work with the [govuk-content-schemas](https://github.com/alphagov/govuk-content-schemas).
3
+ Gem to work with the [schemas in publishing api](https://github.com/alphagov/publishing-api/tree/main/content_schemas).
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,18 +16,12 @@ gem "govuk_schemas", "~> VERSION"
16
16
 
17
17
  ## Running the test suite
18
18
 
19
- Make sure you have `govuk-content-schemas` cloned in a sibling directory:
19
+ Make sure you have `publishing-api` cloned in a sibling directory:
20
20
 
21
21
  ```
22
22
  bundle exec rake
23
23
  ```
24
24
 
25
- ### Documentation
26
-
27
- To run a Yard server locally to preview documentation, run:
28
-
29
- $ bundle exec yard server --reload
30
-
31
25
  ## License
32
26
 
33
- The gem is available as open source under the terms of the [MIT License](LICENSE.md).
27
+ The gem is available as open source under the terms of the [MIT License](LICENCE).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:lint)
5
7
 
6
- task default: [:spec]
8
+ task default: %i[lint spec]
@@ -18,14 +18,14 @@ 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
- # This should be kept in sync with the json-schema version of govuk-content-schemas.
22
- spec.add_dependency "json-schema", "~> 2.8.0"
21
+ # This should be kept in sync with the json-schema version of publishing-api.
22
+ spec.add_dependency "json-schema", ">= 2.8", "< 4.1"
23
23
 
24
+ spec.add_development_dependency "climate_control"
24
25
  spec.add_development_dependency "pry-byebug"
25
26
  spec.add_development_dependency "rake", "~> 13.0"
26
27
  spec.add_development_dependency "rspec", "~> 3.4"
27
- spec.add_development_dependency "rubocop-govuk", "~> 4.0"
28
- spec.add_development_dependency "yard", "~> 0.8"
28
+ spec.add_development_dependency "rubocop-govuk", "4.10.0"
29
29
 
30
- spec.required_ruby_version = ">= 2.6"
30
+ spec.required_ruby_version = ">= 3.0"
31
31
  end
@@ -3,7 +3,7 @@ module GovukSchemas
3
3
  # Return all of the document types on GOV.UK
4
4
  def self.valid_document_types
5
5
  @valid_document_types ||= begin
6
- filename = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/lib/govuk_content_schemas/allowed_document_types.yml"
6
+ filename = "#{GovukSchemas.content_schema_dir}/allowed_document_types.yml"
7
7
  YAML.load_file(filename)
8
8
  end
9
9
  end
@@ -27,11 +27,11 @@ module GovukSchemas
27
27
  # @param schema_name [String] like "detailed_guide", "policy" or "publication"
28
28
  # @return [String] the path to use for examples
29
29
  def self.examples_path(schema_name)
30
- examples_dir = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/examples"
30
+ examples_dir = "#{GovukSchemas.content_schema_dir}/examples"
31
31
  if Dir.exist?(examples_dir)
32
32
  "#{examples_dir}/#{schema_name}/frontend"
33
33
  else
34
- "#{GovukSchemas::CONTENT_SCHEMA_DIR}/formats/#{schema_name}/frontend/examples"
34
+ "#{GovukSchemas.content_schema_dir}/formats/#{schema_name}/frontend/examples"
35
35
  end
36
36
  end
37
37
  end
@@ -8,9 +8,10 @@ module GovukSchemas
8
8
  end
9
9
 
10
10
  def string_for_type(type)
11
- if type == "date-time"
11
+ case type
12
+ when "date-time"
12
13
  time
13
- elsif type == "uri"
14
+ when "uri"
14
15
  uri
15
16
  else
16
17
  raise "Unknown attribute type `#{type}`"
@@ -28,7 +29,7 @@ module GovukSchemas
28
29
  end
29
30
 
30
31
  def base_path
31
- "/" + @random.rand(1..5).times.map { uuid }.join("/")
32
+ "/#{@random.rand(1..5).times.map { uuid }.join('/')}"
32
33
  end
33
34
 
34
35
  def govuk_subdomain_url
@@ -83,6 +84,8 @@ module GovukSchemas
83
84
  Date.today.iso8601
84
85
  when "^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$"
85
86
  Time.now.strftime("%H:%m")
87
+ when "^[1-9][0-9]{3}$"
88
+ rand(1000...9999).to_s
86
89
  when "^#.+$"
87
90
  anchor
88
91
  when "[a-z-]"
@@ -98,17 +101,16 @@ module GovukSchemas
98
101
  when '[a-z0-9\-_]'
99
102
  "#{hex}-#{hex}"
100
103
  else
101
- raise <<-DOC
104
+ raise <<~DOC
102
105
  Don't know how to generate random string for pattern #{pattern.inspect}
103
106
 
104
- This propably means you've introduced a new regex in govuk-content-schemas.
105
- Because it's very hard to generate a valid string from a regex alone,
106
- we have to specify a method to generate random data for each regex in
107
- the schemas.
107
+ This probably means you've introduced a new regex in to a content
108
+ schema in Publishing API. Because it's very hard to generate a valid
109
+ string from a regex alone, we have to specify a method to generate
110
+ random data for each regex in the schemas.
108
111
 
109
- To fix this:
110
-
111
- - Add your regex to `lib/govuk_schemas/random.rb`
112
+ This can be fixed by adding your regex to `lib/govuk_schemas/random_content_generator.rb`
113
+ in https://github.com/alphagov/govuk_schemas
112
114
  DOC
113
115
  end
114
116
  end
@@ -9,7 +9,7 @@ module GovukSchemas
9
9
  #
10
10
  # - The gem doesn't support `patternProperties` yet. On GOV.UK we [use this in
11
11
  # the expanded frontend
12
- # links](https://github.com/alphagov/govuk-content-schemas/blob/bdd97d18c7a9318e66f332f0748a410fddab1141/formats/frontend_links_definition.json#L67-L71).
12
+ # links](https://github.com/alphagov/publishing-api/blob/a8039d430e44c86c3f54a69569f07ad48a4fc912/content_schemas/formats/shared/definitions/frontend_links.jsonnet#L118-L121).
13
13
  # - It's complicated to generate random data for `oneOf` properties. According
14
14
  # to the JSON Schema spec a `oneOf` schema is only valid if the data is valid
15
15
  # against *only one* of the clauses. To do this properly, we'd have to make
@@ -90,7 +90,7 @@ module GovukSchemas
90
90
  payload = yield(payload)
91
91
  # check the payload again after customisation
92
92
  errors = validation_errors_for(payload)
93
- raise InvalidContentGenerated, error_message(payload, errors, true) if errors.any?
93
+ raise InvalidContentGenerated, error_message(payload, errors, customised: true) if errors.any?
94
94
  end
95
95
 
96
96
  payload
@@ -102,7 +102,7 @@ module GovukSchemas
102
102
  JSON::Validator.fully_validate(@schema, item, errors_as_objects: true)
103
103
  end
104
104
 
105
- def error_message(item, errors, customised = false)
105
+ def error_message(item, errors, customised: false)
106
106
  details = <<~ERR
107
107
  Generated payload:
108
108
  --------------------------
@@ -103,11 +103,7 @@ module GovukSchemas
103
103
  next unless should_generate_value
104
104
 
105
105
  one_of_properties = (one_of_sample["properties"] || {})[attribute_name]
106
- document[attribute_name] = if one_of_properties
107
- generate_value(one_of_properties)
108
- else
109
- generate_value(attribute_properties)
110
- end
106
+ document[attribute_name] = generate_value(one_of_properties || attribute_properties)
111
107
  end
112
108
 
113
109
  document
@@ -129,6 +125,7 @@ module GovukSchemas
129
125
  if unique && items.include?(new_value)
130
126
  attempts += 1
131
127
  raise "Failed to create a unique array item after #{max_attempts} attempts" if attempts >= max_attempts
128
+
132
129
  next
133
130
  end
134
131
 
@@ -2,7 +2,6 @@ require "govuk_schemas/validator"
2
2
 
3
3
  module GovukSchemas
4
4
  module RSpecMatchers
5
-
6
5
  %w[links frontend publisher notification].each do |schema_type|
7
6
  RSpec::Matchers.define "be_valid_against_#{schema_type}_schema".to_sym do |schema_name|
8
7
  match do |item|
@@ -10,10 +9,7 @@ module GovukSchemas
10
9
  @validator.valid?
11
10
  end
12
11
 
13
-
14
- failure_message do |actual|
15
- @validator.error_message
16
- end
12
+ failure_message { @validator.error_message }
17
13
  end
18
14
  end
19
15
  end
@@ -11,7 +11,7 @@ module GovukSchemas
11
11
  # GovukSchemas::Schema.find(notification_schema: "detailed_guide")
12
12
  # @return [Hash] the JSON schema as a hash
13
13
  def self.find(schema)
14
- file_path = "#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/#{location_for_schema_name(schema)}"
14
+ file_path = "#{GovukSchemas.content_schema_dir}/dist/formats/#{location_for_schema_name(schema)}"
15
15
  JSON.parse(File.read(file_path))
16
16
  end
17
17
 
@@ -21,7 +21,7 @@ module GovukSchemas
21
21
  # @return [Array<Hash>] List of JSON schemas as hashes
22
22
  def self.all(schema_type: "*")
23
23
  schema_type = "publisher_v2" if schema_type == "publisher"
24
- Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/*/#{schema_type}/*.json").each_with_object({}) do |file_path, hash|
24
+ Dir.glob("#{GovukSchemas.content_schema_dir}/dist/formats/*/#{schema_type}/*.json").each_with_object({}) do |file_path, hash|
25
25
  hash[file_path] = JSON.parse(File.read(file_path))
26
26
  end
27
27
  end
@@ -38,7 +38,7 @@ module GovukSchemas
38
38
  #
39
39
  # @return [Array] all the schema names
40
40
  def self.schema_names
41
- Dir.glob("#{GovukSchemas::CONTENT_SCHEMA_DIR}/dist/formats/*").map do |directory|
41
+ Dir.glob("#{GovukSchemas.content_schema_dir}/dist/formats/*").map do |directory|
42
42
  File.basename(directory)
43
43
  end
44
44
  end
@@ -29,7 +29,7 @@ module GovukSchemas
29
29
  def errors
30
30
  schema = Schema.find("#{type}_schema": schema_name)
31
31
  validator = JSON::Validator.fully_validate(schema, payload)
32
- validator.map { |message| "- " + humanized_error(message) }.join("\n")
32
+ validator.map { |message| "- #{humanized_error(message)}" }.join("\n")
33
33
  end
34
34
 
35
35
  def formatted_payload
@@ -38,7 +38,7 @@ module GovukSchemas
38
38
 
39
39
  def humanized_error(message)
40
40
  message.gsub("The property '#/'", "The item")
41
- .gsub(/in schema [0-9a-f\-]+/, "")
41
+ .gsub(/in schema [0-9a-f-]+/, "")
42
42
  .strip
43
43
  end
44
44
 
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "4.4.1".freeze
3
+ VERSION = "4.6.0".freeze
4
4
  end
data/lib/govuk_schemas.rb CHANGED
@@ -5,8 +5,13 @@ require "govuk_schemas/document_types"
5
5
  require "govuk_schemas/example"
6
6
 
7
7
  module GovukSchemas
8
- # @private
9
- CONTENT_SCHEMA_DIR = ENV["GOVUK_CONTENT_SCHEMAS_PATH"] || "../govuk-content-schemas"
8
+ def self.content_schema_dir=(path_to_schemas)
9
+ @content_schema_dir = path_to_schemas
10
+ end
11
+
12
+ def self.content_schema_dir
13
+ @content_schema_dir ||= ENV.fetch("GOVUK_CONTENT_SCHEMAS_PATH", "../publishing-api/content_schemas")
14
+ end
10
15
 
11
16
  # @private
12
17
  class InvalidContentGenerated < RuntimeError
metadata CHANGED
@@ -1,31 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.6.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: 2022-07-22 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.0
19
+ version: '2.8'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.8'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 2.8.0
32
+ version: '4.1'
27
33
  - !ruby/object:Gem::Dependency
28
- name: pry-byebug
34
+ name: climate_control
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
@@ -39,61 +45,61 @@ dependencies:
39
45
  - !ruby/object:Gem::Version
40
46
  version: '0'
41
47
  - !ruby/object:Gem::Dependency
42
- name: rake
48
+ name: pry-byebug
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
- version: '13.0'
53
+ version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "~>"
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
- version: '13.0'
60
+ version: '0'
55
61
  - !ruby/object:Gem::Dependency
56
- name: rspec
62
+ name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.4'
67
+ version: '13.0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '3.4'
74
+ version: '13.0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: rubocop-govuk
76
+ name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '4.0'
81
+ version: '3.4'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '4.0'
88
+ version: '3.4'
83
89
  - !ruby/object:Gem::Dependency
84
- name: yard
90
+ name: rubocop-govuk
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - "~>"
93
+ - - '='
88
94
  - !ruby/object:Gem::Version
89
- version: '0.8'
95
+ version: 4.10.0
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - "~>"
100
+ - - '='
95
101
  - !ruby/object:Gem::Version
96
- version: '0.8'
102
+ version: 4.10.0
97
103
  description: Gem to generate test data based on GOV.UK content schemas
98
104
  email:
99
105
  - govuk-dev@digital.cabinet-office.gov.uk
@@ -110,7 +116,7 @@ files:
110
116
  - ".yardopts"
111
117
  - CHANGELOG.md
112
118
  - Gemfile
113
- - LICENSE.md
119
+ - LICENCE
114
120
  - README.md
115
121
  - Rakefile
116
122
  - bin/console
@@ -138,14 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
144
  requirements:
139
145
  - - ">="
140
146
  - !ruby/object:Gem::Version
141
- version: '2.6'
147
+ version: '3.0'
142
148
  required_rubygems_version: !ruby/object:Gem::Requirement
143
149
  requirements:
144
150
  - - ">="
145
151
  - !ruby/object:Gem::Version
146
152
  version: '0'
147
153
  requirements: []
148
- rubygems_version: 3.3.18
154
+ rubygems_version: 3.4.13
149
155
  signing_key:
150
156
  specification_version: 4
151
157
  summary: Gem to generate test data based on GOV.UK content schemas
File without changes