18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/jsonapi_swagger_helpers/schema_helpers.rb', line 18
def self.relationships_schema
lambda do |relationships|
property :relationships do
key :type, :object
relationships.each_pair do |relation_name, opts|
property relation_name do
property :data do
if opts[:array]
key :type, :array
items do
if opts[:id]
property :id do
key :type, :string
end
end
property :type do
key :type, :string
key :required, true
key :enum, [opts[:jsonapi_type]]
end
if opts[:attributes]
instance_exec(opts[:attributes], &SchemaHelpers.attributes_schema)
end
if opts[:relationships]
instance_exec(opts[:relationships], &SchemaHelpers.relationships_schema)
end
end
else
if opts[:id]
property :id do
key :type, :string
end
end
property :type do
key :type, :string
key :required, true
key :enum, [opts[:jsonapi_type]]
end
if opts[:attributes]
instance_exec(opts[:attributes], &SchemaHelpers.attributes_schema)
end
if opts[:relationships]
instance_exec(opts[:relationships], &SchemaHelpers.relationships_schema)
end
end
end
end
end
end
end
end
|