Class: Schematist::Schema
- Inherits:
-
Object
- Object
- Schematist::Schema
show all
- Extended by:
- DSL
- Includes:
- JsonOutput
- Defined in:
- lib/schematist/schema.rb
Constant Summary
Constants included
from JsonOutput
JsonOutput::DRAFT_2020_12
Class Method Summary
collapse
Instance Method Summary
collapse
#define, #keys, #keys_matching, #object_keywords, #reference
#conditions, #dependencies, #dependent, #given
#all_of, #any_of, #array, #none_of, #object, #one_of, #optional, #raw, #tuple
#boolean, #integer, #null, #number, #string
#all_of_schema, #any_of_schema, #array_schema, #boolean_schema, #integer_schema, #none_of_schema, #null_schema, #number_schema, #object_schema, #one_of_schema, #string_schema, #tuple_schema
Methods included from JsonOutput
#to_json, #to_json_schema
Constructor Details
#initialize(name = nil, description: nil) ⇒ Schema
Returns a new instance of Schema.
156
157
158
159
|
# File 'lib/schematist/schema.rb', line 156
def initialize(name = nil, description: nil)
@name = name || self.class.name || "Schema"
@description = description
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
169
170
171
172
173
174
175
|
# File 'lib/schematist/schema.rb', line 169
def method_missing(method_name, ...)
if respond_to_missing?(method_name)
self.class.send(method_name, ...)
else
super
end
end
|
Class Method Details
.additional_properties(value = nil) ⇒ Object
117
118
119
120
121
|
# File 'lib/schematist/schema.rb', line 117
def additional_properties(value = nil)
return @additional_properties ||= false if value.nil?
@additional_properties = value
end
|
.anchor(*args) ⇒ Object
74
75
76
|
# File 'lib/schematist/schema.rb', line 74
def anchor(*args)
core_keyword(:anchor, *args)
end
|
.annotations ⇒ Object
34
35
36
|
# File 'lib/schematist/schema.rb', line 34
def annotations
@annotations ||= {}
end
|
78
79
80
|
# File 'lib/schematist/schema.rb', line 78
def (*args)
core_keyword(:comment, *args)
end
|
.core_keywords ⇒ Object
66
67
68
|
# File 'lib/schematist/schema.rb', line 66
def core_keywords
@core_keywords ||= {}
end
|
.create(&block) ⇒ Object
9
10
11
12
13
|
# File 'lib/schematist/schema.rb', line 9
def create(&block)
schema_class = Class.new(Schema)
schema_class.class_eval(&block)
schema_class
end
|
.default(*args) ⇒ Object
46
47
48
|
# File 'lib/schematist/schema.rb', line 46
def default(*args)
annotation(:default, *args)
end
|
.definitions ⇒ Object
23
24
25
|
# File 'lib/schematist/schema.rb', line 23
def definitions
@definitions ||= {}
end
|
.deprecated(*args) ⇒ Object
54
55
56
|
# File 'lib/schematist/schema.rb', line 54
def deprecated(*args)
annotation(:deprecated, *args)
end
|
.description(*args) ⇒ Object
42
43
44
|
# File 'lib/schematist/schema.rb', line 42
def description(*args)
annotation(:description, *args)
end
|
.dynamic_anchor(*args) ⇒ Object
82
83
84
|
# File 'lib/schematist/schema.rb', line 82
def dynamic_anchor(*args)
core_keyword(:dynamic_anchor, *args)
end
|
.dynamic_ref(*args) ⇒ Object
86
87
88
|
# File 'lib/schematist/schema.rb', line 86
def dynamic_ref(*args)
core_keyword(:dynamic_ref, *args)
end
|
.examples(*args) ⇒ Object
50
51
52
|
# File 'lib/schematist/schema.rb', line 50
def examples(*args)
annotation(:examples, *args)
end
|
.id(*args) ⇒ Object
70
71
72
|
# File 'lib/schematist/schema.rb', line 70
def id(*args)
core_keyword(:id, *args)
end
|
.max_properties(value = nil) ⇒ Object
105
106
107
|
# File 'lib/schematist/schema.rb', line 105
def max_properties(value = nil)
object_keyword(:maxProperties, value)
end
|
.min_properties(value = nil) ⇒ Object
101
102
103
|
# File 'lib/schematist/schema.rb', line 101
def min_properties(value = nil)
object_keyword(:minProperties, value)
end
|
.name(name = nil) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/schematist/schema.rb', line 27
def name(name = nil)
@schema_name = name if name
return @schema_name if defined?(@schema_name)
super()
end
|
.properties ⇒ Object
15
16
17
|
# File 'lib/schematist/schema.rb', line 15
def properties
@properties ||= {}
end
|
.read_only(*args) ⇒ Object
58
59
60
|
# File 'lib/schematist/schema.rb', line 58
def read_only(*args)
annotation(:read_only, *args)
end
|
.required_properties ⇒ Object
19
20
21
|
# File 'lib/schematist/schema.rb', line 19
def required_properties
@required_properties ||= []
end
|
.self_schema(definition = nil) ⇒ Object
The schema this class is, when it is not an object built from properties. Set by
calling a type without a name: string enum: %w[a b] rather than string :status.
96
97
98
99
|
# File 'lib/schematist/schema.rb', line 96
def self_schema(definition = nil)
@self_schema = definition if definition
@self_schema
end
|
.title(*args) ⇒ Object
38
39
40
|
# File 'lib/schematist/schema.rb', line 38
def title(*args)
annotation(:title, *args)
end
|
.unevaluated_items(value = nil) ⇒ Object
113
114
115
|
# File 'lib/schematist/schema.rb', line 113
def unevaluated_items(value = nil)
object_keyword(:unevaluatedItems, value)
end
|
.unevaluated_properties(value = nil) ⇒ Object
109
110
111
|
# File 'lib/schematist/schema.rb', line 109
def unevaluated_properties(value = nil)
object_keyword(:unevaluatedProperties, value)
end
|
.valid? ⇒ Boolean
128
129
130
131
|
# File 'lib/schematist/schema.rb', line 128
def valid?
validator = Validator.new(self)
validator.valid?
end
|
.validate! ⇒ Object
123
124
125
126
|
# File 'lib/schematist/schema.rb', line 123
def validate!
validator = Validator.new(self)
validator.validate!
end
|
.vocabulary(*args) ⇒ Object
90
91
92
|
# File 'lib/schematist/schema.rb', line 90
def vocabulary(*args)
core_keyword(:vocabulary, *args)
end
|
.write_only(*args) ⇒ Object
62
63
64
|
# File 'lib/schematist/schema.rb', line 62
def write_only(*args)
annotation(:write_only, *args)
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
177
178
179
|
# File 'lib/schematist/schema.rb', line 177
def respond_to_missing?(method_name, include_private = false)
%i[string number integer boolean array tuple object any_of one_of all_of none_of raw null].include?(method_name) || super
end
|
#valid? ⇒ Boolean
165
166
167
|
# File 'lib/schematist/schema.rb', line 165
def valid?
self.class.valid?
end
|
#validate! ⇒ Object
161
162
163
|
# File 'lib/schematist/schema.rb', line 161
def validate!
self.class.validate!
end
|