cocina-models 0.77.0 → 0.78.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/lib/cocina/models/validators/description_values_validator.rb +77 -0
- data/lib/cocina/models/validators/validator.rb +2 -1
- data/lib/cocina/models/version.rb +1 -1
- data/openapi.yml +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09a3e28b24593aeb0e75c0318067e72fc8e10bb98e189d00b3f166357b198cab'
|
4
|
+
data.tar.gz: 688dbfe3ef449fe8caccd5c3518a6cd059cff2920ad9af3d9fb11553516b520e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bc1bce3e8624fa829ce0f41b69362d723e77549d102d561b41245c462c178cbcac5733fcd0816fd7750fa7bf736611e46de503e1e6b93dfce009ae6bd33eea4
|
7
|
+
data.tar.gz: 5cb526603a08485e0c04abccfa962b92b890fbf9d966d5dc00cb5ddd9aec64b24ebb4aa555397d769d5814edb914960d7d83a1b7f5c23be6752252f34b64a033
|
data/README.md
CHANGED
@@ -55,8 +55,37 @@ If there is a possibility that a model or validation change will conflict with s
|
|
55
55
|
|
56
56
|
1. Create a cocina-models branch containing the proposed change and push to Github.
|
57
57
|
2. On sdr-deploy, check out `main`, update the `Gemfile` so that cocina-models references the branch, and `bundle install`.
|
58
|
-
3.
|
59
|
-
|
58
|
+
3. Select the appropriate database.
|
59
|
+
For QA:
|
60
|
+
```
|
61
|
+
export DATABASE_NAME="dor_services"
|
62
|
+
export DATABASE_USERNAME=$DOR_SERVICES_DB_USER
|
63
|
+
export DATABASE_HOSTNAME=$DOR_SERVICES_DB_QA_HOST
|
64
|
+
export DATABASE_PASSWORD=$DOR_SERVICES_DB_QA_PWD
|
65
|
+
```
|
66
|
+
|
67
|
+
For stage:
|
68
|
+
```
|
69
|
+
export DATABASE_NAME="dor_services"
|
70
|
+
export DATABASE_USERNAME=$DOR_SERVICES_DB_USER
|
71
|
+
export DATABASE_HOSTNAME=$DOR_SERVICES_DB_STAGE_HOST
|
72
|
+
export DATABASE_PASSWORD=$DOR_SERVICES_DB_STAGE_PWD
|
73
|
+
```
|
74
|
+
|
75
|
+
For production:
|
76
|
+
```
|
77
|
+
export DATABASE_NAME="dor_services"
|
78
|
+
export DATABASE_USERNAME=$DOR_SERVICES_DB_USER
|
79
|
+
export DATABASE_HOSTNAME=$DOR_SERVICES_DB_PROD_HOST
|
80
|
+
export DATABASE_PASSWORD=$DOR_SERVICES_DB_PROD_PWD
|
81
|
+
```
|
82
|
+
|
83
|
+
4. Run `bin/validate-cocina`:
|
84
|
+
```
|
85
|
+
export RUBYOPT='-W:no-deprecated -W:no-experimental'
|
86
|
+
RAILS_ENV=production bin/validate-cocina -p 8
|
87
|
+
```
|
88
|
+
5. Check `validate-cocina.csv` for validation errors.
|
60
89
|
|
61
90
|
## Releasing
|
62
91
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cocina
|
4
|
+
module Models
|
5
|
+
module Validators
|
6
|
+
# Validates that there is only one of value, groupedValue, structuredValue, or parallelValue.
|
7
|
+
class DescriptionValuesValidator
|
8
|
+
def self.validate(clazz, attributes)
|
9
|
+
new(clazz, attributes).validate
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(clazz, attributes)
|
13
|
+
@clazz = clazz
|
14
|
+
@attributes = attributes.deep_symbolize_keys
|
15
|
+
@error_paths = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate
|
19
|
+
return unless meets_preconditions?
|
20
|
+
|
21
|
+
validate_obj(attributes, [])
|
22
|
+
|
23
|
+
return if error_paths.empty?
|
24
|
+
|
25
|
+
raise ValidationError, "Multiple value, groupedValue, structuredValue, and parallelValue in description: #{error_paths.join(', ')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :clazz, :attributes, :error_paths
|
31
|
+
|
32
|
+
def meets_preconditions?
|
33
|
+
attributes.key?(:description) || [Cocina::Models::Description,
|
34
|
+
Cocina::Models::RequestDescription].include?(clazz)
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_hash(hash, path)
|
38
|
+
validate_values(hash, path)
|
39
|
+
hash.each do |key, obj|
|
40
|
+
validate_obj(obj, path + [key])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_array(array, path)
|
45
|
+
array.each_with_index do |obj, index|
|
46
|
+
validate_obj(obj, path + [index])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_obj(obj, path)
|
51
|
+
validate_hash(obj, path) if obj.is_a?(Hash)
|
52
|
+
validate_array(obj, path) if obj.is_a?(Array)
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate_values(hash, path)
|
56
|
+
return unless hash.count { |key, value| %i[value groupedValue structuredValue parallelValue].include?(key) && value.present? } > 1
|
57
|
+
|
58
|
+
error_paths << path_to_s(path)
|
59
|
+
end
|
60
|
+
|
61
|
+
def path_to_s(path)
|
62
|
+
# This matches the format used by descriptive spreadsheets
|
63
|
+
path_str = ''
|
64
|
+
path.each_with_index do |part, index|
|
65
|
+
if part.is_a?(Integer)
|
66
|
+
path_str += (part + 1).to_s
|
67
|
+
else
|
68
|
+
path_str += '.' if index.positive?
|
69
|
+
path_str += part.to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
path_str
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/openapi.yml
CHANGED
@@ -691,7 +691,7 @@ components:
|
|
691
691
|
items:
|
692
692
|
$ref: "#/components/schemas/DescriptiveValue"
|
693
693
|
DescriptiveBasicValue:
|
694
|
-
description: Basic value model for descriptive elements.
|
694
|
+
description: Basic value model for descriptive elements. Can only have one of value, parallelValue, groupedValue, or structuredValue.
|
695
695
|
type: object
|
696
696
|
# additionalProperties breaks the validator for allOf, unclear as to why.
|
697
697
|
# additionalProperties: false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocina-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.78.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -462,6 +462,7 @@ files:
|
|
462
462
|
- lib/cocina/models/validators/catalog_links_validator.rb
|
463
463
|
- lib/cocina/models/validators/dark_validator.rb
|
464
464
|
- lib/cocina/models/validators/description_types_validator.rb
|
465
|
+
- lib/cocina/models/validators/description_values_validator.rb
|
465
466
|
- lib/cocina/models/validators/open_api_validator.rb
|
466
467
|
- lib/cocina/models/validators/purl_validator.rb
|
467
468
|
- lib/cocina/models/validators/validator.rb
|
@@ -476,7 +477,7 @@ homepage: https://github.com/sul-dlss/cocina-models
|
|
476
477
|
licenses: []
|
477
478
|
metadata:
|
478
479
|
rubygems_mfa_required: 'true'
|
479
|
-
post_install_message:
|
480
|
+
post_install_message:
|
480
481
|
rdoc_options: []
|
481
482
|
require_paths:
|
482
483
|
- lib
|
@@ -491,8 +492,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
491
492
|
- !ruby/object:Gem::Version
|
492
493
|
version: '0'
|
493
494
|
requirements: []
|
494
|
-
rubygems_version: 3.
|
495
|
-
signing_key:
|
495
|
+
rubygems_version: 3.3.9
|
496
|
+
signing_key:
|
496
497
|
specification_version: 4
|
497
498
|
summary: Data models for the SDR
|
498
499
|
test_files: []
|