@xyd-js/openapi 0.1.0-xyd.4 → 0.1.0-xyd.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +410 -0
  2. package/LICENSE +21 -0
  3. package/__fixtures__/-2.complex.openai/input.yaml +39848 -0
  4. package/__fixtures__/-2.complex.openai/output.json +321646 -0
  5. package/__fixtures__/-2.complex.openai/pluginOasOpenai.ts +553 -0
  6. package/__fixtures__/1.basic/input.yaml +226 -0
  7. package/__fixtures__/1.basic/output.json +1919 -0
  8. package/__fixtures__/2.more/input.yaml +76 -0
  9. package/__fixtures__/2.more/output.json +292 -0
  10. package/__fixtures__/3.multiple-responses/input.yaml +48 -0
  11. package/__fixtures__/3.multiple-responses/output.json +266 -0
  12. package/__fixtures__/4.abc/input.yaml +639 -0
  13. package/__fixtures__/4.abc/output.json +3828 -0
  14. package/__fixtures__/5.xdocs.codeLanguages/input.yaml +231 -0
  15. package/__fixtures__/5.xdocs.codeLanguages/output.json +1879 -0
  16. package/__fixtures__/5.xdocs.sidebar/input.yaml +256 -0
  17. package/__fixtures__/5.xdocs.sidebar/output.json +843 -0
  18. package/__fixtures__/6.codeSamples/input.yaml +75 -0
  19. package/__fixtures__/6.codeSamples/output.json +293 -0
  20. package/__tests__/oapSchemaToReferences.test.ts +88 -0
  21. package/__tests__/utils.ts +81 -0
  22. package/dist/index.cjs +1860 -163
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +36 -4
  25. package/dist/index.d.ts +36 -4
  26. package/dist/index.js +1856 -156
  27. package/dist/index.js.map +1 -1
  28. package/examples/basic/index2.ts +2 -2
  29. package/index.ts +10 -2
  30. package/package.json +11 -7
  31. package/src/const.ts +5 -1
  32. package/src/converters/oas-componentSchemas.ts +205 -0
  33. package/src/converters/oas-examples.ts +417 -0
  34. package/src/{parameters.ts → converters/oas-parameters.ts} +17 -3
  35. package/src/converters/oas-paths.ts +354 -0
  36. package/src/{requestBody.ts → converters/oas-requestBody.ts} +30 -10
  37. package/src/converters/oas-responses.ts +76 -0
  38. package/src/converters/oas-schema.ts +141 -0
  39. package/src/index.ts +13 -5
  40. package/src/oas-core.ts +579 -0
  41. package/src/types.ts +18 -0
  42. package/src/utils.ts +103 -89
  43. package/src/xdocs/index.ts +18 -0
  44. package/src/xdocs/pluginSidebar.ts +580 -0
  45. package/src/xdocs/types.ts +26 -0
  46. package/vitest.config.ts +7 -0
  47. package/src/examples.ts +0 -116
  48. package/src/paths.ts +0 -103
  49. package/src/properties.ts +0 -37
  50. package/src/responses.ts +0 -38
  51. package/src/schema.ts +0 -62
@@ -0,0 +1,639 @@
1
+ {
2
+ "openapi": "3.0.3",
3
+ "info": {
4
+ "title": "Starter API",
5
+ "description": "A sample API specification for the starter project",
6
+ "version": "1.0.0",
7
+ "contact": {
8
+ "name": "API Support",
9
+ "email": "support@example.com"
10
+ },
11
+ "license": {
12
+ "name": "MIT",
13
+ "url": "https://opensource.org/licenses/MIT"
14
+ }
15
+ },
16
+ "servers": [
17
+ {
18
+ "url": "https://api.example.com/v1",
19
+ "description": "Production server"
20
+ },
21
+ {
22
+ "url": "https://staging-api.example.com/v1",
23
+ "description": "Staging server"
24
+ },
25
+ {
26
+ "url": "http://localhost:3000/v1",
27
+ "description": "Local development server"
28
+ }
29
+ ],
30
+ "paths": {
31
+ "/users": {
32
+ "get": {
33
+ "summary": "List users",
34
+ "description": "Retrieve a list of users with optional filtering and pagination",
35
+ "operationId": "getUsers",
36
+ "tags": ["Users"],
37
+ "parameters": [
38
+ {
39
+ "name": "page",
40
+ "in": "query",
41
+ "description": "Page number for pagination",
42
+ "required": false,
43
+ "schema": {
44
+ "type": "integer",
45
+ "minimum": 1,
46
+ "default": 1
47
+ }
48
+ },
49
+ {
50
+ "name": "limit",
51
+ "in": "query",
52
+ "description": "Number of items per page",
53
+ "required": false,
54
+ "schema": {
55
+ "type": "integer",
56
+ "minimum": 1,
57
+ "maximum": 100,
58
+ "default": 20
59
+ }
60
+ },
61
+ {
62
+ "name": "search",
63
+ "in": "query",
64
+ "description": "Search term for filtering users",
65
+ "required": false,
66
+ "schema": {
67
+ "type": "string"
68
+ }
69
+ }
70
+ ],
71
+ "responses": {
72
+ "200": {
73
+ "description": "Successful response",
74
+ "content": {
75
+ "application/json": {
76
+ "schema": {
77
+ "$ref": "#/components/schemas/UserList"
78
+ }
79
+ }
80
+ }
81
+ },
82
+ "400": {
83
+ "description": "Bad request",
84
+ "content": {
85
+ "application/json": {
86
+ "schema": {
87
+ "$ref": "#/components/schemas/Error"
88
+ }
89
+ }
90
+ }
91
+ },
92
+ "401": {
93
+ "description": "Unauthorized",
94
+ "content": {
95
+ "application/json": {
96
+ "schema": {
97
+ "$ref": "#/components/schemas/Error"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ },
104
+ "post": {
105
+ "summary": "Create user",
106
+ "description": "Create a new user",
107
+ "operationId": "createUser",
108
+ "tags": ["Users"],
109
+ "requestBody": {
110
+ "required": true,
111
+ "content": {
112
+ "application/json": {
113
+ "schema": {
114
+ "$ref": "#/components/schemas/CreateUserRequest"
115
+ }
116
+ }
117
+ }
118
+ },
119
+ "responses": {
120
+ "201": {
121
+ "description": "User created successfully",
122
+ "content": {
123
+ "application/json": {
124
+ "schema": {
125
+ "$ref": "#/components/schemas/User"
126
+ }
127
+ }
128
+ }
129
+ },
130
+ "400": {
131
+ "description": "Bad request",
132
+ "content": {
133
+ "application/json": {
134
+ "schema": {
135
+ "$ref": "#/components/schemas/Error"
136
+ }
137
+ }
138
+ }
139
+ },
140
+ "409": {
141
+ "description": "User already exists",
142
+ "content": {
143
+ "application/json": {
144
+ "schema": {
145
+ "$ref": "#/components/schemas/Error"
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ },
153
+ "/users/{userId}": {
154
+ "get": {
155
+ "summary": "Get user by ID",
156
+ "description": "Retrieve a specific user by their ID",
157
+ "operationId": "getUserById",
158
+ "tags": ["Users"],
159
+ "parameters": [
160
+ {
161
+ "name": "userId",
162
+ "in": "path",
163
+ "required": true,
164
+ "description": "The user ID",
165
+ "schema": {
166
+ "type": "string",
167
+ "format": "uuid"
168
+ }
169
+ }
170
+ ],
171
+ "responses": {
172
+ "200": {
173
+ "description": "Successful response",
174
+ "content": {
175
+ "application/json": {
176
+ "schema": {
177
+ "$ref": "#/components/schemas/User"
178
+ }
179
+ }
180
+ }
181
+ },
182
+ "404": {
183
+ "description": "User not found",
184
+ "content": {
185
+ "application/json": {
186
+ "schema": {
187
+ "$ref": "#/components/schemas/Error"
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ },
194
+ "put": {
195
+ "summary": "Update user",
196
+ "description": "Update an existing user",
197
+ "operationId": "updateUser",
198
+ "tags": ["Users"],
199
+ "parameters": [
200
+ {
201
+ "name": "userId",
202
+ "in": "path",
203
+ "required": true,
204
+ "description": "The user ID",
205
+ "schema": {
206
+ "type": "string",
207
+ "format": "uuid"
208
+ }
209
+ }
210
+ ],
211
+ "requestBody": {
212
+ "required": true,
213
+ "content": {
214
+ "application/json": {
215
+ "schema": {
216
+ "$ref": "#/components/schemas/UpdateUserRequest"
217
+ }
218
+ }
219
+ }
220
+ },
221
+ "responses": {
222
+ "200": {
223
+ "description": "User updated successfully",
224
+ "content": {
225
+ "application/json": {
226
+ "schema": {
227
+ "$ref": "#/components/schemas/User"
228
+ }
229
+ }
230
+ }
231
+ },
232
+ "404": {
233
+ "description": "User not found",
234
+ "content": {
235
+ "application/json": {
236
+ "schema": {
237
+ "$ref": "#/components/schemas/Error"
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
243
+ },
244
+ "delete": {
245
+ "summary": "Delete user",
246
+ "description": "Delete a user",
247
+ "operationId": "deleteUser",
248
+ "tags": ["Users"],
249
+ "parameters": [
250
+ {
251
+ "name": "userId",
252
+ "in": "path",
253
+ "required": true,
254
+ "description": "The user ID",
255
+ "schema": {
256
+ "type": "string",
257
+ "format": "uuid"
258
+ }
259
+ }
260
+ ],
261
+ "responses": {
262
+ "204": {
263
+ "description": "User deleted successfully"
264
+ },
265
+ "404": {
266
+ "description": "User not found",
267
+ "content": {
268
+ "application/json": {
269
+ "schema": {
270
+ "$ref": "#/components/schemas/Error"
271
+ }
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ },
278
+ "/auth/login": {
279
+ "post": {
280
+ "summary": "User login",
281
+ "description": "Authenticate a user and return access token",
282
+ "operationId": "login",
283
+ "tags": ["Authentication"],
284
+ "requestBody": {
285
+ "required": true,
286
+ "content": {
287
+ "application/json": {
288
+ "schema": {
289
+ "$ref": "#/components/schemas/LoginRequest"
290
+ }
291
+ }
292
+ }
293
+ },
294
+ "responses": {
295
+ "200": {
296
+ "description": "Login successful",
297
+ "content": {
298
+ "application/json": {
299
+ "schema": {
300
+ "$ref": "#/components/schemas/LoginResponse"
301
+ }
302
+ }
303
+ }
304
+ },
305
+ "401": {
306
+ "description": "Invalid credentials",
307
+ "content": {
308
+ "application/json": {
309
+ "schema": {
310
+ "$ref": "#/components/schemas/Error"
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+ },
318
+ "/auth/refresh": {
319
+ "post": {
320
+ "summary": "Refresh token",
321
+ "description": "Refresh an access token using a refresh token",
322
+ "operationId": "refreshToken",
323
+ "tags": ["Authentication"],
324
+ "requestBody": {
325
+ "required": true,
326
+ "content": {
327
+ "application/json": {
328
+ "schema": {
329
+ "$ref": "#/components/schemas/RefreshTokenRequest"
330
+ }
331
+ }
332
+ }
333
+ },
334
+ "responses": {
335
+ "200": {
336
+ "description": "Token refreshed successfully",
337
+ "content": {
338
+ "application/json": {
339
+ "schema": {
340
+ "$ref": "#/components/schemas/LoginResponse"
341
+ }
342
+ }
343
+ }
344
+ },
345
+ "401": {
346
+ "description": "Invalid refresh token",
347
+ "content": {
348
+ "application/json": {
349
+ "schema": {
350
+ "$ref": "#/components/schemas/Error"
351
+ }
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }
357
+ },
358
+ "/health": {
359
+ "get": {
360
+ "summary": "Health check",
361
+ "description": "Check the health status of the API",
362
+ "operationId": "healthCheck",
363
+ "tags": ["System"],
364
+ "responses": {
365
+ "200": {
366
+ "description": "API is healthy",
367
+ "content": {
368
+ "application/json": {
369
+ "schema": {
370
+ "$ref": "#/components/schemas/HealthResponse"
371
+ }
372
+ }
373
+ }
374
+ }
375
+ }
376
+ }
377
+ }
378
+ },
379
+ "components": {
380
+ "schemas": {
381
+ "User": {
382
+ "type": "object",
383
+ "properties": {
384
+ "id": {
385
+ "type": "string",
386
+ "format": "uuid",
387
+ "description": "Unique identifier for the user"
388
+ },
389
+ "email": {
390
+ "type": "string",
391
+ "format": "email",
392
+ "description": "User's email address"
393
+ },
394
+ "firstName": {
395
+ "type": "string",
396
+ "description": "User's first name"
397
+ },
398
+ "lastName": {
399
+ "type": "string",
400
+ "description": "User's last name"
401
+ },
402
+ "role": {
403
+ "type": "string",
404
+ "enum": ["user", "admin", "moderator"],
405
+ "description": "User's role in the system"
406
+ },
407
+ "isActive": {
408
+ "type": "boolean",
409
+ "description": "Whether the user account is active"
410
+ },
411
+ "createdAt": {
412
+ "type": "string",
413
+ "format": "date-time",
414
+ "description": "When the user was created"
415
+ },
416
+ "updatedAt": {
417
+ "type": "string",
418
+ "format": "date-time",
419
+ "description": "When the user was last updated"
420
+ }
421
+ },
422
+ "required": ["id", "email", "firstName", "lastName", "role", "isActive", "createdAt", "updatedAt"]
423
+ },
424
+ "CreateUserRequest": {
425
+ "type": "object",
426
+ "properties": {
427
+ "email": {
428
+ "type": "string",
429
+ "format": "email",
430
+ "description": "User's email address"
431
+ },
432
+ "password": {
433
+ "type": "string",
434
+ "minLength": 8,
435
+ "description": "User's password"
436
+ },
437
+ "firstName": {
438
+ "type": "string",
439
+ "minLength": 1,
440
+ "description": "User's first name"
441
+ },
442
+ "lastName": {
443
+ "type": "string",
444
+ "minLength": 1,
445
+ "description": "User's last name"
446
+ },
447
+ "role": {
448
+ "type": "string",
449
+ "enum": ["user", "admin", "moderator"],
450
+ "default": "user",
451
+ "description": "User's role in the system"
452
+ }
453
+ },
454
+ "required": ["email", "password", "firstName", "lastName"]
455
+ },
456
+ "UpdateUserRequest": {
457
+ "type": "object",
458
+ "properties": {
459
+ "firstName": {
460
+ "type": "string",
461
+ "minLength": 1,
462
+ "description": "User's first name"
463
+ },
464
+ "lastName": {
465
+ "type": "string",
466
+ "minLength": 1,
467
+ "description": "User's last name"
468
+ },
469
+ "role": {
470
+ "type": "string",
471
+ "enum": ["user", "admin", "moderator"],
472
+ "description": "User's role in the system"
473
+ },
474
+ "isActive": {
475
+ "type": "boolean",
476
+ "description": "Whether the user account is active"
477
+ }
478
+ }
479
+ },
480
+ "UserList": {
481
+ "type": "object",
482
+ "properties": {
483
+ "data": {
484
+ "type": "array",
485
+ "items": {
486
+ "$ref": "#/components/schemas/User"
487
+ }
488
+ },
489
+ "pagination": {
490
+ "$ref": "#/components/schemas/Pagination"
491
+ }
492
+ },
493
+ "required": ["data", "pagination"]
494
+ },
495
+ "Pagination": {
496
+ "type": "object",
497
+ "properties": {
498
+ "page": {
499
+ "type": "integer",
500
+ "description": "Current page number"
501
+ },
502
+ "limit": {
503
+ "type": "integer",
504
+ "description": "Number of items per page"
505
+ },
506
+ "total": {
507
+ "type": "integer",
508
+ "description": "Total number of items"
509
+ },
510
+ "totalPages": {
511
+ "type": "integer",
512
+ "description": "Total number of pages"
513
+ }
514
+ },
515
+ "required": ["page", "limit", "total", "totalPages"]
516
+ },
517
+ "LoginRequest": {
518
+ "type": "object",
519
+ "properties": {
520
+ "email": {
521
+ "type": "string",
522
+ "format": "email",
523
+ "description": "User's email address"
524
+ },
525
+ "password": {
526
+ "type": "string",
527
+ "description": "User's password"
528
+ }
529
+ },
530
+ "required": ["email", "password"]
531
+ },
532
+ "LoginResponse": {
533
+ "type": "object",
534
+ "properties": {
535
+ "accessToken": {
536
+ "type": "string",
537
+ "description": "JWT access token"
538
+ },
539
+ "refreshToken": {
540
+ "type": "string",
541
+ "description": "JWT refresh token"
542
+ },
543
+ "expiresIn": {
544
+ "type": "integer",
545
+ "description": "Token expiration time in seconds"
546
+ },
547
+ "user": {
548
+ "$ref": "#/components/schemas/User"
549
+ }
550
+ },
551
+ "required": ["accessToken", "refreshToken", "expiresIn", "user"]
552
+ },
553
+ "RefreshTokenRequest": {
554
+ "type": "object",
555
+ "properties": {
556
+ "refreshToken": {
557
+ "type": "string",
558
+ "description": "JWT refresh token"
559
+ }
560
+ },
561
+ "required": ["refreshToken"]
562
+ },
563
+ "HealthResponse": {
564
+ "type": "object",
565
+ "properties": {
566
+ "status": {
567
+ "type": "string",
568
+ "enum": ["healthy", "unhealthy"],
569
+ "description": "Overall health status"
570
+ },
571
+ "timestamp": {
572
+ "type": "string",
573
+ "format": "date-time",
574
+ "description": "When the health check was performed"
575
+ },
576
+ "version": {
577
+ "type": "string",
578
+ "description": "API version"
579
+ },
580
+ "uptime": {
581
+ "type": "number",
582
+ "description": "API uptime in seconds"
583
+ }
584
+ },
585
+ "required": ["status", "timestamp", "version", "uptime"]
586
+ },
587
+ "Error": {
588
+ "type": "object",
589
+ "properties": {
590
+ "error": {
591
+ "type": "string",
592
+ "description": "Error message"
593
+ },
594
+ "code": {
595
+ "type": "string",
596
+ "description": "Error code"
597
+ },
598
+ "details": {
599
+ "type": "object",
600
+ "description": "Additional error details"
601
+ },
602
+ "timestamp": {
603
+ "type": "string",
604
+ "format": "date-time",
605
+ "description": "When the error occurred"
606
+ }
607
+ },
608
+ "required": ["error", "code", "timestamp"]
609
+ }
610
+ },
611
+ "securitySchemes": {
612
+ "bearerAuth": {
613
+ "type": "http",
614
+ "scheme": "bearer",
615
+ "bearerFormat": "JWT",
616
+ "description": "JWT token for API authentication"
617
+ }
618
+ }
619
+ },
620
+ "security": [
621
+ {
622
+ "bearerAuth": []
623
+ }
624
+ ],
625
+ "tags": [
626
+ {
627
+ "name": "Users",
628
+ "description": "User management operations"
629
+ },
630
+ {
631
+ "name": "Authentication",
632
+ "description": "Authentication and authorization operations"
633
+ },
634
+ {
635
+ "name": "System",
636
+ "description": "System-level operations"
637
+ }
638
+ ]
639
+ }