-
Notifications
You must be signed in to change notification settings - Fork 104
/
person_schema.rb
80 lines (73 loc) · 1.86 KB
/
person_schema.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
76
77
78
79
80
# frozen_string_literal: true
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.
class JsonApi::PersonSchema
def self.read
self.new.data
end
def data
{ type: :object,
properties: {
data: {
type: :object,
properties: {
id: { type: :string, description: 'ID'},
type: { type: :string, enum: ['people'], default: 'people'},
attributes: attributes,
relationships: relationships
}
},
included: included
}
}
end
def attributes
{ type: :object,
properties: {
first_name: { type: :string },
last_name: { type: :string }
},
description: 'Person attributes' }
end
def relationships
{ type: :object,
properties: {
phone_numbers: {
type: :object,
properties: {
data: {
type: :array,
items: {
type: :object,
properties: {
type: { type: :string, enum: [:phone_numbers], default: :phone_numbers },
id: { type: :string },
method: { type: :string, enum: [:update], default: :update },
}
}
}
}
}
}
}
end
def included
{ type: :array,
items: {
type: :object,
properties: {
type: { type: :string, enum: [:phone_numbers], default: :phone_numbers },
id: { type: :string },
attributes: {
type: :object,
properties: {
number: { type: :string }
}
}
}
}
}
end
end