@xyd-js/openapi 0.1.0-xyd.5 → 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 +404 -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,76 @@
1
+ openapi: 3.0.0
2
+ paths:
3
+ /users:
4
+ get:
5
+ summary: Returns a list of users
6
+ description: Optional extended description in CommonMark or HTML.
7
+ responses:
8
+ '200':
9
+ description: A JSON array of users
10
+ content:
11
+ application/json:
12
+ schema:
13
+ # Response
14
+ # $ref: '#/components/schemas/User'
15
+ # Response & User
16
+ # allOf:
17
+ # - $ref: '#/components/schemas/Response'
18
+ # - $ref: '#/components/schemas/User'
19
+ # # Response | User
20
+ # anyOf:
21
+ # - $ref: '#/components/schemas/Response'
22
+ # - $ref: '#/components/schemas/User'
23
+ # # Response ^ User
24
+ # oneOf:
25
+ # - $ref: '#/components/schemas/Response'
26
+ # - $ref: '#/components/schemas/User'
27
+
28
+
29
+ type: array
30
+ items:
31
+ # Response
32
+ # $ref: '#/components/schemas/User'
33
+ # # Response & User
34
+ allOf:
35
+ - $ref: '#/components/schemas/Response'
36
+ - $ref: '#/components/schemas/User'
37
+ # # Response | User
38
+ # anyOf:
39
+ # - $ref: '#/components/schemas/Response'
40
+ # - $ref: '#/components/schemas/User'
41
+ # # Response ^ User
42
+ # oneOf:
43
+ # - $ref: '#/components/schemas/Response'
44
+ # - $ref: '#/components/schemas/User'
45
+
46
+ components:
47
+ schemas:
48
+ Response:
49
+ type: object
50
+ title: "Hello Response"
51
+ properties:
52
+ message:
53
+ type: string
54
+ User:
55
+ type: object
56
+ required:
57
+ - id
58
+ - username
59
+ properties:
60
+ id:
61
+ type: integer
62
+ format: int64
63
+ username:
64
+ type: string
65
+ email:
66
+ type: string
67
+ format: email
68
+ status:
69
+ type: string
70
+ enum: [ active, inactive ]
71
+ createdAt:
72
+ type: string
73
+ format: date-time
74
+ updatedAt:
75
+ type: string
76
+ format: date-time
@@ -0,0 +1,292 @@
1
+ [
2
+ {
3
+ "title": "Returns a list of users",
4
+ "canonical": "returns-a-list-of-users",
5
+ "description": "Optional extended description in CommonMark or HTML.",
6
+ "type": "rest_get",
7
+ "category": "rest",
8
+ "context": {
9
+ "method": "get",
10
+ "path": "/users",
11
+ "fullPath": "/users",
12
+ "group": [
13
+ ""
14
+ ],
15
+ "scopes": []
16
+ },
17
+ "examples": {
18
+ "groups": [
19
+ {
20
+ "description": "Example request",
21
+ "examples": [
22
+ {
23
+ "codeblock": {
24
+ "tabs": [
25
+ {
26
+ "title": "shell",
27
+ "language": "shell",
28
+ "code": "curl --request GET \\\n --url https://example.com/users \\\n --header 'accept: application/json'"
29
+ },
30
+ {
31
+ "title": "javascript",
32
+ "language": "javascript",
33
+ "code": "const options = {method: 'GET', headers: {accept: 'application/json'}};\n\nfetch('https://example.com/users', options)\n .then(res => res.json())\n .then(res => console.log(res))\n .catch(err => console.error(err));"
34
+ },
35
+ {
36
+ "title": "python",
37
+ "language": "python",
38
+ "code": "import requests\n\nurl = \"https://example.com/users\"\n\nheaders = {\"accept\": \"application/json\"}\n\nresponse = requests.get(url, headers=headers)\n\nprint(response.text)"
39
+ },
40
+ {
41
+ "title": "go",
42
+ "language": "go",
43
+ "code": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com/users\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"accept\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}"
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "description": "Example response",
52
+ "examples": [
53
+ {
54
+ "codeblock": {
55
+ "title": "200",
56
+ "tabs": [
57
+ {
58
+ "title": "json",
59
+ "language": "json",
60
+ "code": "[\n {\n \"message\": \"string\",\n \"id\": 0,\n \"username\": \"string\",\n \"email\": \"user@example.com\",\n \"status\": \"active\",\n \"createdAt\": \"2019-08-24T14:15:22Z\",\n \"updatedAt\": \"2019-08-24T14:15:22Z\"\n }\n]"
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ },
69
+ "definitions": [
70
+ {
71
+ "title": "Response",
72
+ "variants": [
73
+ {
74
+ "title": "200",
75
+ "description": "A JSON array of users",
76
+ "properties": [],
77
+ "rootProperty": {
78
+ "type": "$$array",
79
+ "properties": [
80
+ {
81
+ "name": "message",
82
+ "type": "string",
83
+ "description": "",
84
+ "meta": []
85
+ },
86
+ {
87
+ "name": "id",
88
+ "type": "integer",
89
+ "description": "",
90
+ "meta": [
91
+ {
92
+ "name": "required",
93
+ "value": "true"
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "name": "username",
99
+ "type": "string",
100
+ "description": "",
101
+ "meta": [
102
+ {
103
+ "name": "required",
104
+ "value": "true"
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "name": "email",
110
+ "type": "string",
111
+ "description": "",
112
+ "meta": []
113
+ },
114
+ {
115
+ "name": "status",
116
+ "type": "string",
117
+ "description": "",
118
+ "meta": [
119
+ {
120
+ "name": "enum",
121
+ "value": "true"
122
+ }
123
+ ],
124
+ "properties": [
125
+ {
126
+ "name": "active",
127
+ "type": "string",
128
+ "description": "",
129
+ "meta": []
130
+ },
131
+ {
132
+ "name": "inactive",
133
+ "type": "string",
134
+ "description": "",
135
+ "meta": []
136
+ }
137
+ ]
138
+ },
139
+ {
140
+ "name": "createdAt",
141
+ "type": "string",
142
+ "description": "",
143
+ "meta": []
144
+ },
145
+ {
146
+ "name": "updatedAt",
147
+ "type": "string",
148
+ "description": "",
149
+ "meta": []
150
+ }
151
+ ]
152
+ },
153
+ "meta": [
154
+ {
155
+ "name": "status",
156
+ "value": "200"
157
+ },
158
+ {
159
+ "name": "contentType",
160
+ "value": "application/json"
161
+ }
162
+ ],
163
+ "symbolDef": {
164
+ "id": [
165
+ "#/components/schemas/Response",
166
+ "#/components/schemas/User"
167
+ ]
168
+ }
169
+ }
170
+ ],
171
+ "properties": []
172
+ }
173
+ ]
174
+ },
175
+ {
176
+ "title": "Response",
177
+ "description": "",
178
+ "canonical": "objects/Response",
179
+ "definitions": [
180
+ {
181
+ "title": "Response",
182
+ "properties": [
183
+ {
184
+ "name": "message",
185
+ "type": "string",
186
+ "description": "",
187
+ "meta": []
188
+ }
189
+ ],
190
+ "meta": []
191
+ }
192
+ ],
193
+ "examples": {
194
+ "groups": []
195
+ },
196
+ "type": "rest_component_schema",
197
+ "context": {
198
+ "componentSchema": "Response",
199
+ "group": [
200
+ "Objects"
201
+ ]
202
+ }
203
+ },
204
+ {
205
+ "title": "User",
206
+ "description": "",
207
+ "canonical": "objects/User",
208
+ "definitions": [
209
+ {
210
+ "title": "User",
211
+ "properties": [
212
+ {
213
+ "name": "id",
214
+ "type": "integer",
215
+ "description": "",
216
+ "meta": [
217
+ {
218
+ "name": "required",
219
+ "value": "true"
220
+ }
221
+ ]
222
+ },
223
+ {
224
+ "name": "username",
225
+ "type": "string",
226
+ "description": "",
227
+ "meta": [
228
+ {
229
+ "name": "required",
230
+ "value": "true"
231
+ }
232
+ ]
233
+ },
234
+ {
235
+ "name": "email",
236
+ "type": "string",
237
+ "description": "",
238
+ "meta": []
239
+ },
240
+ {
241
+ "name": "status",
242
+ "type": "string",
243
+ "description": "",
244
+ "meta": [
245
+ {
246
+ "name": "enum",
247
+ "value": "true"
248
+ }
249
+ ],
250
+ "properties": [
251
+ {
252
+ "name": "active",
253
+ "type": "string",
254
+ "description": "",
255
+ "meta": []
256
+ },
257
+ {
258
+ "name": "inactive",
259
+ "type": "string",
260
+ "description": "",
261
+ "meta": []
262
+ }
263
+ ]
264
+ },
265
+ {
266
+ "name": "createdAt",
267
+ "type": "string",
268
+ "description": "",
269
+ "meta": []
270
+ },
271
+ {
272
+ "name": "updatedAt",
273
+ "type": "string",
274
+ "description": "",
275
+ "meta": []
276
+ }
277
+ ],
278
+ "meta": []
279
+ }
280
+ ],
281
+ "examples": {
282
+ "groups": []
283
+ },
284
+ "type": "rest_component_schema",
285
+ "context": {
286
+ "componentSchema": "User",
287
+ "group": [
288
+ "Objects"
289
+ ]
290
+ }
291
+ }
292
+ ]
@@ -0,0 +1,48 @@
1
+ openapi: 3.0.0
2
+ paths:
3
+ /response:
4
+ get:
5
+ summary: Returns a response
6
+ description: Returns a response or a stream of responses
7
+ responses:
8
+ "400":
9
+ description: Bad Request
10
+ content:
11
+ application/json:
12
+ schema:
13
+ $ref: "#/components/schemas/ErrorResponse"
14
+
15
+ "200":
16
+ description: OK
17
+ content:
18
+ application/json:
19
+ schema:
20
+ $ref: "#/components/schemas/Response"
21
+ text/event-stream:
22
+ schema:
23
+ $ref: "#/components/schemas/ResponseStream"
24
+
25
+ components:
26
+ schemas:
27
+ ErrorResponse:
28
+ type: object
29
+ title: "ErrorResponse"
30
+ properties:
31
+ message:
32
+ type: string
33
+
34
+ Response:
35
+ type: object
36
+ title: "Hello Response"
37
+ properties:
38
+ message:
39
+ type: string
40
+
41
+ ResponseStream:
42
+ type: object
43
+ title: "Hello ResponseStream"
44
+ properties:
45
+ message:
46
+ type: string
47
+
48
+
@@ -0,0 +1,266 @@
1
+ [
2
+ {
3
+ "title": "Returns a response",
4
+ "canonical": "returns-a-response",
5
+ "description": "Returns a response or a stream of responses",
6
+ "type": "rest_get",
7
+ "category": "rest",
8
+ "context": {
9
+ "method": "get",
10
+ "path": "/response",
11
+ "fullPath": "/response",
12
+ "group": [
13
+ ""
14
+ ],
15
+ "scopes": []
16
+ },
17
+ "examples": {
18
+ "groups": [
19
+ {
20
+ "description": "Example request",
21
+ "examples": [
22
+ {
23
+ "codeblock": {
24
+ "tabs": [
25
+ {
26
+ "title": "shell",
27
+ "language": "shell",
28
+ "code": "curl --request GET \\\n --url https://example.com/response \\\n --header 'accept: application/json'"
29
+ },
30
+ {
31
+ "title": "javascript",
32
+ "language": "javascript",
33
+ "code": "const options = {method: 'GET', headers: {accept: 'application/json'}};\n\nfetch('https://example.com/response', options)\n .then(res => res.json())\n .then(res => console.log(res))\n .catch(err => console.error(err));"
34
+ },
35
+ {
36
+ "title": "python",
37
+ "language": "python",
38
+ "code": "import requests\n\nurl = \"https://example.com/response\"\n\nheaders = {\"accept\": \"application/json\"}\n\nresponse = requests.get(url, headers=headers)\n\nprint(response.text)"
39
+ },
40
+ {
41
+ "title": "go",
42
+ "language": "go",
43
+ "code": "package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com/response\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"accept\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(string(body))\n\n}"
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "description": "Example response",
52
+ "examples": [
53
+ {
54
+ "codeblock": {
55
+ "title": "200",
56
+ "tabs": [
57
+ {
58
+ "title": "application/json",
59
+ "language": "json",
60
+ "code": "{\n \"message\": \"string\"\n}"
61
+ },
62
+ {
63
+ "title": "text/event-stream",
64
+ "language": "text",
65
+ "code": "{\n \"message\": \"string\"\n}"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "codeblock": {
72
+ "title": "400",
73
+ "tabs": [
74
+ {
75
+ "title": "application/json",
76
+ "language": "json",
77
+ "code": "{\n \"message\": \"string\"\n}"
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ ]
85
+ },
86
+ "definitions": [
87
+ {
88
+ "title": "Response",
89
+ "variants": [
90
+ {
91
+ "title": "200",
92
+ "description": "OK",
93
+ "properties": [
94
+ {
95
+ "name": "message",
96
+ "type": "string",
97
+ "description": "",
98
+ "meta": []
99
+ }
100
+ ],
101
+ "meta": [
102
+ {
103
+ "name": "status",
104
+ "value": "200"
105
+ },
106
+ {
107
+ "name": "contentType",
108
+ "value": "application/json"
109
+ }
110
+ ],
111
+ "symbolDef": {
112
+ "id": "#/components/schemas/Response"
113
+ }
114
+ },
115
+ {
116
+ "title": "200",
117
+ "description": "OK",
118
+ "properties": [
119
+ {
120
+ "name": "message",
121
+ "type": "string",
122
+ "description": "",
123
+ "meta": []
124
+ }
125
+ ],
126
+ "meta": [
127
+ {
128
+ "name": "status",
129
+ "value": "200"
130
+ },
131
+ {
132
+ "name": "contentType",
133
+ "value": "text/event-stream"
134
+ }
135
+ ],
136
+ "symbolDef": {
137
+ "id": "#/components/schemas/ResponseStream"
138
+ }
139
+ },
140
+ {
141
+ "title": "400",
142
+ "description": "Bad Request",
143
+ "properties": [
144
+ {
145
+ "name": "message",
146
+ "type": "string",
147
+ "description": "",
148
+ "meta": []
149
+ }
150
+ ],
151
+ "meta": [
152
+ {
153
+ "name": "status",
154
+ "value": "400"
155
+ },
156
+ {
157
+ "name": "contentType",
158
+ "value": "application/json"
159
+ }
160
+ ],
161
+ "symbolDef": {
162
+ "id": "#/components/schemas/ErrorResponse"
163
+ }
164
+ }
165
+ ],
166
+ "properties": []
167
+ }
168
+ ]
169
+ },
170
+ {
171
+ "title": "ErrorResponse",
172
+ "description": "",
173
+ "canonical": "objects/ErrorResponse",
174
+ "definitions": [
175
+ {
176
+ "title": "ErrorResponse",
177
+ "properties": [
178
+ {
179
+ "name": "message",
180
+ "type": "string",
181
+ "description": "",
182
+ "meta": []
183
+ }
184
+ ],
185
+ "meta": [],
186
+ "symbolDef": {
187
+ "id": "#/components/schemas/ErrorResponse"
188
+ }
189
+ }
190
+ ],
191
+ "examples": {
192
+ "groups": []
193
+ },
194
+ "type": "rest_component_schema",
195
+ "context": {
196
+ "componentSchema": "ErrorResponse",
197
+ "group": [
198
+ "Objects"
199
+ ]
200
+ }
201
+ },
202
+ {
203
+ "title": "Response",
204
+ "description": "",
205
+ "canonical": "objects/Response",
206
+ "definitions": [
207
+ {
208
+ "title": "Response",
209
+ "properties": [
210
+ {
211
+ "name": "message",
212
+ "type": "string",
213
+ "description": "",
214
+ "meta": []
215
+ }
216
+ ],
217
+ "meta": [],
218
+ "symbolDef": {
219
+ "id": "#/components/schemas/Response"
220
+ }
221
+ }
222
+ ],
223
+ "examples": {
224
+ "groups": []
225
+ },
226
+ "type": "rest_component_schema",
227
+ "context": {
228
+ "componentSchema": "Response",
229
+ "group": [
230
+ "Objects"
231
+ ]
232
+ }
233
+ },
234
+ {
235
+ "title": "ResponseStream",
236
+ "description": "",
237
+ "canonical": "objects/ResponseStream",
238
+ "definitions": [
239
+ {
240
+ "title": "ResponseStream",
241
+ "properties": [
242
+ {
243
+ "name": "message",
244
+ "type": "string",
245
+ "description": "",
246
+ "meta": []
247
+ }
248
+ ],
249
+ "meta": [],
250
+ "symbolDef": {
251
+ "id": "#/components/schemas/ResponseStream"
252
+ }
253
+ }
254
+ ],
255
+ "examples": {
256
+ "groups": []
257
+ },
258
+ "type": "rest_component_schema",
259
+ "context": {
260
+ "componentSchema": "ResponseStream",
261
+ "group": [
262
+ "Objects"
263
+ ]
264
+ }
265
+ }
266
+ ]