summaryrefslogtreecommitdiffstats
path: root/contacts_validation/contacts_validation/data/contacts_schema.yaml
blob: 7431d066a757b30da987a0ff64b265058697cbbc (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# vim: set ts=2 sts=2 sw=2 :
$schema: http://json-schema.org/draft-07/schema#
title: contacts
description: schema of my personal contacts book
type: array
items:
  title: contact
  type: object
  additionalProperties: false
  required: [display, uuid]
  properties:

    #####################
    # required properties
    #####################

    display:
      description: contact name, displayed as is
      type: string

    uuid:
      description: unique identifier of the contact (ex. uuidgen command)
      type: string
      pattern: '^[\dabcdef]{8}-[\dabcdef]{4}-[\dabcdef]{4}-[\dabcdef]{4}-[\dabcdef]{12}$'

    #######################
    # additional properties
    #######################
    # note: I made the choice to have to explicitely put property names (like
    # phone: 'numberxxx' for phones) instead of having the possibility to
    # either have phones: ['numberxxx', {phone: 'numberyyy', otherprop:
    # xxx}]). It is a little less easier to write, but it is more clear when
    # manually reading a contact (and less confusing).

    firstname:
      $ref: '#/definitions/simple_strings'

    lastname:
      $ref: '#/definitions/simple_string'

    lastnamebm:
      title: last name (surname) before being married (birth last name)
      $ref: '#/definitions/simple_string'

    nickname:
      $ref: '#/definitions/simple_strings'

    title:
      $ref: '#/definitions/simple_string'

    comments:
      $ref: '#/definitions/comments'

    role:
      #$ref: '#/definitions/simple_string'
      type: string

    org:
      type: array
      items: {type: string}

    birthday:
      $ref: '#/definitions/datetime'

    birthday_ignore:
      description:
        ignore this birthday when generating calendar events (ex. with
        rem-generate-birthdays)
      type: boolean

    married:
      $ref: '#/definitions/datetime'

    favorite:
      description:
        use this contact as favorite, a special field in vcard format, used by
        phones supporting it
      type: boolean

    related:
      description: this contact is related to another pointed by this uri
      type: string
      format: uri

    kind:
      description: the kind of contact, or why this contact has been added
      type: string
      enum:
      - job # here because of job
      - com # here because it is a commercial contact of anything I use
      - friend # here because it is one of my friend, or friend of friend
      - family # here because it is part of my family
      - school # contact here because of the school

    urls:
      type: array
      items:
        description: a uri associated with the contact (ex. cv site)
        type: string
        format: uri

    notes:
      $ref: '#/definitions/simple_strings'

    websites:
      type: array
      items: {$ref: '#/definitions/website'}

    associations:
      type: array
      items: {$ref: '#/definitions/association'}

    emails:
      type: array
      items: {$ref: '#/definitions/email'}

    ims:
      title: instant messages addresses
      type: array
      items: {$ref: '#/definitions/im'}

    phones:
      type: array
      items: {$ref: '#/definitions/phone'}

    addresses:
      type: array
      items: {$ref: '#/definitions/address'}

    events:
      type: array
      items: {$ref: '#/definitions/event'}

    #imported:
    #  description: free form, used for the first time import of contact
    #  type: [array, object]


definitions:

  email:
    type: object
    additionalProperties: false
    required: [email]
    properties:
      email:
        type: string
        # limitation: a true e-mail address can contain multiple '@' symbols,
        # but I accept to not store them in my contacts.
        pattern: '^[^@]+@[^@]+$'
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  im:
    type: object
    additionalProperties: false
    required: [im]
    properties:
      im: {type: string, format: uri}
      type:
        type: string
        enum: [xmpp]
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  phone:
    type: object
    additionalProperties: false
    required: [phone]
    properties:
      phone:
        type: string
        pattern: '^\+[1-9]{2}\d{9}|[1-9]\d{2}|[1-9]\d{4}$'
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  website:
    type: object
    additionalProperties: false
    required: [website]
    properties:
      website: {type: string, format: uri}
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  address:
    type: object
    additionalProperties: false
    required: [street, code, city, country]
    properties:
      label: {$ref: '#/definitions/simple_string'}
      street:
        type: string
        pattern: "^[\\w' .-]+$"
      code:
        type: [string, number]
        $ref: '#/definitions/simple_string_pattern'
      city: {type: string, pattern: "^[\\w' ,-]+$"}
      country: {$ref: '#/definitions/simple_string'}
      box:
        type: [string, number]
        $ref: '#/definitions/simple_string_pattern'
      extended: {$ref: '#/definitions/simple_string'}
      region: {$ref: '#/definitions/simple_string'}

      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  association:
    type: object
    additionalProperties: false
    required: [association]
    properties:
      association: {$ref: '#/definitions/simple_string'}
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}

  event:
    description:
      any date of importance for this contact (assume 1 day if duration or end
      date not given)
    type: object
    additionalProperties: false
    # oneOf below define until and duration as mutually exclusive, see
    # https://stackoverflow.com/questions/28162509/mutually-exclusive-property-groups
    # for details
    oneOf:
    - {required: [event, date], not: {anyOf: [{required: [until]}, {required: [duration]}]}}
    - {required: [event, date, until], not: {required: [duration]}}
    - {required: [event, date, duration], not: {required: [until]}}
    properties:
      event: {type: string, description: description of the event}
      date: {$ref: '#/definitions/datetime'}
      comments: {$ref: '#/definitions/comments'}
      tags: {$ref: '#/definitions/tags'}
      until:
        description:
          the event was on-going until this date, mutually exclusive with
          duration
        $ref: '#/definition/datetime'
      duration:
        type: number
        minimum: 1
        multipleOf: 1 # force to be an integer
        default: 1
        description:
          duration of the event expressed in days, mutually exclusive with
          until

  comments:
    type: string
    description:
      free form comments (in plural even though being a single block of text
      since the text often contains multiple comments)

  tags:
    type: array
    uniqueItems: true
    items:
      type: string
      title: tags
      description: possible tags list
      # note: not sure if I keep the enum
      enum:
      - main
      - wired
      - phone
      - private # a private phone, not for work, not for professional
      - home # a phone shared for all person residing in the same house
      - mobile # a mobile/cell phone
      - old
      - box
      - short
      - voicemail
      - voice
      - work # a phone number dedicated for work, professional use
      - parents
      - down
      - gateway
      - maybe_invalid
      - school
      - uk
      - fax

  strings:
    description: validate a string or list of strings, no pattern restriction
    type: [string, array]
    items:
      type: string

  simple_string_pattern:
    description:
      validate a simple string, simple means they contains alphanumeric and
      space and dash and simple quote characters only
    pattern: "^[\\w' -]+$"

  simple_string:
    type: string
    $ref: '#/definitions/simple_string_pattern'

  simple_strings:
    description:
      validate a simple string or list of simple strings
    type: [string, array]
    $ref: '#/definitions/simple_string_pattern'
    items:
      type: string
      pattern: '#/definitions/simple_string_pattern'

  datetime:
    type: string
    description: matches a date in the form YYYY-MM-DD
    pattern: '^\d{4}-\d{2}-\d{2}$'