-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
514 lines (459 loc) · 14.2 KB
/
Copy pathopenapi.yaml
File metadata and controls
514 lines (459 loc) · 14.2 KB
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
openapi: 3.0.3
info:
title: Shrtn API
version: 0.8.0
description: |
REST API for the Shrtn browser extension.
Shrtn validates HTTP and HTTPS URLs, generates unique
seven-character short codes, stores links persistently in
PostgreSQL, redirects public short URLs, and exposes click analytics.
servers:
- url: https://shrtn.up.railway.app
description: Production Railway server
- url: http://localhost:5056
description: Local development server
tags:
- name: Health
description: Service availability endpoints
- name: Links
description: Short-link creation and redirect endpoints
- name: Analytics
description: Short-link click analytics endpoints
paths:
/health:
get:
tags:
- Health
summary: Get API health
operationId: getHealth
responses:
"200":
description: The Shrtn API is running
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
example:
status: UP
service: shrtn-api
version: 0.8.0
timestamp: "2026-07-15T02:25:00.000Z"
/api/v1/links:
post:
tags:
- Links
summary: Create a shortened URL
description: |
Validates an HTTP or HTTPS URL, generates a unique
seven-character short code, and stores the link persistently
in PostgreSQL.
operationId: createShortLink
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateLinkRequest"
examples:
standardUrl:
summary: Standard HTTPS URL
value:
originalUrl: https://example.com/products?id=123
localDevelopmentUrl:
summary: Local development URL
value:
originalUrl: http://localhost:5173
responses:
"201":
description: Short link created successfully
headers:
Location:
description: Complete shortened URL
schema:
type: string
format: uri
example: https://shrtn.up.railway.app/AbC123x
content:
application/json:
schema:
$ref: "#/components/schemas/LinkResponse"
example:
data:
originalUrl: https://example.com/products?id=123
shortCode: AbC123x
shortUrl: https://shrtn.up.railway.app/AbC123x
createdAt: "2026-07-15T02:25:00.000Z"
"400":
description: Request validation or JSON parsing failed
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
examples:
requiredUrl:
summary: Missing URL
value:
error:
code: VALIDATION_ERROR
message: Request validation failed.
details:
- field: originalUrl
message: originalUrl is required.
invalidUrl:
summary: Invalid URL
value:
error:
code: VALIDATION_ERROR
message: Request validation failed.
details:
- field: originalUrl
message: originalUrl must be a valid URL.
unsupportedProtocol:
summary: Unsupported URL protocol
value:
error:
code: VALIDATION_ERROR
message: Request validation failed.
details:
- field: originalUrl
message: Only HTTP and HTTPS URLs are supported.
invalidJson:
summary: Malformed JSON
value:
error:
code: INVALID_JSON
message: The request body contains invalid JSON.
"409":
description: A unique short code could not be generated
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: SHORT_CODE_CONFLICT
message: A unique short code could not be generated.
"413":
description: Request body exceeds the 10 KB limit
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: REQUEST_TOO_LARGE
message: The request body is too large.
"429":
description: The client exceeded the request rate limit
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: RATE_LIMIT_EXCEEDED
message: Too many requests. Please try again later.
"500":
description: Unexpected server failure
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: INTERNAL_SERVER_ERROR
message: An unexpected server error occurred.
/api/v1/links/{shortCode}/analytics:
get:
tags:
- Analytics
summary: Get analytics for a shortened link
description: |
Returns the stored destination, creation timestamp, total
redirect count, and most recent redirect timestamp.
Reading analytics does not increment the click count.
operationId: getLinkAnalytics
parameters:
- $ref: "#/components/parameters/ShortCode"
responses:
"200":
description: Link analytics retrieved successfully
content:
application/json:
schema:
$ref: "#/components/schemas/LinkAnalyticsResponse"
example:
data:
originalUrl: https://example.com/products?id=123
shortCode: AbC123x
createdAt: "2026-07-15T02:25:00.000Z"
clickCount: 3
lastClickedAt: "2026-07-15T03:10:00.000Z"
"404":
description: The short link does not exist or the route format is invalid
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
examples:
linkNotFound:
summary: Valid code with no stored record
value:
error:
code: LINK_NOT_FOUND
message: The requested short link does not exist.
invalidCodeFormat:
summary: Invalid short-code format
value:
error:
code: ROUTE_NOT_FOUND
message: Route GET /api/v1/links/not-valid/analytics does not exist.
"429":
description: The client exceeded the request rate limit
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: RATE_LIMIT_EXCEEDED
message: Too many requests. Please try again later.
"500":
description: Unexpected server failure
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: INTERNAL_SERVER_ERROR
message: An unexpected server error occurred.
/{shortCode}:
get:
tags:
- Links
summary: Redirect a short link
description: |
Finds a persistent PostgreSQL link using its seven-character
short code, atomically records the redirect analytics, and
redirects the client to the original URL.
operationId: redirectShortLink
parameters:
- $ref: "#/components/parameters/ShortCode"
responses:
"302":
description: Redirect to the original URL
headers:
Location:
description: Original URL associated with the short code
schema:
type: string
format: uri
example: https://example.com/products?id=123
"404":
description: The short link does not exist or the route format is invalid
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
examples:
linkNotFound:
summary: Valid code with no stored record
value:
error:
code: LINK_NOT_FOUND
message: The requested short link does not exist.
invalidCodeFormat:
summary: Invalid short-code format
value:
error:
code: ROUTE_NOT_FOUND
message: Route GET /not-valid does not exist.
"429":
description: The client exceeded the request rate limit
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: RATE_LIMIT_EXCEEDED
message: Too many requests. Please try again later.
"500":
description: Unexpected server failure
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorResponse"
example:
error:
code: INTERNAL_SERVER_ERROR
message: An unexpected server error occurred.
components:
parameters:
ShortCode:
name: shortCode
in: path
required: true
description: Seven-character alphanumeric Shrtn code
schema:
type: string
minLength: 7
maxLength: 7
pattern: "^[A-Za-z0-9]{7}$"
example: AbC123x
schemas:
HealthResponse:
type: object
additionalProperties: false
required:
- status
- service
- version
- timestamp
properties:
status:
type: string
enum:
- UP
example: UP
service:
type: string
enum:
- shrtn-api
example: shrtn-api
version:
type: string
example: 0.8.0
timestamp:
type: string
format: date-time
example: "2026-07-15T02:25:00.000Z"
CreateLinkRequest:
type: object
additionalProperties: false
required:
- originalUrl
properties:
originalUrl:
type: string
format: uri
minLength: 1
maxLength: 4096
description: HTTP or HTTPS URL to shorten
example: https://example.com/products?id=123
Link:
type: object
additionalProperties: false
required:
- originalUrl
- shortCode
- shortUrl
- createdAt
properties:
originalUrl:
type: string
format: uri
example: https://example.com/products?id=123
shortCode:
type: string
minLength: 7
maxLength: 7
pattern: "^[A-Za-z0-9]{7}$"
example: AbC123x
shortUrl:
type: string
format: uri
example: https://shrtn.up.railway.app/AbC123x
createdAt:
type: string
format: date-time
example: "2026-07-15T02:25:00.000Z"
LinkResponse:
type: object
additionalProperties: false
required:
- data
properties:
data:
$ref: "#/components/schemas/Link"
LinkAnalytics:
type: object
additionalProperties: false
required:
- originalUrl
- shortCode
- createdAt
- clickCount
- lastClickedAt
properties:
originalUrl:
type: string
format: uri
example: https://example.com/products?id=123
shortCode:
type: string
minLength: 7
maxLength: 7
pattern: "^[A-Za-z0-9]{7}$"
example: AbC123x
createdAt:
type: string
format: date-time
example: "2026-07-15T02:25:00.000Z"
clickCount:
type: integer
format: int64
minimum: 0
example: 3
lastClickedAt:
type: string
format: date-time
nullable: true
example: "2026-07-15T03:10:00.000Z"
LinkAnalyticsResponse:
type: object
additionalProperties: false
required:
- data
properties:
data:
$ref: "#/components/schemas/LinkAnalytics"
ErrorDetail:
type: object
additionalProperties: false
required:
- field
- message
properties:
field:
type: string
example: originalUrl
message:
type: string
example: originalUrl must be a valid URL.
Error:
type: object
additionalProperties: false
required:
- code
- message
properties:
code:
type: string
example: VALIDATION_ERROR
message:
type: string
example: Request validation failed.
details:
type: array
items:
$ref: "#/components/schemas/ErrorDetail"
ErrorResponse:
type: object
additionalProperties: false
required:
- error
properties:
error:
$ref: "#/components/schemas/Error"