cocina-models 0.66.0 → 0.68.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/README.md +5 -0
- data/cocina-models.gemspec +3 -1
- data/lib/cocina/generator/generator.rb +1 -6
- data/lib/cocina/generator/vocab.rb +36 -39
- data/lib/cocina/models/access.rb +3 -3
- data/lib/cocina/models/admin_policy.rb +1 -1
- data/lib/cocina/models/{admin_policy_default_access.rb → admin_policy_access_template.rb} +4 -4
- data/lib/cocina/models/admin_policy_administrative.rb +1 -1
- data/lib/cocina/models/administrative.rb +0 -3
- data/lib/cocina/models/citation_only_access.rb +3 -3
- data/lib/cocina/models/collection.rb +6 -6
- data/lib/cocina/models/collection_access.rb +1 -1
- data/lib/cocina/models/controlled_digital_lending_access.rb +3 -3
- data/lib/cocina/models/dark_access.rb +3 -3
- data/lib/cocina/models/dro.rb +16 -16
- data/lib/cocina/models/dro_access.rb +4 -4
- data/lib/cocina/models/embargo.rb +3 -3
- data/lib/cocina/models/file.rb +1 -1
- data/lib/cocina/models/file_access.rb +3 -3
- data/lib/cocina/models/file_set.rb +16 -16
- data/lib/cocina/models/file_set_type.rb +72 -0
- data/lib/cocina/models/location_based_access.rb +3 -3
- data/lib/cocina/models/location_based_download_access.rb +3 -3
- data/lib/cocina/models/object_type.rb +96 -0
- data/lib/cocina/models/request_admin_policy.rb +2 -2
- data/lib/cocina/models/request_administrative.rb +14 -0
- data/lib/cocina/models/request_collection.rb +7 -7
- data/lib/cocina/models/request_dro.rb +17 -17
- data/lib/cocina/models/request_file.rb +1 -1
- data/lib/cocina/models/request_file_set.rb +16 -16
- data/lib/cocina/models/stanford_access.rb +3 -3
- data/lib/cocina/models/validator.rb +1 -1
- data/lib/cocina/models/version.rb +1 -1
- data/lib/cocina/models/world_access.rb +3 -3
- data/lib/cocina/models.rb +14 -7
- data/openapi.yml +143 -122
- metadata +14 -6
- data/lib/cocina/models/vocab.rb +0 -162
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cocina
|
4
|
+
module Models
|
5
|
+
# This vocabulary defines the top level object type
|
6
|
+
class ObjectType
|
7
|
+
def self.three_dimensional
|
8
|
+
'https://cocina.sul.stanford.edu/models/3d'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.admin_policy
|
12
|
+
'https://cocina.sul.stanford.edu/models/admin_policy'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.agreement
|
16
|
+
'https://cocina.sul.stanford.edu/models/agreement'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.book
|
20
|
+
'https://cocina.sul.stanford.edu/models/book'
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.collection
|
24
|
+
'https://cocina.sul.stanford.edu/models/collection'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.curated_collection
|
28
|
+
'https://cocina.sul.stanford.edu/models/curated-collection'
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.document
|
32
|
+
'https://cocina.sul.stanford.edu/models/document'
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.exhibit
|
36
|
+
'https://cocina.sul.stanford.edu/models/exhibit'
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.file
|
40
|
+
'https://cocina.sul.stanford.edu/models/file'
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.geo
|
44
|
+
'https://cocina.sul.stanford.edu/models/geo'
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.image
|
48
|
+
'https://cocina.sul.stanford.edu/models/image'
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.manuscript
|
52
|
+
'https://cocina.sul.stanford.edu/models/manuscript'
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.map
|
56
|
+
'https://cocina.sul.stanford.edu/models/map'
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.media
|
60
|
+
'https://cocina.sul.stanford.edu/models/media'
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.object
|
64
|
+
'https://cocina.sul.stanford.edu/models/object'
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.page
|
68
|
+
'https://cocina.sul.stanford.edu/models/page'
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.photograph
|
72
|
+
'https://cocina.sul.stanford.edu/models/photograph'
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.series
|
76
|
+
'https://cocina.sul.stanford.edu/models/series'
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.track
|
80
|
+
'https://cocina.sul.stanford.edu/models/track'
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.user_collection
|
84
|
+
'https://cocina.sul.stanford.edu/models/user-collection'
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.webarchive_binary
|
88
|
+
'https://cocina.sul.stanford.edu/models/webarchive-binary'
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.webarchive_seed
|
92
|
+
'https://cocina.sul.stanford.edu/models/webarchive-seed'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -7,14 +7,14 @@ module Cocina
|
|
7
7
|
|
8
8
|
include Checkable
|
9
9
|
|
10
|
-
TYPES = ['
|
10
|
+
TYPES = ['https://cocina.sul.stanford.edu/models/admin_policy'].freeze
|
11
11
|
|
12
12
|
# The version of Cocina with which this object conforms.
|
13
13
|
# example: 1.2.3
|
14
14
|
attribute :cocinaVersion, Types::Strict::String.default(Cocina::Models::VERSION)
|
15
15
|
attribute :type, Types::Strict::String.enum(*RequestAdminPolicy::TYPES)
|
16
16
|
attribute :label, Types::Strict::String
|
17
|
-
attribute :version, Types::Strict::Integer
|
17
|
+
attribute :version, Types::Strict::Integer.default(1).enum(1)
|
18
18
|
attribute(:administrative, AdminPolicyAdministrative.default { AdminPolicyAdministrative.new })
|
19
19
|
attribute :description, RequestDescription.optional.meta(omittable: true)
|
20
20
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cocina
|
4
|
+
module Models
|
5
|
+
class RequestAdministrative < Struct
|
6
|
+
# example: druid:bc123df4567
|
7
|
+
attribute :hasAdminPolicy, Types::Strict::String
|
8
|
+
attribute :releaseTags, Types::Strict::Array.of(ReleaseTag).default([].freeze)
|
9
|
+
# Internal project this resource is a part of. This governs routing of messages about this object.
|
10
|
+
# example: Google Books
|
11
|
+
attribute :partOfProject, Types::Strict::String.meta(omittable: true)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -7,20 +7,20 @@ module Cocina
|
|
7
7
|
|
8
8
|
include Checkable
|
9
9
|
|
10
|
-
TYPES = ['
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
10
|
+
TYPES = ['https://cocina.sul.stanford.edu/models/collection',
|
11
|
+
'https://cocina.sul.stanford.edu/models/curated-collection',
|
12
|
+
'https://cocina.sul.stanford.edu/models/user-collection',
|
13
|
+
'https://cocina.sul.stanford.edu/models/exhibit',
|
14
|
+
'https://cocina.sul.stanford.edu/models/series'].freeze
|
15
15
|
|
16
16
|
# The version of Cocina with which this object conforms.
|
17
17
|
# example: 1.2.3
|
18
18
|
attribute :cocinaVersion, Types::Strict::String.default(Cocina::Models::VERSION)
|
19
19
|
attribute :type, Types::Strict::String.enum(*RequestCollection::TYPES)
|
20
20
|
attribute :label, Types::Strict::String
|
21
|
-
attribute :version, Types::Strict::Integer
|
21
|
+
attribute :version, Types::Strict::Integer.default(1).enum(1)
|
22
22
|
attribute(:access, CollectionAccess.default { CollectionAccess.new })
|
23
|
-
attribute(:administrative,
|
23
|
+
attribute(:administrative, RequestAdministrative.default { RequestAdministrative.new })
|
24
24
|
attribute :description, RequestDescription.optional.meta(omittable: true)
|
25
25
|
attribute :identification, CollectionIdentification.optional.meta(omittable: true)
|
26
26
|
end
|
@@ -7,30 +7,30 @@ module Cocina
|
|
7
7
|
|
8
8
|
include Checkable
|
9
9
|
|
10
|
-
TYPES = ['
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
10
|
+
TYPES = ['https://cocina.sul.stanford.edu/models/object',
|
11
|
+
'https://cocina.sul.stanford.edu/models/3d',
|
12
|
+
'https://cocina.sul.stanford.edu/models/agreement',
|
13
|
+
'https://cocina.sul.stanford.edu/models/book',
|
14
|
+
'https://cocina.sul.stanford.edu/models/document',
|
15
|
+
'https://cocina.sul.stanford.edu/models/geo',
|
16
|
+
'https://cocina.sul.stanford.edu/models/image',
|
17
|
+
'https://cocina.sul.stanford.edu/models/page',
|
18
|
+
'https://cocina.sul.stanford.edu/models/photograph',
|
19
|
+
'https://cocina.sul.stanford.edu/models/manuscript',
|
20
|
+
'https://cocina.sul.stanford.edu/models/map',
|
21
|
+
'https://cocina.sul.stanford.edu/models/media',
|
22
|
+
'https://cocina.sul.stanford.edu/models/track',
|
23
|
+
'https://cocina.sul.stanford.edu/models/webarchive-binary',
|
24
|
+
'https://cocina.sul.stanford.edu/models/webarchive-seed'].freeze
|
25
25
|
|
26
26
|
# The version of Cocina with which this object conforms.
|
27
27
|
# example: 1.2.3
|
28
28
|
attribute :cocinaVersion, Types::Strict::String.default(Cocina::Models::VERSION)
|
29
29
|
attribute :type, Types::Strict::String.enum(*RequestDRO::TYPES)
|
30
30
|
attribute :label, Types::Strict::String
|
31
|
-
attribute :version, Types::Strict::Integer
|
31
|
+
attribute :version, Types::Strict::Integer.default(1).enum(1)
|
32
32
|
attribute :access, DROAccess.optional.meta(omittable: true)
|
33
|
-
attribute(:administrative,
|
33
|
+
attribute(:administrative, RequestAdministrative.default { RequestAdministrative.new })
|
34
34
|
attribute :description, RequestDescription.optional.meta(omittable: true)
|
35
35
|
attribute(:identification, RequestIdentification.default { RequestIdentification.new })
|
36
36
|
attribute :structural, RequestDROStructural.optional.meta(omittable: true)
|
@@ -5,7 +5,7 @@ module Cocina
|
|
5
5
|
class RequestFile < Struct
|
6
6
|
include Checkable
|
7
7
|
|
8
|
-
TYPES = ['
|
8
|
+
TYPES = ['https://cocina.sul.stanford.edu/models/file'].freeze
|
9
9
|
|
10
10
|
attribute :type, Types::Strict::String.enum(*RequestFile::TYPES)
|
11
11
|
attribute :label, Types::Strict::String
|
@@ -5,22 +5,22 @@ module Cocina
|
|
5
5
|
class RequestFileSet < Struct
|
6
6
|
include Checkable
|
7
7
|
|
8
|
-
TYPES = ['
|
9
|
-
'
|
10
|
-
'
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
8
|
+
TYPES = ['https://cocina.sul.stanford.edu/models/resources/audio',
|
9
|
+
'https://cocina.sul.stanford.edu/models/resources/attachment',
|
10
|
+
'https://cocina.sul.stanford.edu/models/resources/document',
|
11
|
+
'https://cocina.sul.stanford.edu/models/resources/file',
|
12
|
+
'https://cocina.sul.stanford.edu/models/resources/image',
|
13
|
+
'https://cocina.sul.stanford.edu/models/resources/main-augmented',
|
14
|
+
'https://cocina.sul.stanford.edu/models/resources/main-original',
|
15
|
+
'https://cocina.sul.stanford.edu/models/resources/media',
|
16
|
+
'https://cocina.sul.stanford.edu/models/resources/object',
|
17
|
+
'https://cocina.sul.stanford.edu/models/resources/page',
|
18
|
+
'https://cocina.sul.stanford.edu/models/resources/permissions',
|
19
|
+
'https://cocina.sul.stanford.edu/models/resources/preview',
|
20
|
+
'https://cocina.sul.stanford.edu/models/resources/supplement',
|
21
|
+
'https://cocina.sul.stanford.edu/models/resources/3d',
|
22
|
+
'https://cocina.sul.stanford.edu/models/resources/thumb',
|
23
|
+
'https://cocina.sul.stanford.edu/models/resources/video'].freeze
|
24
24
|
|
25
25
|
attribute :type, Types::Strict::String.enum(*RequestFileSet::TYPES)
|
26
26
|
attribute :label, Types::Strict::String
|
@@ -4,11 +4,11 @@ module Cocina
|
|
4
4
|
module Models
|
5
5
|
class StanfordAccess < Struct
|
6
6
|
# Access level.
|
7
|
-
attribute :
|
7
|
+
attribute :view, Types::Strict::String.enum('stanford')
|
8
8
|
# Download access level.
|
9
9
|
attribute :download, Types::Strict::String.enum('stanford')
|
10
|
-
#
|
11
|
-
attribute :
|
10
|
+
# Not used for this access type, must be null.
|
11
|
+
attribute :location, Types::Strict::String.optional.enum('').meta(omittable: true)
|
12
12
|
attribute :controlledDigitalLending, Types::Strict::Bool.enum(false).meta(omittable: true)
|
13
13
|
end
|
14
14
|
end
|
@@ -35,7 +35,7 @@ module Cocina
|
|
35
35
|
|
36
36
|
# rubocop:disable Style/ClassVars
|
37
37
|
def self.root
|
38
|
-
@@root ||= OpenAPIParser.parse(YAML.load_file(openapi_path))
|
38
|
+
@@root ||= OpenAPIParser.parse(YAML.load_file(openapi_path), strict_reference_validation: true)
|
39
39
|
end
|
40
40
|
# rubocop:enable Style/ClassVars
|
41
41
|
private_class_method :root
|
@@ -4,11 +4,11 @@ module Cocina
|
|
4
4
|
module Models
|
5
5
|
class WorldAccess < Struct
|
6
6
|
# Access level.
|
7
|
-
attribute :
|
7
|
+
attribute :view, Types::Strict::String.enum('world')
|
8
8
|
# Download access level.
|
9
9
|
attribute :download, Types::Strict::String.enum('none', 'stanford', 'world')
|
10
|
-
#
|
11
|
-
attribute :
|
10
|
+
# Not used for this access type, must be null.
|
11
|
+
attribute :location, Types::Strict::String.optional.enum('').meta(omittable: true)
|
12
12
|
attribute :controlledDigitalLending, Types::Strict::Bool.enum(false).meta(omittable: true)
|
13
13
|
end
|
14
14
|
end
|
data/lib/cocina/models.rb
CHANGED
@@ -42,7 +42,7 @@ module Cocina
|
|
42
42
|
# Raised when the type attribute is not valid.
|
43
43
|
class UnknownTypeError < Error; end
|
44
44
|
|
45
|
-
# Raised when an error occurs validating against openapi.
|
45
|
+
# Raised when the type attribute is missing or an error occurs validating against openapi.
|
46
46
|
class ValidationError < Error; end
|
47
47
|
|
48
48
|
# Base class for Cocina Structs
|
@@ -60,10 +60,10 @@ module Cocina
|
|
60
60
|
# @param [boolean] validate
|
61
61
|
# @return [DRO,Collection,AdminPolicy]
|
62
62
|
# @raises [UnknownTypeError] if a valid type is not found in the data
|
63
|
-
# @raises [
|
63
|
+
# @raises [ValidationError] if a type field cannot be found in the data
|
64
64
|
# @raises [ValidationError] if hash representation fails openapi validation
|
65
65
|
def self.build(dyn, validate: true)
|
66
|
-
clazz = case dyn
|
66
|
+
clazz = case type_for(dyn)
|
67
67
|
when *DRO::TYPES
|
68
68
|
DRO
|
69
69
|
when *Collection::TYPES
|
@@ -71,7 +71,7 @@ module Cocina
|
|
71
71
|
when *AdminPolicy::TYPES
|
72
72
|
AdminPolicy
|
73
73
|
else
|
74
|
-
raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
|
74
|
+
raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
|
75
75
|
end
|
76
76
|
clazz.new(dyn, false, validate)
|
77
77
|
end
|
@@ -80,10 +80,10 @@ module Cocina
|
|
80
80
|
# @param [boolean] validate
|
81
81
|
# @return [RequestDRO,RequestCollection,RequestAdminPolicy]
|
82
82
|
# @raises [UnknownTypeError] if a valid type is not found in the data
|
83
|
-
# @raises [
|
83
|
+
# @raises [ValidationError] if a type field cannot be found in the data
|
84
84
|
# @raises [ValidationError] if hash representation fails openapi validation
|
85
85
|
def self.build_request(dyn, validate: true)
|
86
|
-
clazz = case dyn
|
86
|
+
clazz = case type_for(dyn)
|
87
87
|
when *DRO::TYPES
|
88
88
|
RequestDRO
|
89
89
|
when *Collection::TYPES
|
@@ -91,9 +91,16 @@ module Cocina
|
|
91
91
|
when *AdminPolicy::TYPES
|
92
92
|
RequestAdminPolicy
|
93
93
|
else
|
94
|
-
raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
|
94
|
+
raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'"
|
95
95
|
end
|
96
96
|
clazz.new(dyn, false, validate)
|
97
97
|
end
|
98
|
+
|
99
|
+
def self.type_for(dyn)
|
100
|
+
dyn.with_indifferent_access.fetch('type')
|
101
|
+
rescue KeyError
|
102
|
+
raise ValidationError, 'Type field not found'
|
103
|
+
end
|
104
|
+
private_class_method :type_for
|
98
105
|
end
|
99
106
|
end
|