-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
api-spec.yml
473 lines (459 loc) · 14.3 KB
/
api-spec.yml
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
openapi: 3.0.3
info:
title: BloomLibrary API
version: "1.0"
servers:
- url: https://api.bloomlibrary.org/v1
components:
parameters:
PathId:
name: id
in: path
required: true
schema:
type: string
PathTag:
name: tag
in: path
required: true
schema:
type: string
HeaderAuthToken:
name: Authentication-Token
in: header
required: true
schema:
type: string
Lang:
description: comma-separated list of BCP 47 language tags
name: lang
in: query
required: false
schema:
type: string
Uploader:
description: comma-separated list of email addresses
name: uploader
in: query
required: false
schema:
type: string
Environment:
name: env
in: query
required: false
schema:
type: string
enum:
- dev
- prod
- unittest
Limit:
name: limit
in: query
description: Number of items to retrieve
required: false
schema:
type: integer
minimum: 0 # set to 0, for example, if you only want the count
maximum: 100 #REVIEW: is this a good max?
Offset: # not implemented yet
name: offset
in: query
description: Number of items to skip
required: false
schema:
type: integer
minimum: 0
Count:
name: count
in: query
description: If true, the result will also contain the count of items
required: false
schema:
type: boolean
Expand:
name: expand
in: query
description: A comma-separated list of fields for which to include the full record
required: false
schema:
type: string
schemas:
Book:
type: object
properties:
id:
type: string
languages:
type: array
items:
$ref: "#/components/schemas/Language"
titles:
type: array
items:
type: object
properties:
lang:
type: string
title:
type: string
required: [lang, title]
uploader:
type: object
properties:
email:
type: string
id:
type: string
required: [email]
# editor uses these, but we don't necessarily want them as part of the public shape
instanceId:
type: string
format: uuid
titleFromUpload:
type: string
baseUrl:
type: string
format: uri
updatedAt:
type: string
format: date-time
createdAt:
type: string
format: date-time
draft:
type: boolean
nullable: true
harvestState:
type: string
brandingProjectName:
type: string
inCirculation:
type: boolean
nullable: true
phashOfFirstContentImage:
type: string
bookLineage:
type: string
# links:
# type: string
# format: uri
required: [id]
example:
id: 123
languages: [{ "tag": "en" }, { "tag": "fr" }]
titles:
- lang: en
title: Moon & Cap
- lang: fr
title: La lune et le Cap
uploader:
email: [email protected]
# links: https://api.bloomlibrary.org/books/123/links
Language:
type: object
properties:
id:
description: Unique ID for the language record. Unfortunately, tag is not unique.
type: string
tag:
description: BCP 47 language tag
type: string
name:
type: string
englishName:
type: string
usageCount:
type: integer
required: [tag]
LongRunningOperationCommonResult:
type: object
properties:
id: # the operation ID; used to query for status
type: string
status:
type: string
enum:
- Succeeded
- Running
- Failed
- NotStarted
LongRunningOperationSucceededResult:
allOf:
- $ref: "#/components/schemas/LongRunningOperationCommonResult"
- type: object
properties:
result:
oneOf:
- $ref: "#/components/schemas/UploadStartResult"
- $ref: "#/components/schemas/UploadFinishResult"
LongRunningOperationFailedResult:
allOf:
- $ref: "#/components/schemas/LongRunningOperationCommonResult"
- type: object
properties:
error:
type: object
properties:
code:
type: string
message:
type: string
LongRunningOperationOtherResult:
$ref: "#/components/schemas/LongRunningOperationCommonResult"
UploadStartResult:
type: object
properties:
transactionId:
type: string
credentials:
type: object
properties:
AccessKeyId:
type: string
SecretAccessKey:
type: string
SessionToken:
type: string
url:
type: string
format: uri
filesToUpload:
type: array
items:
type: string
UploadFinishResult:
type: object
responses:
BookArray:
description: OK
content:
application/json:
schema:
type: object
properties:
results:
type: array
items:
$ref: "#/components/schemas/Book"
count:
type: integer
AcceptedWithOperationLocation:
description: Accepted
headers:
Operation-Location:
description: URL to check the status of the operation
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/LongRunningOperationCommonResult"
paths:
/books:
get: # 5.7 editor uses to get book count in language: /books?lang=xyz&limit=0&count=true
description: returns an array of books with metadata (and links?)
parameters:
- $ref: "#/components/parameters/Lang"
- $ref: "#/components/parameters/Uploader"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Offset"
- $ref: "#/components/parameters/Count"
- $ref: "#/components/parameters/Expand"
- $ref: "#/components/parameters/Environment"
responses:
200:
$ref: "#/components/responses/BookArray"
# When we get a POST rather than a GET,
# it indicates we must look in the body for
# which books to return.
# Reasoning: the url has a length limit which we avoid by using the body.
# Currently, we need this for bookInstanceIds.
post: # 5.7 editor uses to get blorg badge statuses
description: returns an array of books with metadata
parameters:
- $ref: "#/components/parameters/Lang"
- $ref: "#/components/parameters/Uploader"
- $ref: "#/components/parameters/Environment"
requestBody:
description: array of book instance IDs
required: true
content:
application/json:
schema:
type: object
properties:
instanceIds:
description: A book "instance ID" is a guid found in meta.json; it was designed to be unique but we couldn't keep people from copying using file explorer, so it is not actually unique. It serves as a unique identifier for a book in a particular collection within the editor. In contrast, the "book ID" is the database ID and it is unique.
type: array
items:
type: string
responses:
200:
$ref: "#/components/responses/BookArray"
/books/{id}: # needed by 5.7 editor conflict dialog and SP App team
get:
description: Get metadata for a specific book
parameters:
- $ref: "#/components/parameters/PathId"
- $ref: "#/components/parameters/Expand"
- $ref: "#/components/parameters/Environment"
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Book"
delete: # needed for next round of blorg changes
description: Delete a book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
responses:
204:
description: No Content
# Gets its own endpoint because it is expensive.
# i.e. we don't want to just return it with each book record.
# Some day, we may have a /books:permissions for collection-level permissions.
# But in Feb 2024, I could not figure out how to define the route in functions.json
# to achieve that along with handling /books /books/{id}.
# To do this, we may have to define a new function with /books{collection-action}.
/books/{id}:permissions: # needed for next round of changes
get:
description: returns whether the user may edit the book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
responses:
200:
description: OK
content:
application/json:
schema:
type: object
properties:
reupload:
type: boolean
delete:
type: boolean
editSurfaceMetadata:
type: boolean
editAllMetadata:
type: boolean
becomeUploader:
type: boolean
# not needed yet (since we have the expanded form from /books)
/languages/{tag}:
get:
description: returns the language name
parameters:
- $ref: "#/components/parameters/PathTag"
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Language"
/books/{id}:upload-start: # 5.7 editor uses
post:
description: Initiate upload or reupload of a book. id is "new" if creating a new book. Otherwise, it is the existing book ID.
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
files:
description: Array of relative file paths and their corresponding hashes
type: array
items:
type: object
properties:
path:
type: string
hash:
type: string
name:
description: Any file-system-safe name. Bloom editor uses the folder name. This may become part of the S3 key (and currently does).
type: string
clientName:
description: Name of the client. For Bloom editor, this includes the channel. This may be used to disallow certain channels from uploading, etc.
type: string
clientVersion:
description: Version of the client. This may be used to disallow certain versions from uploading, etc.
type: string
required:
- files
- clientName
- clientVersion
responses:
202:
$ref: "#/components/responses/AcceptedWithOperationLocation"
/books/{id}:upload-finish: # 5.7 editor uses
post:
description: Finalize uploading a book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
requestBody:
description: The transaction ID
required: true
content:
application/json:
schema:
type: object
properties:
transactionId:
type: string
metadata:
type: object
becomeUploader:
description: If true, the book record will be updated to show that the user is now the uploader.
type: boolean
required:
- transactionId
- metadata
responses:
202:
$ref: "#/components/responses/AcceptedWithOperationLocation"
# status is used for long-running operations to check their progress.
# When the job is complete, it returns status:Succeeded and the actual result.
/status/{operation-id}: # 5.7 editor uses
get:
description: returns the status (and result if complete) of a long-running operation
parameters:
- name: operation-id
in: path
description: The operation ID
required: true
schema:
type: string
responses:
200:
description: OK
headers:
Retry-After:
description: Seconds to wait before retrying
schema:
type: integer
content:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/LongRunningOperationSucceededResult"
- $ref: "#/components/schemas/LongRunningOperationFailedResult"
- $ref: "#/components/schemas/LongRunningOperationOtherResult"
discriminator:
propertyName: status
mapping:
Succeeded: "#/components/schemas/LongRunningOperationSucceededResult"
Failed: "#/components/schemas/LongRunningOperationFailedResult"
Running: "#/components/schemas/LongRunningOperationOtherResult"
NotStarted: "#/components/schemas/LongRunningOperationOtherResult"