@xyd-js/openapi 0.1.0-build.168
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.
- package/CHANGELOG.md +1517 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/__fixtures__/-2.complex.openai/input.yaml +39848 -0
- package/__fixtures__/-2.complex.openai/output.json +321646 -0
- package/__fixtures__/-2.complex.openai/pluginOasOpenai.ts +553 -0
- package/__fixtures__/-3.random/input.yaml +234 -0
- package/__fixtures__/-3.random/output.json +1140 -0
- package/__fixtures__/1.basic/input.yaml +226 -0
- package/__fixtures__/1.basic/output.json +1919 -0
- package/__fixtures__/2.more/input.yaml +76 -0
- package/__fixtures__/2.more/output.json +327 -0
- package/__fixtures__/3.multiple-responses/input.yaml +48 -0
- package/__fixtures__/3.multiple-responses/output.json +311 -0
- package/__fixtures__/5.xdocs.codeLanguages/input.yaml +231 -0
- package/__fixtures__/5.xdocs.codeLanguages/output.json +1879 -0
- package/__fixtures__/5.xdocs.sidebar/input.yaml +256 -0
- package/__fixtures__/5.xdocs.sidebar/output.json +843 -0
- package/__fixtures__/6.codeSamples/input.yaml +75 -0
- package/__fixtures__/6.codeSamples/output.json +293 -0
- package/__tests__/oapSchemaToReferences.test.ts +82 -0
- package/__tests__/utils.ts +81 -0
- package/dist/index.cjs +2154 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +2119 -0
- package/dist/index.js.map +1 -0
- package/examples/basic/index.ts +20 -0
- package/examples/basic/index2.ts +36 -0
- package/examples/basic/openapi.yaml +124 -0
- package/examples/dist/index.cjs +2 -0
- package/examples/dist/index.cjs.map +1 -0
- package/examples/dist/index.d.cts +2 -0
- package/examples/dist/index.d.ts +2 -0
- package/examples/dist/index.js +2 -0
- package/examples/dist/index.js.map +1 -0
- package/examples/semi/index.ts +16 -0
- package/examples/semi/openapi.yaml +365 -0
- package/examples/semi/references.json +500 -0
- package/examples/webhooks/index.ts +16 -0
- package/examples/webhooks/openapi.yaml +248 -0
- package/examples/webhooks/references.json +895 -0
- package/index.ts +12 -0
- package/package.json +31 -0
- package/src/const.ts +14 -0
- package/src/converters/oas-componentSchemas.ts +205 -0
- package/src/converters/oas-examples.ts +530 -0
- package/src/converters/oas-parameters.ts +41 -0
- package/src/converters/oas-paths.ts +354 -0
- package/src/converters/oas-requestBody.ts +57 -0
- package/src/converters/oas-responses.ts +76 -0
- package/src/converters/oas-schema.ts +141 -0
- package/src/index.ts +21 -0
- package/src/oas-core.ts +579 -0
- package/src/types.ts +18 -0
- package/src/utils.ts +157 -0
- package/src/xdocs/index.ts +18 -0
- package/src/xdocs/pluginSidebar.ts +580 -0
- package/src/xdocs/types.ts +26 -0
- package/tsconfig.json +18 -0
- package/tsup.config.ts +19 -0
- package/tsup.examples-config.ts +30 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
openapi: 3.0.0
|
|
2
|
+
info:
|
|
3
|
+
title: Sample API
|
|
4
|
+
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
|
5
|
+
version: 0.1.9
|
|
6
|
+
servers:
|
|
7
|
+
- url: http://api.example.com/v1
|
|
8
|
+
description: Optional server description, e.g. Main (production) server
|
|
9
|
+
- url: http://staging-api.example.com
|
|
10
|
+
description: Optional server description, e.g. Internal staging server for testing
|
|
11
|
+
paths:
|
|
12
|
+
/users:
|
|
13
|
+
get:
|
|
14
|
+
summary: Returns a list of users
|
|
15
|
+
description: Optional extended description in CommonMark or HTML.
|
|
16
|
+
parameters:
|
|
17
|
+
- name: limit
|
|
18
|
+
in: query
|
|
19
|
+
description: Maximum number of items to return
|
|
20
|
+
required: true
|
|
21
|
+
schema:
|
|
22
|
+
type: integer
|
|
23
|
+
default: 20
|
|
24
|
+
- name: offset
|
|
25
|
+
in: query
|
|
26
|
+
description: Number of items to skip
|
|
27
|
+
required: false
|
|
28
|
+
schema:
|
|
29
|
+
type: integer
|
|
30
|
+
default: 0
|
|
31
|
+
responses:
|
|
32
|
+
'200':
|
|
33
|
+
description: A JSON array of users
|
|
34
|
+
content:
|
|
35
|
+
application/json:
|
|
36
|
+
schema:
|
|
37
|
+
type: array
|
|
38
|
+
items:
|
|
39
|
+
$ref: '#/components/schemas/User'
|
|
40
|
+
x-codeSamples:
|
|
41
|
+
- lang: bash
|
|
42
|
+
label: List all users
|
|
43
|
+
source: |
|
|
44
|
+
curl -X GET https://api.example.com/v1/users
|
|
45
|
+
|
|
46
|
+
- lang: javascript
|
|
47
|
+
label: List all users
|
|
48
|
+
source: |
|
|
49
|
+
const api = require('api-client');
|
|
50
|
+
api.users.list();
|
|
51
|
+
components:
|
|
52
|
+
schemas:
|
|
53
|
+
User:
|
|
54
|
+
type: object
|
|
55
|
+
required:
|
|
56
|
+
- id
|
|
57
|
+
- username
|
|
58
|
+
properties:
|
|
59
|
+
id:
|
|
60
|
+
type: integer
|
|
61
|
+
format: int64
|
|
62
|
+
username:
|
|
63
|
+
type: string
|
|
64
|
+
email:
|
|
65
|
+
type: string
|
|
66
|
+
format: email
|
|
67
|
+
status:
|
|
68
|
+
type: string
|
|
69
|
+
enum: [active, inactive]
|
|
70
|
+
createdAt:
|
|
71
|
+
type: string
|
|
72
|
+
format: date-time
|
|
73
|
+
updatedAt:
|
|
74
|
+
type: string
|
|
75
|
+
format: date-time
|
|
@@ -0,0 +1,293 @@
|
|
|
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": "http:/api.example.com/v1/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": "bash",
|
|
27
|
+
"language": "bash",
|
|
28
|
+
"code": "curl -X GET https://api.example.com/v1/users\n"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"title": "javascript",
|
|
32
|
+
"language": "javascript",
|
|
33
|
+
"code": "const api = require('api-client');\napi.users.list();\n"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"description": "Example response",
|
|
42
|
+
"examples": [
|
|
43
|
+
{
|
|
44
|
+
"codeblock": {
|
|
45
|
+
"title": "200",
|
|
46
|
+
"tabs": [
|
|
47
|
+
{
|
|
48
|
+
"title": "application/json",
|
|
49
|
+
"language": "json",
|
|
50
|
+
"code": "[\n {\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]"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"definitions": [
|
|
60
|
+
{
|
|
61
|
+
"title": "Query parameters",
|
|
62
|
+
"properties": [
|
|
63
|
+
{
|
|
64
|
+
"name": "limit",
|
|
65
|
+
"type": "integer",
|
|
66
|
+
"description": "Maximum number of items to return",
|
|
67
|
+
"meta": [
|
|
68
|
+
{
|
|
69
|
+
"name": "defaults",
|
|
70
|
+
"value": 20
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"name": "required",
|
|
74
|
+
"value": "true"
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "offset",
|
|
80
|
+
"type": "integer",
|
|
81
|
+
"description": "Number of items to skip",
|
|
82
|
+
"meta": [
|
|
83
|
+
{
|
|
84
|
+
"name": "defaults",
|
|
85
|
+
"value": 0
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"title": "Response",
|
|
93
|
+
"variants": [
|
|
94
|
+
{
|
|
95
|
+
"title": "200",
|
|
96
|
+
"description": "A JSON array of users",
|
|
97
|
+
"properties": [],
|
|
98
|
+
"rootProperty": {
|
|
99
|
+
"type": "$$array",
|
|
100
|
+
"properties": [
|
|
101
|
+
{
|
|
102
|
+
"name": "id",
|
|
103
|
+
"type": "integer",
|
|
104
|
+
"description": "",
|
|
105
|
+
"meta": [
|
|
106
|
+
{
|
|
107
|
+
"name": "required",
|
|
108
|
+
"value": "true"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "username",
|
|
114
|
+
"type": "string",
|
|
115
|
+
"description": "",
|
|
116
|
+
"meta": [
|
|
117
|
+
{
|
|
118
|
+
"name": "required",
|
|
119
|
+
"value": "true"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "email",
|
|
125
|
+
"type": "string",
|
|
126
|
+
"description": "",
|
|
127
|
+
"meta": []
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "status",
|
|
131
|
+
"type": "$$enum",
|
|
132
|
+
"description": "",
|
|
133
|
+
"meta": [
|
|
134
|
+
{
|
|
135
|
+
"name": "enum-type",
|
|
136
|
+
"value": "string"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"properties": [
|
|
140
|
+
{
|
|
141
|
+
"name": "active",
|
|
142
|
+
"type": "string",
|
|
143
|
+
"description": "",
|
|
144
|
+
"meta": []
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"name": "inactive",
|
|
148
|
+
"type": "string",
|
|
149
|
+
"description": "",
|
|
150
|
+
"meta": []
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"name": "createdAt",
|
|
156
|
+
"type": "string",
|
|
157
|
+
"description": "",
|
|
158
|
+
"meta": []
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "updatedAt",
|
|
162
|
+
"type": "string",
|
|
163
|
+
"description": "",
|
|
164
|
+
"meta": []
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
"meta": [
|
|
169
|
+
{
|
|
170
|
+
"name": "status",
|
|
171
|
+
"value": "200"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"name": "contentType",
|
|
175
|
+
"value": "application/json"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"name": "definitionDescription",
|
|
179
|
+
"value": ""
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"properties": []
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"title": "User",
|
|
190
|
+
"description": "",
|
|
191
|
+
"canonical": "objects/User",
|
|
192
|
+
"definitions": [
|
|
193
|
+
{
|
|
194
|
+
"title": "User",
|
|
195
|
+
"properties": [
|
|
196
|
+
{
|
|
197
|
+
"name": "id",
|
|
198
|
+
"type": "integer",
|
|
199
|
+
"description": "",
|
|
200
|
+
"meta": [
|
|
201
|
+
{
|
|
202
|
+
"name": "required",
|
|
203
|
+
"value": "true"
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"name": "username",
|
|
209
|
+
"type": "string",
|
|
210
|
+
"description": "",
|
|
211
|
+
"meta": [
|
|
212
|
+
{
|
|
213
|
+
"name": "required",
|
|
214
|
+
"value": "true"
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"name": "email",
|
|
220
|
+
"type": "string",
|
|
221
|
+
"description": "",
|
|
222
|
+
"meta": []
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"name": "status",
|
|
226
|
+
"type": "$$enum",
|
|
227
|
+
"description": "",
|
|
228
|
+
"meta": [
|
|
229
|
+
{
|
|
230
|
+
"name": "enum-type",
|
|
231
|
+
"value": "string"
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
"properties": [
|
|
235
|
+
{
|
|
236
|
+
"name": "active",
|
|
237
|
+
"type": "string",
|
|
238
|
+
"description": "",
|
|
239
|
+
"meta": []
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"name": "inactive",
|
|
243
|
+
"type": "string",
|
|
244
|
+
"description": "",
|
|
245
|
+
"meta": []
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"name": "createdAt",
|
|
251
|
+
"type": "string",
|
|
252
|
+
"description": "",
|
|
253
|
+
"meta": []
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"name": "updatedAt",
|
|
257
|
+
"type": "string",
|
|
258
|
+
"description": "",
|
|
259
|
+
"meta": []
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
"meta": []
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
"examples": {
|
|
266
|
+
"groups": [
|
|
267
|
+
{
|
|
268
|
+
"description": "Example",
|
|
269
|
+
"examples": [
|
|
270
|
+
{
|
|
271
|
+
"codeblock": {
|
|
272
|
+
"tabs": [
|
|
273
|
+
{
|
|
274
|
+
"title": "json",
|
|
275
|
+
"language": "json",
|
|
276
|
+
"code": "{\n \"id\": 0,\n \"username\": \"\",\n \"email\": \"\",\n \"status\": \"\",\n \"createdAt\": \"\",\n \"updatedAt\": \"\"\n}"
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
"type": "rest_component_schema",
|
|
286
|
+
"context": {
|
|
287
|
+
"componentSchema": "User",
|
|
288
|
+
"group": [
|
|
289
|
+
"Objects"
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {testOasSchemaToReferences} from "./utils";
|
|
4
|
+
import {uniformOasOptions} from "../src/types";
|
|
5
|
+
import {uniformOpenAIMeta} from "../__fixtures__/-2.complex.openai/pluginOasOpenai";
|
|
6
|
+
import {uniformPluginXDocsSidebar} from "../src/xdocs/pluginSidebar";
|
|
7
|
+
|
|
8
|
+
const tests: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string,
|
|
11
|
+
url?: string, // URL to the OpenAPI schema
|
|
12
|
+
plugins?: any[]; // TODO: fix any,
|
|
13
|
+
options?: uniformOasOptions
|
|
14
|
+
}[] = [
|
|
15
|
+
{
|
|
16
|
+
name: "-3.random",
|
|
17
|
+
// url: "https://raw.githubusercontent.com/bump-sh-examples/train-travel-api/main/openapi.yaml",
|
|
18
|
+
// url: "https://raw.githubusercontent.com/digitalocean/openapi/main/specification/DigitalOcean-public.v2.yaml",
|
|
19
|
+
// url: "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/ghes-3.0/ghes-3.0.json",
|
|
20
|
+
// url: "https://raw.githubusercontent.com/box/box-openapi/main/openapi.json",
|
|
21
|
+
// url: "https://api.apis.guru/v2/specs/nytimes.com/article_search/1.0.0/openapi.yaml",
|
|
22
|
+
// url: "https://developers.intercom.com/_spec/docs/references/@2.11/rest-api/api.intercom.io.json",
|
|
23
|
+
// url: "https://raw.githubusercontent.com/livesession/livesession-openapi/refs/heads/master/openapi.yaml",
|
|
24
|
+
// url: "https://openapi.vercel.sh",
|
|
25
|
+
description: "",
|
|
26
|
+
// plugins: [
|
|
27
|
+
// uniformPluginXDocsSidebar
|
|
28
|
+
// ]
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
// {
|
|
32
|
+
// name: "1.basic",
|
|
33
|
+
// description: "Basic OpenAPI API example",
|
|
34
|
+
// },
|
|
35
|
+
// {
|
|
36
|
+
// name: "2.more",
|
|
37
|
+
// description: "More OpenAPI API example",
|
|
38
|
+
// },
|
|
39
|
+
// {
|
|
40
|
+
// name: "3.multiple-responses",
|
|
41
|
+
// description: "Multiple responses OpenAPI API example",
|
|
42
|
+
// },
|
|
43
|
+
// {
|
|
44
|
+
// name: "5.xdocs.codeLanguages",
|
|
45
|
+
// description: "x-docs OpenAPI API codeLanguages example",
|
|
46
|
+
// },
|
|
47
|
+
// {
|
|
48
|
+
// name: "5.xdocs.sidebar",
|
|
49
|
+
// description: "x-docs OpenAPI API sidebar example",
|
|
50
|
+
// plugins: [
|
|
51
|
+
// uniformPluginXDocsSidebar
|
|
52
|
+
// ]
|
|
53
|
+
// },
|
|
54
|
+
// {
|
|
55
|
+
// name: "6.codeSamples",
|
|
56
|
+
// description: "x-codeSamples OpenAPI API example",
|
|
57
|
+
// },
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
describe("oapSchemaToReferences", {timeout: 15000}, () => {
|
|
61
|
+
tests.forEach((test) => {
|
|
62
|
+
it(`[${test.name}]: ${test.description}`, async () => {
|
|
63
|
+
await testOasSchemaToReferences(test.name, test.options, test.plugins, test.url);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// TODO: uncomment when ready
|
|
70
|
+
// {
|
|
71
|
+
// name: "-2.complex.openai",
|
|
72
|
+
// description: "OpenAI OpenAPI API example",
|
|
73
|
+
// plugins: [
|
|
74
|
+
// uniformOpenAIMeta,
|
|
75
|
+
// ],
|
|
76
|
+
// // options: {
|
|
77
|
+
// // regions: [
|
|
78
|
+
// // // "/components/schemas/ListAssistantsResponse",
|
|
79
|
+
// // "POST /responses"
|
|
80
|
+
// // ]
|
|
81
|
+
// // }
|
|
82
|
+
// },
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
4
|
+
import {expect} from "vitest";
|
|
5
|
+
|
|
6
|
+
import uniform from "@xyd-js/uniform";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
deferencedOpenAPI,
|
|
10
|
+
oapSchemaToReferences,
|
|
11
|
+
|
|
12
|
+
type uniformOasOptions
|
|
13
|
+
} from "../index";
|
|
14
|
+
|
|
15
|
+
// Helper function to remove functions from an object
|
|
16
|
+
function removeFunctions(obj: any): any {
|
|
17
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(obj)) {
|
|
22
|
+
return obj.map(removeFunctions);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const result: any = {};
|
|
26
|
+
for (const key in obj) {
|
|
27
|
+
if (typeof obj[key] !== 'function') {
|
|
28
|
+
result[key] = removeFunctions(obj[key]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Helper function to run a test with a specific fixture
|
|
35
|
+
export async function testOasSchemaToReferences(
|
|
36
|
+
fixtureName: string,
|
|
37
|
+
options?: uniformOasOptions,
|
|
38
|
+
plugins?: any[], // TODO: fix any,
|
|
39
|
+
url?: string // URL to the OpenAPI schema
|
|
40
|
+
) {
|
|
41
|
+
const schemaLocation = url ? url : fullFixturePath(`${fixtureName}/input.yaml`)
|
|
42
|
+
|
|
43
|
+
const schemalocation = await deferencedOpenAPI(schemaLocation);
|
|
44
|
+
let result = oapSchemaToReferences(schemalocation, options);
|
|
45
|
+
if (plugins?.length) {
|
|
46
|
+
const uni = uniform(result, {
|
|
47
|
+
plugins
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
result = uni.references;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// saveResultAsOutput(fixtureName, result) // TODO: comment for prod
|
|
54
|
+
|
|
55
|
+
const expectedOutput = readFixtureOutput(`${fixtureName}/output.json`);
|
|
56
|
+
try {
|
|
57
|
+
// Remove functions before comparison
|
|
58
|
+
const cleanResult = removeFunctions(result);
|
|
59
|
+
const cleanExpected = removeFunctions(expectedOutput);
|
|
60
|
+
expect(cleanResult).toEqual(cleanExpected);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (result?.length > 100) {
|
|
63
|
+
throw new Error(`FAILED: The diff result is too long (${result.length} items) to show.`);
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Helper function to read fixture output
|
|
70
|
+
function readFixtureOutput(name: string) {
|
|
71
|
+
const fixturePath = fullFixturePath(name);
|
|
72
|
+
return JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function fullFixturePath(name: string) {
|
|
76
|
+
return path.join(__dirname, "../__fixtures__", name);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function saveResultAsOutput(fixtureName: string, result: any) {
|
|
80
|
+
fs.writeFileSync(fullFixturePath(fixtureName + "/output.json"), JSON.stringify(result, null, 2));
|
|
81
|
+
}
|