cocina-models 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +3 -1
- data/lib/cocina/generator/schema.rb +29 -8
- data/lib/cocina/generator/schema_array.rb +5 -1
- data/lib/cocina/generator/schema_base.rb +22 -0
- data/lib/cocina/generator/schema_value.rb +1 -23
- data/lib/cocina/models.rb +2 -2
- data/lib/cocina/models/admin_policy.rb +1 -1
- data/lib/cocina/models/applies_to.rb +9 -0
- data/lib/cocina/models/collection.rb +1 -1
- data/lib/cocina/models/contributor.rb +14 -0
- data/lib/cocina/models/description.rb +17 -1
- data/lib/cocina/models/descriptive_admin_metadata.rb +12 -0
- data/lib/cocina/models/descriptive_basic_value.rb +21 -0
- data/lib/cocina/models/descriptive_structured_value.rb +9 -0
- data/lib/cocina/models/descriptive_value.rb +23 -0
- data/lib/cocina/models/descriptive_value_required.rb +23 -0
- data/lib/cocina/models/dro.rb +1 -1
- data/lib/cocina/models/event.rb +15 -0
- data/lib/cocina/models/request_admin_policy.rb +1 -1
- data/lib/cocina/models/request_collection.rb +1 -1
- data/lib/cocina/models/request_dro.rb +1 -1
- data/lib/cocina/models/source.rb +14 -0
- data/lib/cocina/models/validator.rb +12 -6
- data/lib/cocina/models/version.rb +1 -1
- data/openapi.yml +214 -13
- metadata +11 -3
- data/lib/cocina/models/title.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10987f18b2d6489790ca3edbcead8ff6aa2fedfbca1bcb18d5606b8112c88f7e
|
|
4
|
+
data.tar.gz: 1431af2debd70299b4574997d842f0107ce356b44b67123deedf237b08f669b9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff3ba29a4e6ca6a23bb55bdb12a2a4ef26852468155d812e9572a07b0711e6e22e549fbd186985e62b3b6e90deb501d938db62cf73c61823c80759a5d2b40fcc
|
|
7
|
+
data.tar.gz: a480849d853c21828d5830f6227d9e169a1f9cefac484038ebd6d0f0d661d9c40e44e217e15cd62f80a9efcfad2a51ad8c009fbe6048040475c21a5f4485228e
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
This is a Ruby implementation of the SDR data model (named "COCINA"). The data being modeled includes digital repository objects.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Validation is performed by openapi (using OpenAPIParser). Modeling is provided by dry-struct and dry-types. Together, these provide a way for consumers to validate objects against models and to manipulate thos objects.
|
|
11
11
|
|
|
12
12
|
This is a work in progress that will ultimately implement the full [COCINA data model](http://sul-dlss.github.io/cocina-models/). See also [architecture documentation](https://sul-dlss.github.io/taco-truck/COCINA.html#cocina-data-models--shapes).
|
|
13
13
|
|
|
14
14
|
## Generate models from openapi.yml
|
|
15
15
|
|
|
16
|
+
Note that only a small subset of openapi is supported. If you are using a new openapi feature or pattern, verify that the model will be generated as expected.
|
|
17
|
+
|
|
16
18
|
### All
|
|
17
19
|
```
|
|
18
20
|
exe/generator generate
|
|
@@ -5,12 +5,7 @@ module Cocina
|
|
|
5
5
|
# Class for generating from an openapi schema
|
|
6
6
|
class Schema < SchemaBase
|
|
7
7
|
def schema_properties
|
|
8
|
-
@schema_properties ||=
|
|
9
|
-
property_class_for(properties_doc).new(properties_doc,
|
|
10
|
-
key: key,
|
|
11
|
-
required: schema_doc.requires?(properties_doc),
|
|
12
|
-
parent: self)
|
|
13
|
-
end
|
|
8
|
+
@schema_properties ||= (properties + all_of_properties).uniq(&:key)
|
|
14
9
|
end
|
|
15
10
|
|
|
16
11
|
def generate
|
|
@@ -54,7 +49,7 @@ module Cocina
|
|
|
54
49
|
|
|
55
50
|
def types
|
|
56
51
|
type_properties_doc = schema_doc.properties['type']
|
|
57
|
-
return '' if type_properties_doc.nil?
|
|
52
|
+
return '' if type_properties_doc.nil? || type_properties_doc.enum.nil?
|
|
58
53
|
|
|
59
54
|
types_list = type_properties_doc.enum.map { |item| "'#{item}'" }.join(",\n ")
|
|
60
55
|
|
|
@@ -70,7 +65,7 @@ module Cocina
|
|
|
70
65
|
|
|
71
66
|
<<~RUBY
|
|
72
67
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
73
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
68
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
74
69
|
super(attributes, safe, &block)
|
|
75
70
|
end
|
|
76
71
|
RUBY
|
|
@@ -79,6 +74,32 @@ module Cocina
|
|
|
79
74
|
def validatable?
|
|
80
75
|
!schema_doc.node_context.document.paths["/validate/#{schema_doc.name}"].nil?
|
|
81
76
|
end
|
|
77
|
+
|
|
78
|
+
def properties
|
|
79
|
+
schema_properties_for(schema_doc)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def all_of_properties
|
|
83
|
+
all_of_properties_for(schema_doc)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def all_of_properties_for(doc)
|
|
87
|
+
return [] if doc.all_of.nil?
|
|
88
|
+
|
|
89
|
+
doc.all_of.map do |all_of_schema|
|
|
90
|
+
# All of for this + recurse
|
|
91
|
+
schema_properties_for(all_of_schema) + all_of_properties_for(all_of_schema)
|
|
92
|
+
end.flatten
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def schema_properties_for(doc)
|
|
96
|
+
doc.properties.map do |key, properties_doc|
|
|
97
|
+
property_class_for(properties_doc).new(properties_doc,
|
|
98
|
+
key: key,
|
|
99
|
+
required: doc.requires?(properties_doc),
|
|
100
|
+
parent: self)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
82
103
|
end
|
|
83
104
|
end
|
|
84
105
|
end
|
|
@@ -5,7 +5,7 @@ module Cocina
|
|
|
5
5
|
# Class for generating from an openapi array
|
|
6
6
|
class SchemaArray < SchemaBase
|
|
7
7
|
def generate
|
|
8
|
-
"attribute :#{name.camelize(:lower)}, Types::Strict::Array.of(#{
|
|
8
|
+
"attribute :#{name.camelize(:lower)}, Types::Strict::Array.of(#{array_of_type})#{omittable}"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def omittable
|
|
@@ -15,6 +15,10 @@ module Cocina
|
|
|
15
15
|
'.meta(omittable: true)'
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
def array_of_type
|
|
20
|
+
schema_doc.items.name || "Types::#{dry_datatype(schema_doc.items)}"
|
|
21
|
+
end
|
|
18
22
|
end
|
|
19
23
|
end
|
|
20
24
|
end
|
|
@@ -44,6 +44,28 @@ module Cocina
|
|
|
44
44
|
|
|
45
45
|
"# example: #{schema_doc.example}\n"
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
def dry_datatype(doc)
|
|
49
|
+
case doc.type
|
|
50
|
+
when 'integer'
|
|
51
|
+
'Strict::Integer'
|
|
52
|
+
when 'string'
|
|
53
|
+
string_dry_datatype(doc)
|
|
54
|
+
when 'boolean'
|
|
55
|
+
'Strict::Bool'
|
|
56
|
+
else
|
|
57
|
+
raise "#{schema_doc.type} not supported"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def string_dry_datatype(doc)
|
|
62
|
+
case doc.format
|
|
63
|
+
when 'date-time'
|
|
64
|
+
'Params::DateTime'
|
|
65
|
+
else
|
|
66
|
+
'Strict::String'
|
|
67
|
+
end
|
|
68
|
+
end
|
|
47
69
|
end
|
|
48
70
|
end
|
|
49
71
|
end
|
|
@@ -6,34 +6,12 @@ module Cocina
|
|
|
6
6
|
class SchemaValue < SchemaBase
|
|
7
7
|
# rubocop:disable Metrics/LineLength
|
|
8
8
|
def generate
|
|
9
|
-
"#{description}#{example}attribute :#{name.camelize(:lower)}, Types::#{dry_datatype}#{default}#{enum}#{omittable}"
|
|
9
|
+
"#{description}#{example}attribute :#{name.camelize(:lower)}, Types::#{dry_datatype(schema_doc)}#{default}#{enum}#{omittable}"
|
|
10
10
|
end
|
|
11
11
|
# rubocop:enable Metrics/LineLength
|
|
12
12
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
|
-
def dry_datatype
|
|
16
|
-
case schema_doc.type
|
|
17
|
-
when 'integer'
|
|
18
|
-
'Strict::Integer'
|
|
19
|
-
when 'string'
|
|
20
|
-
string_dry_datatype
|
|
21
|
-
when 'boolean'
|
|
22
|
-
'Strict::Bool'
|
|
23
|
-
else
|
|
24
|
-
raise "#{schema_doc.type} not supported"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def string_dry_datatype
|
|
29
|
-
case schema_doc.format
|
|
30
|
-
when 'date-time'
|
|
31
|
-
'Params::DateTime'
|
|
32
|
-
else
|
|
33
|
-
'Strict::String'
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
15
|
def enum
|
|
38
16
|
return '' unless schema_doc.enum
|
|
39
17
|
|
data/lib/cocina/models.rb
CHANGED
|
@@ -78,7 +78,7 @@ module Cocina
|
|
|
78
78
|
else
|
|
79
79
|
raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
|
|
80
80
|
end
|
|
81
|
-
clazz.new(dyn,
|
|
81
|
+
clazz.new(dyn, false, validate)
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
# @param [Hash] dyn a ruby hash representation of the JSON serialization of a request for a Collection or DRO
|
|
@@ -98,7 +98,7 @@ module Cocina
|
|
|
98
98
|
else
|
|
99
99
|
raise UnknownTypeError, "Unknown type: '#{dyn.fetch('type')}'"
|
|
100
100
|
end
|
|
101
|
-
clazz.new(dyn,
|
|
101
|
+
clazz.new(dyn, false, validate)
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
end
|
|
@@ -17,7 +17,7 @@ module Cocina
|
|
|
17
17
|
attribute :description, Description.optional.meta(omittable: true)
|
|
18
18
|
|
|
19
19
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
20
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
20
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
21
21
|
super(attributes, safe, &block)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
@@ -26,7 +26,7 @@ module Cocina
|
|
|
26
26
|
attribute :identification, CollectionIdentification.optional.meta(omittable: true)
|
|
27
27
|
|
|
28
28
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
29
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
29
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
30
30
|
super(attributes, safe, &block)
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class Contributor < Struct
|
|
6
|
+
attribute :name, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
7
|
+
# Entity type of the contributor (person, organization, etc.).
|
|
8
|
+
attribute :type, Types::Strict::String.meta(omittable: true)
|
|
9
|
+
# Status of the contributor relative to other parallel contributors.
|
|
10
|
+
attribute :status, Types::Strict::String.meta(omittable: true)
|
|
11
|
+
attribute :role, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -3,7 +3,23 @@
|
|
|
3
3
|
module Cocina
|
|
4
4
|
module Models
|
|
5
5
|
class Description < Struct
|
|
6
|
-
attribute :title, Types::Strict::Array.of(
|
|
6
|
+
attribute :title, Types::Strict::Array.of(DescriptiveValueRequired).default([].freeze)
|
|
7
|
+
attribute :contributor, Types::Strict::Array.of(Contributor).meta(omittable: true)
|
|
8
|
+
attribute :event, Types::Strict::Array.of(Event).meta(omittable: true)
|
|
9
|
+
attribute :form, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
10
|
+
attribute :language, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
11
|
+
attribute :note, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
12
|
+
attribute :identifier, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
13
|
+
# Stanford persistent URL associated with the resource.
|
|
14
|
+
attribute :purl, Types::Strict::String.meta(omittable: true)
|
|
15
|
+
attribute :url, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
16
|
+
attribute :marcEncodedData, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
17
|
+
attribute :adminMetadata, DescriptiveAdminMetadata.optional.meta(omittable: true)
|
|
18
|
+
|
|
19
|
+
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
20
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
21
|
+
super(attributes, safe, &block)
|
|
22
|
+
end
|
|
7
23
|
end
|
|
8
24
|
end
|
|
9
25
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class DescriptiveAdminMetadata < Struct
|
|
6
|
+
attribute :contributor, Types::Strict::Array.of(Contributor).meta(omittable: true)
|
|
7
|
+
attribute :event, Types::Strict::Array.of(Event).meta(omittable: true)
|
|
8
|
+
attribute :language, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
9
|
+
attribute :note, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class DescriptiveBasicValue < Struct
|
|
6
|
+
# String value of the descriptive element.
|
|
7
|
+
attribute :value, Types::Strict::String.meta(omittable: true)
|
|
8
|
+
# Type of value provided by the descriptive element.
|
|
9
|
+
attribute :type, Types::Strict::String.meta(omittable: true)
|
|
10
|
+
# Status of the descriptive element relative to other instances of the element.
|
|
11
|
+
attribute :status, Types::Strict::String.meta(omittable: true)
|
|
12
|
+
# Code value of the descriptive element.
|
|
13
|
+
attribute :code, Types::Strict::String.meta(omittable: true)
|
|
14
|
+
# URI value of the descriptive element.
|
|
15
|
+
attribute :uri, Types::Strict::String.meta(omittable: true)
|
|
16
|
+
attribute :standard, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
17
|
+
attribute :encoding, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
18
|
+
attribute :source, Source.optional.meta(omittable: true)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class DescriptiveValue < Struct
|
|
6
|
+
# String value of the descriptive element.
|
|
7
|
+
attribute :value, Types::Strict::String.meta(omittable: true)
|
|
8
|
+
# Type of value provided by the descriptive element.
|
|
9
|
+
attribute :type, Types::Strict::String.meta(omittable: true)
|
|
10
|
+
# Status of the descriptive element relative to other instances of the element.
|
|
11
|
+
attribute :status, Types::Strict::String.meta(omittable: true)
|
|
12
|
+
# Code value of the descriptive element.
|
|
13
|
+
attribute :code, Types::Strict::String.meta(omittable: true)
|
|
14
|
+
# URI value of the descriptive element.
|
|
15
|
+
attribute :uri, Types::Strict::String.meta(omittable: true)
|
|
16
|
+
attribute :standard, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
17
|
+
attribute :encoding, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
18
|
+
attribute :source, Source.optional.meta(omittable: true)
|
|
19
|
+
attribute :structuredValue, Types::Strict::Array.of(DescriptiveBasicValue).meta(omittable: true)
|
|
20
|
+
attribute :appliesTo, Types::Strict::Array.of(DescriptiveBasicValue).meta(omittable: true)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class DescriptiveValueRequired < Struct
|
|
6
|
+
# String value of the descriptive element.
|
|
7
|
+
attribute :value, Types::Strict::String.meta(omittable: true)
|
|
8
|
+
# Type of value provided by the descriptive element.
|
|
9
|
+
attribute :type, Types::Strict::String.meta(omittable: true)
|
|
10
|
+
# Status of the descriptive element relative to other instances of the element.
|
|
11
|
+
attribute :status, Types::Strict::String.meta(omittable: true)
|
|
12
|
+
# Code value of the descriptive element.
|
|
13
|
+
attribute :code, Types::Strict::String.meta(omittable: true)
|
|
14
|
+
# URI value of the descriptive element.
|
|
15
|
+
attribute :uri, Types::Strict::String.meta(omittable: true)
|
|
16
|
+
attribute :standard, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
17
|
+
attribute :encoding, Types::Strict::Array.of(Types::Strict::String).meta(omittable: true)
|
|
18
|
+
attribute :source, Source.optional.meta(omittable: true)
|
|
19
|
+
attribute :structuredValue, Types::Strict::Array.of(DescriptiveBasicValue).meta(omittable: true)
|
|
20
|
+
attribute :appliesTo, Types::Strict::Array.of(DescriptiveBasicValue).meta(omittable: true)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/cocina/models/dro.rb
CHANGED
|
@@ -38,7 +38,7 @@ module Cocina
|
|
|
38
38
|
attribute :geographic, Geographic.optional.meta(omittable: true)
|
|
39
39
|
|
|
40
40
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
41
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
41
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
42
42
|
super(attributes, safe, &block)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class Event < Struct
|
|
6
|
+
# Description of the event (creation, publication, etc.).
|
|
7
|
+
attribute :type, Types::Strict::String.meta(omittable: true)
|
|
8
|
+
attribute :date, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
9
|
+
attribute :contributor, Types::Strict::Array.of(Contributor).meta(omittable: true)
|
|
10
|
+
attribute :location, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
11
|
+
attribute :note, Types::Strict::Array.of(DescriptiveValue).meta(omittable: true)
|
|
12
|
+
attribute :structuredValue, Types::Strict::Array.of(DescriptiveBasicValue).meta(omittable: true)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -15,7 +15,7 @@ module Cocina
|
|
|
15
15
|
attribute :description, Description.optional.meta(omittable: true)
|
|
16
16
|
|
|
17
17
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
18
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
18
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
19
19
|
super(attributes, safe, &block)
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -21,7 +21,7 @@ module Cocina
|
|
|
21
21
|
attribute :identification, CollectionIdentification.optional.meta(omittable: true)
|
|
22
22
|
|
|
23
23
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
24
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
24
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
25
25
|
super(attributes, safe, &block)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -33,7 +33,7 @@ module Cocina
|
|
|
33
33
|
attribute :geographic, Geographic.optional.meta(omittable: true)
|
|
34
34
|
|
|
35
35
|
def self.new(attributes = default_attributes, safe = false, validate = true, &block)
|
|
36
|
-
Validator.validate(self, attributes.with_indifferent_access) if validate
|
|
36
|
+
Validator.validate(self, attributes.with_indifferent_access) if validate && name
|
|
37
37
|
super(attributes, safe, &block)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cocina
|
|
4
|
+
module Models
|
|
5
|
+
class Source < Struct
|
|
6
|
+
# Code representing the value source.
|
|
7
|
+
attribute :code, Types::Strict::String.meta(omittable: true)
|
|
8
|
+
# URI for the value source.
|
|
9
|
+
attribute :uri, Types::Strict::String.meta(omittable: true)
|
|
10
|
+
# String describing the value source.
|
|
11
|
+
attribute :value, Types::Strict::String.meta(omittable: true)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -4,12 +4,6 @@ module Cocina
|
|
|
4
4
|
module Models
|
|
5
5
|
# Perform validation against openapi
|
|
6
6
|
class Validator
|
|
7
|
-
# rubocop:disable Style/ClassVars
|
|
8
|
-
def self.root
|
|
9
|
-
@@root ||= OpenAPIParser.parse(YAML.load_file('openapi.yml'))
|
|
10
|
-
end
|
|
11
|
-
# rubocop:enable Style/ClassVars
|
|
12
|
-
|
|
13
7
|
def self.validate(clazz, attributes)
|
|
14
8
|
method_name = clazz.name.split('::').last
|
|
15
9
|
request_operation = root.request_operation(:post, "/validate/#{method_name}")
|
|
@@ -17,6 +11,18 @@ module Cocina
|
|
|
17
11
|
rescue OpenAPIParser::OpenAPIError => e
|
|
18
12
|
raise ValidationError, e.message
|
|
19
13
|
end
|
|
14
|
+
|
|
15
|
+
# rubocop:disable Style/ClassVars
|
|
16
|
+
def self.root
|
|
17
|
+
@@root ||= OpenAPIParser.parse(YAML.load_file(openapi_path))
|
|
18
|
+
end
|
|
19
|
+
# rubocop:enable Style/ClassVars
|
|
20
|
+
private_class_method :root
|
|
21
|
+
|
|
22
|
+
def self.openapi_path
|
|
23
|
+
::File.expand_path('../../../openapi.yml', __dir__)
|
|
24
|
+
end
|
|
25
|
+
private_class_method :openapi_path
|
|
20
26
|
end
|
|
21
27
|
end
|
|
22
28
|
end
|
data/openapi.yml
CHANGED
|
@@ -79,7 +79,18 @@ paths:
|
|
|
79
79
|
responses:
|
|
80
80
|
'200':
|
|
81
81
|
description: noop
|
|
82
|
-
|
|
82
|
+
/validate/Description:
|
|
83
|
+
post:
|
|
84
|
+
summary: Validate a Description
|
|
85
|
+
requestBody:
|
|
86
|
+
required: true
|
|
87
|
+
content:
|
|
88
|
+
application/json:
|
|
89
|
+
schema:
|
|
90
|
+
$ref: '#/components/schemas/Description'
|
|
91
|
+
responses:
|
|
92
|
+
'200':
|
|
93
|
+
description: noop
|
|
83
94
|
components:
|
|
84
95
|
schemas:
|
|
85
96
|
Access:
|
|
@@ -144,6 +155,15 @@ components:
|
|
|
144
155
|
type: string
|
|
145
156
|
hasAdminPolicy:
|
|
146
157
|
type: string
|
|
158
|
+
AppliesTo:
|
|
159
|
+
description: Property model for indicating the parts, aspects, or versions of the resource to which a
|
|
160
|
+
descriptive element is applicable.
|
|
161
|
+
type: object
|
|
162
|
+
properties:
|
|
163
|
+
appliesTo:
|
|
164
|
+
type: array
|
|
165
|
+
items:
|
|
166
|
+
$ref: "#/components/schemas/DescriptiveBasicValue"
|
|
147
167
|
CatalogLink:
|
|
148
168
|
type: object
|
|
149
169
|
required:
|
|
@@ -201,14 +221,164 @@ components:
|
|
|
201
221
|
type: array
|
|
202
222
|
items:
|
|
203
223
|
$ref: '#/components/schemas/CatalogLink'
|
|
224
|
+
Contributor:
|
|
225
|
+
description: Property model for describing agents contributing in some way to
|
|
226
|
+
the creation and history of the resource
|
|
227
|
+
type: object
|
|
228
|
+
properties:
|
|
229
|
+
name:
|
|
230
|
+
description: Names associated with a contributor.
|
|
231
|
+
type: array
|
|
232
|
+
items:
|
|
233
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
234
|
+
type:
|
|
235
|
+
description: Entity type of the contributor (person, organization, etc.).
|
|
236
|
+
type: string
|
|
237
|
+
status:
|
|
238
|
+
description: Status of the contributor relative to other parallel contributors.
|
|
239
|
+
type: string
|
|
240
|
+
role:
|
|
241
|
+
description: Relationships of the contributor to the resource or to an event
|
|
242
|
+
in its history.
|
|
243
|
+
type: array
|
|
244
|
+
items:
|
|
245
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
246
|
+
DescriptiveAdminMetadata:
|
|
247
|
+
description: Information about this description of the resource.
|
|
248
|
+
type: object
|
|
249
|
+
properties:
|
|
250
|
+
contributor:
|
|
251
|
+
type: array
|
|
252
|
+
items:
|
|
253
|
+
$ref: "#/components/schemas/Contributor"
|
|
254
|
+
event:
|
|
255
|
+
type: array
|
|
256
|
+
items:
|
|
257
|
+
$ref: "#/components/schemas/Event"
|
|
258
|
+
language:
|
|
259
|
+
type: array
|
|
260
|
+
items:
|
|
261
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
262
|
+
note:
|
|
263
|
+
type: array
|
|
264
|
+
items:
|
|
265
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
266
|
+
DescriptiveBasicValue:
|
|
267
|
+
description: Value model for descriptive elements without recursive properties.
|
|
268
|
+
type: object
|
|
269
|
+
properties:
|
|
270
|
+
value:
|
|
271
|
+
description: String value of the descriptive element.
|
|
272
|
+
type: string
|
|
273
|
+
type:
|
|
274
|
+
description: Type of value provided by the descriptive element.
|
|
275
|
+
type: string
|
|
276
|
+
status:
|
|
277
|
+
description: Status of the descriptive element relative to other instances
|
|
278
|
+
of the element.
|
|
279
|
+
type: string
|
|
280
|
+
code:
|
|
281
|
+
description: Code value of the descriptive element.
|
|
282
|
+
type: string
|
|
283
|
+
uri:
|
|
284
|
+
description: URI value of the descriptive element.
|
|
285
|
+
type: string
|
|
286
|
+
format: uri
|
|
287
|
+
standard:
|
|
288
|
+
description: Descriptive or content standard to which the value conforms.
|
|
289
|
+
type: array
|
|
290
|
+
items:
|
|
291
|
+
type: string
|
|
292
|
+
encoding:
|
|
293
|
+
description: Encoding schema, standard, or syntax to which the value conforms.
|
|
294
|
+
type: array
|
|
295
|
+
items:
|
|
296
|
+
type: string
|
|
297
|
+
source:
|
|
298
|
+
$ref: "#/components/schemas/Source"
|
|
299
|
+
DescriptiveStructuredValue:
|
|
300
|
+
description: Value model for descriptive elements structured as typed values.
|
|
301
|
+
type: object
|
|
302
|
+
properties:
|
|
303
|
+
structuredValue:
|
|
304
|
+
type: array
|
|
305
|
+
items:
|
|
306
|
+
$ref: "#/components/schemas/DescriptiveBasicValue"
|
|
307
|
+
DescriptiveValue:
|
|
308
|
+
description: Default value model for descriptive elements.
|
|
309
|
+
type: object
|
|
310
|
+
allOf:
|
|
311
|
+
- $ref: "#/components/schemas/DescriptiveBasicValue"
|
|
312
|
+
- $ref: "#/components/schemas/DescriptiveStructuredValue"
|
|
313
|
+
- $ref: "#/components/schemas/AppliesTo"
|
|
314
|
+
DescriptiveValueRequired:
|
|
315
|
+
type: object
|
|
316
|
+
allOf:
|
|
317
|
+
- $ref: "#/components/schemas/DescriptiveValue"
|
|
318
|
+
- anyOf:
|
|
319
|
+
- type: object
|
|
320
|
+
required:
|
|
321
|
+
- value
|
|
322
|
+
- type: object
|
|
323
|
+
- required:
|
|
324
|
+
- structuredValue
|
|
204
325
|
Description:
|
|
205
|
-
description: Descriptive metadata
|
|
206
326
|
type: object
|
|
207
327
|
properties:
|
|
208
328
|
title:
|
|
329
|
+
description: Titles of the resource.
|
|
330
|
+
type: array
|
|
331
|
+
minItems: 1
|
|
332
|
+
items:
|
|
333
|
+
$ref: "#/components/schemas/DescriptiveValueRequired"
|
|
334
|
+
contributor:
|
|
335
|
+
description: Agents contributing in some way to the creation and history of the
|
|
336
|
+
resource.
|
|
337
|
+
type: array
|
|
338
|
+
items:
|
|
339
|
+
$ref: "#/components/schemas/Contributor"
|
|
340
|
+
event:
|
|
341
|
+
description: Events in the history of the resource.
|
|
342
|
+
type: array
|
|
343
|
+
items:
|
|
344
|
+
$ref: "#/components/schemas/Event"
|
|
345
|
+
form:
|
|
346
|
+
description: Characteristics of the resource's physical, digital, and intellectual
|
|
347
|
+
form and genre.
|
|
348
|
+
type: array
|
|
349
|
+
items:
|
|
350
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
351
|
+
language:
|
|
352
|
+
description: Languages, scripts, and notations used in all or part of a resource.
|
|
353
|
+
type: array
|
|
354
|
+
items:
|
|
355
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
356
|
+
note:
|
|
357
|
+
description: Additional information relevant to a resource.
|
|
358
|
+
type: array
|
|
359
|
+
items:
|
|
360
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
361
|
+
identifier:
|
|
362
|
+
description: Unique strings associated with the resource.
|
|
363
|
+
type: array
|
|
364
|
+
items:
|
|
365
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
366
|
+
purl:
|
|
367
|
+
description: Stanford persistent URL associated with the resource.
|
|
368
|
+
type: string
|
|
369
|
+
format: uri
|
|
370
|
+
url:
|
|
371
|
+
description: URLs where the resource may be accessed in full or part.
|
|
372
|
+
type: array
|
|
373
|
+
items:
|
|
374
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
375
|
+
marcEncodedData:
|
|
376
|
+
description: Data about the resource represented in MARC fixed fields and codes.
|
|
209
377
|
type: array
|
|
210
378
|
items:
|
|
211
|
-
$ref:
|
|
379
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
380
|
+
adminMetadata:
|
|
381
|
+
$ref: "#/components/schemas/DescriptiveAdminMetadata"
|
|
212
382
|
required:
|
|
213
383
|
- title
|
|
214
384
|
DRO:
|
|
@@ -330,6 +500,35 @@ components:
|
|
|
330
500
|
required:
|
|
331
501
|
- releaseDate
|
|
332
502
|
- access
|
|
503
|
+
Event:
|
|
504
|
+
description: Property model for describing events in the history of the resource.
|
|
505
|
+
type: object
|
|
506
|
+
properties:
|
|
507
|
+
type:
|
|
508
|
+
description: Description of the event (creation, publication, etc.).
|
|
509
|
+
type: string
|
|
510
|
+
date:
|
|
511
|
+
description: Dates associated with the event.
|
|
512
|
+
type: array
|
|
513
|
+
items:
|
|
514
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
515
|
+
contributor:
|
|
516
|
+
description: Contributors associated with the event.
|
|
517
|
+
type: array
|
|
518
|
+
items:
|
|
519
|
+
$ref: "#/components/schemas/Contributor"
|
|
520
|
+
location:
|
|
521
|
+
description: Locations associated with the event.
|
|
522
|
+
type: array
|
|
523
|
+
items:
|
|
524
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
525
|
+
note:
|
|
526
|
+
description: Other information about the event.
|
|
527
|
+
type: array
|
|
528
|
+
items:
|
|
529
|
+
$ref: "#/components/schemas/DescriptiveValue"
|
|
530
|
+
allOf:
|
|
531
|
+
- $ref: "#/components/schemas/DescriptiveStructuredValue"
|
|
333
532
|
File:
|
|
334
533
|
description: Binaries that are the basis of what our domain manages. Binaries here do not include metadata files generated for the domain's own management purposes.
|
|
335
534
|
type: object
|
|
@@ -680,16 +879,18 @@ components:
|
|
|
680
879
|
enum:
|
|
681
880
|
- right-to-left
|
|
682
881
|
- left-to-right
|
|
683
|
-
|
|
684
|
-
description:
|
|
882
|
+
Source:
|
|
883
|
+
description: Property model for indicating the vocabulary, authority, or other
|
|
884
|
+
origin for a term, code, or identifier.
|
|
685
885
|
type: object
|
|
686
886
|
properties:
|
|
687
|
-
|
|
688
|
-
description:
|
|
689
|
-
type:
|
|
690
|
-
|
|
691
|
-
description:
|
|
887
|
+
code:
|
|
888
|
+
description: Code representing the value source.
|
|
889
|
+
type: string
|
|
890
|
+
uri:
|
|
891
|
+
description: URI for the value source.
|
|
892
|
+
type: string
|
|
893
|
+
format: uri
|
|
894
|
+
value:
|
|
895
|
+
description: String describing the value source.
|
|
692
896
|
type: string
|
|
693
|
-
required:
|
|
694
|
-
- primary
|
|
695
|
-
- titleFull
|
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.31.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Coyne
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-03-
|
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -260,15 +260,23 @@ files:
|
|
|
260
260
|
- lib/cocina/models/admin_policy.rb
|
|
261
261
|
- lib/cocina/models/admin_policy_administrative.rb
|
|
262
262
|
- lib/cocina/models/administrative.rb
|
|
263
|
+
- lib/cocina/models/applies_to.rb
|
|
263
264
|
- lib/cocina/models/catalog_link.rb
|
|
264
265
|
- lib/cocina/models/checkable.rb
|
|
265
266
|
- lib/cocina/models/collection.rb
|
|
266
267
|
- lib/cocina/models/collection_identification.rb
|
|
268
|
+
- lib/cocina/models/contributor.rb
|
|
267
269
|
- lib/cocina/models/description.rb
|
|
270
|
+
- lib/cocina/models/descriptive_admin_metadata.rb
|
|
271
|
+
- lib/cocina/models/descriptive_basic_value.rb
|
|
272
|
+
- lib/cocina/models/descriptive_structured_value.rb
|
|
273
|
+
- lib/cocina/models/descriptive_value.rb
|
|
274
|
+
- lib/cocina/models/descriptive_value_required.rb
|
|
268
275
|
- lib/cocina/models/dro.rb
|
|
269
276
|
- lib/cocina/models/dro_access.rb
|
|
270
277
|
- lib/cocina/models/dro_structural.rb
|
|
271
278
|
- lib/cocina/models/embargo.rb
|
|
279
|
+
- lib/cocina/models/event.rb
|
|
272
280
|
- lib/cocina/models/file.rb
|
|
273
281
|
- lib/cocina/models/file_administrative.rb
|
|
274
282
|
- lib/cocina/models/file_set.rb
|
|
@@ -286,7 +294,7 @@ files:
|
|
|
286
294
|
- lib/cocina/models/request_file_set.rb
|
|
287
295
|
- lib/cocina/models/request_file_set_structural.rb
|
|
288
296
|
- lib/cocina/models/sequence.rb
|
|
289
|
-
- lib/cocina/models/
|
|
297
|
+
- lib/cocina/models/source.rb
|
|
290
298
|
- lib/cocina/models/validator.rb
|
|
291
299
|
- lib/cocina/models/version.rb
|
|
292
300
|
- lib/cocina/models/vocab.rb
|
data/lib/cocina/models/title.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Cocina
|
|
4
|
-
module Models
|
|
5
|
-
class Title < Struct
|
|
6
|
-
# Is this the primary title for the object
|
|
7
|
-
attribute :primary, Types::Strict::Bool.default(false)
|
|
8
|
-
# The full title for the object
|
|
9
|
-
attribute :titleFull, Types::Strict::String
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|