govuk_schemas 4.4.1 → 4.5.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: b7843ee3adf4523d3d0a0a8c722f5ae3175edaf3a4d1ee248a4fdafee9b596cf
4
+ data.tar.gz: b04e4942d146c69782e5b0e70f2d441e0f4aa6822afa054ad78d77cd40aaab7f
5
5
  SHA512:
6
- metadata.gz: 3d1fa913598d9058f76c7406878043ad564bd1c443840af54e37a13130890a653abb9ab9725aa85368c449cb610782affc5d89a63e82e76255b130066217a779
7
- data.tar.gz: d8e9fb819a1f85d3e287377382a1777688becbd2d18be394d7dc6b551f16e5dd1b31ded118c6b469c3240c6483660493c05fed1e6ffcf81648a9a68b15e21522
6
+ metadata.gz: 14d5fb78761952ed355573bfd62c5cef13d2b723011a7bad969c5cf43926231e8a02af778aadcc514e73af3137703fa950b11264b90ac5111192c252f567f1f6
7
+ data.tar.gz: 6e13df6f72f725fc504fb4151ca849dd2faeeae26c7d0c3f16f923ce3eec218293d3f66642d9237634c9666c481731f018b47df739ec8719929c82c1429b47dc
@@ -4,14 +4,3 @@ 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
@@ -11,19 +11,19 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
- - name: Clone govuk-content-schemas
14
+ - name: Clone content-schemas
15
15
  uses: actions/checkout@v2
16
16
  with:
17
- repository: alphagov/govuk-content-schemas
17
+ repository: alphagov/publishing-api
18
18
  ref: deployed-to-production
19
- path: tmp/govuk-content-schemas
19
+ path: tmp/publishing-api
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
23
23
  bundler-cache: true
24
24
  - run: bundle exec rake
25
25
  env:
26
- GOVUK_CONTENT_SCHEMAS_PATH: tmp/govuk-content-schemas
26
+ GOVUK_CONTENT_SCHEMAS_PATH: tmp/publishing-api/content_schemas
27
27
 
28
28
  # Branch protection rules cannot directly depend on status checks from matrix jobs.
29
29
  # So instead we define `test` as a dummy job which only runs after the preceding `test_matrix` checks have passed.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 4.5.0
2
+
3
+ General support for content schemas in publishing api:
4
+ * 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.
5
+ * Update path of allowed_document_types.yml to reflect new location in publishing api, allowing us to remove a symlink.
6
+ * Introduce a setter method for manually configuring the path to schemas, outside of an env variable
7
+
1
8
  # 4.4.1
2
9
 
3
10
  * 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,7 +16,7 @@ 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
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,9 +18,10 @@ 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", "< 3.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"
@@ -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
@@ -101,7 +102,7 @@ module GovukSchemas
101
102
  raise <<-DOC
102
103
  Don't know how to generate random string for pattern #{pattern.inspect}
103
104
 
104
- This propably means you've introduced a new regex in govuk-content-schemas.
105
+ This propably means you've introduced a new regex in publishing api.
105
106
  Because it's very hard to generate a valid string from a regex alone,
106
107
  we have to specify a method to generate random data for each regex in
107
108
  the schemas.
@@ -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
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "4.4.1".freeze
3
+ VERSION = "4.5.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,29 +1,49 @@
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.5.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: 2022-11-23 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
+ - !ruby/object:Gem::Version
19
+ version: '2.8'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 2.8.0
22
+ version: '3.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 2.8.0
29
+ version: '2.8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: climate_control
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: pry-byebug
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
165
  - !ruby/object:Gem::Version
146
166
  version: '0'
147
167
  requirements: []
148
- rubygems_version: 3.3.18
168
+ rubygems_version: 3.3.26
149
169
  signing_key:
150
170
  specification_version: 4
151
171
  summary: Gem to generate test data based on GOV.UK content schemas