@scalar/workspace-store 0.1.0

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 (198) hide show
  1. package/.turbo/turbo-build.log +10 -0
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +199 -0
  4. package/dist/create-server-workspace-store.d.ts +151 -0
  5. package/dist/create-server-workspace-store.d.ts.map +1 -0
  6. package/dist/create-server-workspace-store.js +199 -0
  7. package/dist/create-server-workspace-store.js.map +7 -0
  8. package/dist/create-workspace-store.d.ts +19773 -0
  9. package/dist/create-workspace-store.d.ts.map +1 -0
  10. package/dist/create-workspace-store.js +186 -0
  11. package/dist/create-workspace-store.js.map +7 -0
  12. package/dist/helpers/general.d.ts +88 -0
  13. package/dist/helpers/general.d.ts.map +1 -0
  14. package/dist/helpers/general.js +38 -0
  15. package/dist/helpers/general.js.map +7 -0
  16. package/dist/helpers/json-path-utils.d.ts +23 -0
  17. package/dist/helpers/json-path-utils.d.ts.map +1 -0
  18. package/dist/helpers/json-path-utils.js +16 -0
  19. package/dist/helpers/json-path-utils.js.map +7 -0
  20. package/dist/helpers/proxy.d.ts +63 -0
  21. package/dist/helpers/proxy.d.ts.map +1 -0
  22. package/dist/helpers/proxy.js +100 -0
  23. package/dist/helpers/proxy.js.map +7 -0
  24. package/dist/index.d.ts +4 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +13 -0
  27. package/dist/index.js.map +7 -0
  28. package/dist/schemas/callback.d.ts +1095 -0
  29. package/dist/schemas/callback.d.ts.map +1 -0
  30. package/dist/schemas/callback.js +11 -0
  31. package/dist/schemas/callback.js.map +7 -0
  32. package/dist/schemas/components.d.ts +2461 -0
  33. package/dist/schemas/components.d.ts.map +1 -0
  34. package/dist/schemas/components.js +38 -0
  35. package/dist/schemas/components.js.map +7 -0
  36. package/dist/schemas/contact.d.ts +10 -0
  37. package/dist/schemas/contact.d.ts.map +1 -0
  38. package/dist/schemas/contact.js +13 -0
  39. package/dist/schemas/contact.js.map +7 -0
  40. package/dist/schemas/discriminator.d.ts +12 -0
  41. package/dist/schemas/discriminator.d.ts.map +1 -0
  42. package/dist/schemas/discriminator.js +11 -0
  43. package/dist/schemas/discriminator.js.map +7 -0
  44. package/dist/schemas/encoding.d.ts +23 -0
  45. package/dist/schemas/encoding.d.ts.map +1 -0
  46. package/dist/schemas/encoding.js +13 -0
  47. package/dist/schemas/encoding.js.map +7 -0
  48. package/dist/schemas/example.d.ts +16 -0
  49. package/dist/schemas/example.d.ts.map +1 -0
  50. package/dist/schemas/example.js +15 -0
  51. package/dist/schemas/example.js.map +7 -0
  52. package/dist/schemas/external-documentation.d.ts +8 -0
  53. package/dist/schemas/external-documentation.d.ts.map +1 -0
  54. package/dist/schemas/external-documentation.js +11 -0
  55. package/dist/schemas/external-documentation.js.map +7 -0
  56. package/dist/schemas/header.d.ts +18 -0
  57. package/dist/schemas/header.d.ts.map +1 -0
  58. package/dist/schemas/header.js +13 -0
  59. package/dist/schemas/header.js.map +7 -0
  60. package/dist/schemas/info.d.ts +28 -0
  61. package/dist/schemas/info.d.ts.map +1 -0
  62. package/dist/schemas/info.js +23 -0
  63. package/dist/schemas/info.js.map +7 -0
  64. package/dist/schemas/license.d.ts +10 -0
  65. package/dist/schemas/license.d.ts.map +1 -0
  66. package/dist/schemas/license.js +13 -0
  67. package/dist/schemas/license.js.map +7 -0
  68. package/dist/schemas/link.d.ts +30 -0
  69. package/dist/schemas/link.d.ts.map +1 -0
  70. package/dist/schemas/link.js +20 -0
  71. package/dist/schemas/link.js.map +7 -0
  72. package/dist/schemas/media-type.d.ts +55 -0
  73. package/dist/schemas/media-type.d.ts.map +1 -0
  74. package/dist/schemas/media-type.js +19 -0
  75. package/dist/schemas/media-type.js.map +7 -0
  76. package/dist/schemas/oauth-flow.d.ts +12 -0
  77. package/dist/schemas/oauth-flow.d.ts.map +1 -0
  78. package/dist/schemas/oauth-flow.js +15 -0
  79. package/dist/schemas/oauth-flow.js.map +7 -0
  80. package/dist/schemas/oauthflows.d.ts +34 -0
  81. package/dist/schemas/oauthflows.d.ts.map +1 -0
  82. package/dist/schemas/oauthflows.js +16 -0
  83. package/dist/schemas/oauthflows.js.map +7 -0
  84. package/dist/schemas/openapi-document.d.ts +4683 -0
  85. package/dist/schemas/openapi-document.d.ts.map +1 -0
  86. package/dist/schemas/openapi-document.js +35 -0
  87. package/dist/schemas/openapi-document.js.map +7 -0
  88. package/dist/schemas/operation-without-callback.d.ts +190 -0
  89. package/dist/schemas/operation-without-callback.d.ts.map +1 -0
  90. package/dist/schemas/operation-without-callback.js +39 -0
  91. package/dist/schemas/operation-without-callback.js.map +7 -0
  92. package/dist/schemas/parameter.d.ts +25 -0
  93. package/dist/schemas/parameter.d.ts.map +1 -0
  94. package/dist/schemas/parameter.js +22 -0
  95. package/dist/schemas/parameter.js.map +7 -0
  96. package/dist/schemas/path-item.d.ts +1106 -0
  97. package/dist/schemas/path-item.d.ts.map +1 -0
  98. package/dist/schemas/path-item.js +37 -0
  99. package/dist/schemas/path-item.js.map +7 -0
  100. package/dist/schemas/paths.d.ts +1093 -0
  101. package/dist/schemas/paths.d.ts.map +1 -0
  102. package/dist/schemas/paths.js +11 -0
  103. package/dist/schemas/paths.js.map +7 -0
  104. package/dist/schemas/reference.d.ts +17 -0
  105. package/dist/schemas/reference.d.ts.map +1 -0
  106. package/dist/schemas/reference.js +15 -0
  107. package/dist/schemas/reference.js.map +7 -0
  108. package/dist/schemas/request-body.d.ts +54 -0
  109. package/dist/schemas/request-body.d.ts.map +1 -0
  110. package/dist/schemas/request-body.js +14 -0
  111. package/dist/schemas/request-body.js.map +7 -0
  112. package/dist/schemas/response.d.ts +84 -0
  113. package/dist/schemas/response.d.ts.map +1 -0
  114. package/dist/schemas/response.js +19 -0
  115. package/dist/schemas/response.js.map +7 -0
  116. package/dist/schemas/responses.d.ts +94 -0
  117. package/dist/schemas/responses.d.ts.map +1 -0
  118. package/dist/schemas/responses.js +8 -0
  119. package/dist/schemas/responses.js.map +7 -0
  120. package/dist/schemas/schema.d.ts +34 -0
  121. package/dist/schemas/schema.d.ts.map +1 -0
  122. package/dist/schemas/schema.js +22 -0
  123. package/dist/schemas/schema.js.map +7 -0
  124. package/dist/schemas/security-requirement.d.ts +11 -0
  125. package/dist/schemas/security-requirement.d.ts.map +1 -0
  126. package/dist/schemas/security-requirement.js +10 -0
  127. package/dist/schemas/security-requirement.js.map +7 -0
  128. package/dist/schemas/security-scheme.d.ts +137 -0
  129. package/dist/schemas/security-scheme.d.ts.map +1 -0
  130. package/dist/schemas/security-scheme.js +56 -0
  131. package/dist/schemas/security-scheme.js.map +7 -0
  132. package/dist/schemas/server-variable.d.ts +10 -0
  133. package/dist/schemas/server-variable.d.ts.map +1 -0
  134. package/dist/schemas/server-variable.js +13 -0
  135. package/dist/schemas/server-variable.js.map +7 -0
  136. package/dist/schemas/server-workspace.d.ts +14043 -0
  137. package/dist/schemas/server-workspace.d.ts.map +1 -0
  138. package/dist/schemas/server-workspace.js +29 -0
  139. package/dist/schemas/server-workspace.js.map +7 -0
  140. package/dist/schemas/server.d.ts +14 -0
  141. package/dist/schemas/server.d.ts.map +1 -0
  142. package/dist/schemas/server.js +14 -0
  143. package/dist/schemas/server.js.map +7 -0
  144. package/dist/schemas/tag.d.ts +13 -0
  145. package/dist/schemas/tag.d.ts.map +1 -0
  146. package/dist/schemas/tag.js +14 -0
  147. package/dist/schemas/tag.js.map +7 -0
  148. package/dist/schemas/xml.d.ts +18 -0
  149. package/dist/schemas/xml.d.ts.map +1 -0
  150. package/dist/schemas/xml.js +17 -0
  151. package/dist/schemas/xml.js.map +7 -0
  152. package/esbuild.ts +6 -0
  153. package/package.json +54 -0
  154. package/src/create-server-workspace-store.test.ts +429 -0
  155. package/src/create-server-workspace-store.ts +339 -0
  156. package/src/create-workspace-store.test.ts +488 -0
  157. package/src/create-workspace-store.ts +282 -0
  158. package/src/helpers/general.ts +115 -0
  159. package/src/helpers/json-path-utils.test.ts +13 -0
  160. package/src/helpers/json-path-utils.ts +38 -0
  161. package/src/helpers/proxy.test.ts +61 -0
  162. package/src/helpers/proxy.ts +213 -0
  163. package/src/index.ts +8 -0
  164. package/src/schemas/callback.ts +13 -0
  165. package/src/schemas/components.ts +36 -0
  166. package/src/schemas/contact.ts +11 -0
  167. package/src/schemas/discriminator.ts +13 -0
  168. package/src/schemas/encoding.ts +17 -0
  169. package/src/schemas/example.ts +17 -0
  170. package/src/schemas/external-documentation.ts +9 -0
  171. package/src/schemas/header.ts +19 -0
  172. package/src/schemas/info.ts +23 -0
  173. package/src/schemas/license.ts +11 -0
  174. package/src/schemas/link.ts +24 -0
  175. package/src/schemas/media-type.ts +21 -0
  176. package/src/schemas/oauth-flow.ts +13 -0
  177. package/src/schemas/oauthflows.ts +16 -0
  178. package/src/schemas/openapi-document.ts +34 -0
  179. package/src/schemas/operation-without-callback.ts +37 -0
  180. package/src/schemas/parameter.ts +26 -0
  181. package/src/schemas/path-item.ts +35 -0
  182. package/src/schemas/paths.ts +11 -0
  183. package/src/schemas/reference.ts +18 -0
  184. package/src/schemas/request-body.ts +12 -0
  185. package/src/schemas/response.ts +16 -0
  186. package/src/schemas/responses.ts +14 -0
  187. package/src/schemas/schema.ts +26 -0
  188. package/src/schemas/security-requirement.ts +16 -0
  189. package/src/schemas/security-scheme.ts +58 -0
  190. package/src/schemas/server-variable.ts +11 -0
  191. package/src/schemas/server-workspace.ts +36 -0
  192. package/src/schemas/server.ts +12 -0
  193. package/src/schemas/tag.ts +12 -0
  194. package/src/schemas/xml.ts +19 -0
  195. package/test/helpers.ts +16 -0
  196. package/tsconfig.build.json +12 -0
  197. package/tsconfig.json +8 -0
  198. package/vite.config.ts +9 -0
@@ -0,0 +1,429 @@
1
+ import { describe, expect, test } from 'vitest'
2
+ import {
3
+ createServerWorkspaceStore,
4
+ escapePaths,
5
+ externalizeComponentReferences,
6
+ externalizePathReferences,
7
+ filterHttpMethodsOnly,
8
+ } from './create-server-workspace-store'
9
+ import fs from 'node:fs/promises'
10
+ import { cwd } from 'node:process'
11
+ import { allFilesMatch } from '../test/helpers'
12
+
13
+ describe('create-server-store', () => {
14
+ const exampleDocument = () => ({
15
+ 'openapi': '3.1.1',
16
+ 'info': {
17
+ 'title': 'Scalar Galaxy',
18
+ 'version': '0.3.2',
19
+ },
20
+ 'paths': {
21
+ '/planets': {
22
+ get: { summary: 'List planets' },
23
+ },
24
+ },
25
+ 'components': {
26
+ 'parameters': {
27
+ 'planetId': {
28
+ 'name': 'planetId',
29
+ 'description': 'The ID of the planet to get',
30
+ 'in': 'path',
31
+ 'required': true,
32
+ 'schema': {
33
+ 'type': 'integer',
34
+ 'format': 'int64',
35
+ 'examples': [1],
36
+ },
37
+ },
38
+ },
39
+ },
40
+ })
41
+
42
+ describe('ssr', () => {
43
+ test('should be able to pass a list of documents and get the workspace', async () => {
44
+ const store = createServerWorkspaceStore({
45
+ mode: 'ssr',
46
+ baseUrl: 'https://example.com',
47
+ documents: [
48
+ {
49
+ name: 'api-1',
50
+ document: exampleDocument(),
51
+ },
52
+ {
53
+ name: 'api-2',
54
+ document: exampleDocument(),
55
+ },
56
+ ],
57
+ meta: {
58
+ 'x-scalar-active-document': 'api-1',
59
+ 'x-scalar-dark-mode': true,
60
+ },
61
+ })
62
+
63
+ const workspaceDocument = (name: string) => ({
64
+ 'openapi': '3.1.1',
65
+ 'info': {
66
+ 'title': 'Scalar Galaxy',
67
+ 'version': '0.3.2',
68
+ },
69
+ 'paths': {
70
+ '/planets': {
71
+ get: {
72
+ '$ref': `https://example.com/${name}/operations/~1planets/get#`,
73
+ },
74
+ },
75
+ },
76
+ 'components': {
77
+ parameters: {
78
+ planetId: {
79
+ '$ref': `https://example.com/${name}/components/parameters/planetId#`,
80
+ },
81
+ },
82
+ },
83
+ })
84
+
85
+ expect(store.getWorkspace()).toEqual({
86
+ 'x-scalar-active-document': 'api-1',
87
+ 'x-scalar-dark-mode': true,
88
+ documents: {
89
+ 'api-1': workspaceDocument('api-1'),
90
+ 'api-2': workspaceDocument('api-2'),
91
+ },
92
+ })
93
+ })
94
+
95
+ test('should be able to get the document chunks', async () => {
96
+ const store = createServerWorkspaceStore({
97
+ mode: 'ssr',
98
+ baseUrl: 'https://example.com',
99
+ documents: [
100
+ {
101
+ name: 'doc-1',
102
+ document: exampleDocument(),
103
+ },
104
+ ],
105
+ })
106
+
107
+ expect(store.get('#/doc-1/operations/~1planets/get')).toEqual({ summary: 'List planets' })
108
+ expect(store.get('#/doc-1/components/parameters/planetId')).toEqual({
109
+ 'name': 'planetId',
110
+ 'description': 'The ID of the planet to get',
111
+ 'in': 'path',
112
+ 'required': true,
113
+ 'schema': {
114
+ 'type': 'integer',
115
+ 'format': 'int64',
116
+ 'examples': [1],
117
+ },
118
+ })
119
+ })
120
+
121
+ test('should be able to add more documents on the workspace', async () => {
122
+ const store = createServerWorkspaceStore({
123
+ mode: 'ssr',
124
+ baseUrl: 'https://example.com',
125
+ documents: [
126
+ {
127
+ name: 'doc-1',
128
+ document: exampleDocument(),
129
+ meta: {
130
+ 'x-scalar-active-auth': 'test',
131
+ },
132
+ },
133
+ {
134
+ name: 'doc-2',
135
+ document: exampleDocument(),
136
+ },
137
+ ],
138
+ })
139
+
140
+ store.addDocument(exampleDocument(), { name: 'doc-3', 'x-scalar-active-auth': 'test' })
141
+ const workspace = store.getWorkspace()
142
+
143
+ expect(workspace.documents['doc-1']).toEqual({
144
+ 'openapi': '3.1.1',
145
+ 'info': {
146
+ 'title': 'Scalar Galaxy',
147
+ 'version': '0.3.2',
148
+ },
149
+ 'paths': {
150
+ '/planets': {
151
+ get: { '$ref': 'https://example.com/doc-1/operations/~1planets/get#' },
152
+ },
153
+ },
154
+ 'components': {
155
+ 'parameters': {
156
+ planetId: {
157
+ '$ref': 'https://example.com/doc-1/components/parameters/planetId#',
158
+ },
159
+ },
160
+ },
161
+ 'x-scalar-active-auth': 'test',
162
+ })
163
+
164
+ expect(workspace.documents['doc-3']).toEqual({
165
+ 'openapi': '3.1.1',
166
+ 'info': {
167
+ 'title': 'Scalar Galaxy',
168
+ 'version': '0.3.2',
169
+ },
170
+ 'paths': {
171
+ '/planets': {
172
+ get: { '$ref': 'https://example.com/doc-3/operations/~1planets/get#' },
173
+ },
174
+ },
175
+ 'components': {
176
+ 'parameters': {
177
+ planetId: {
178
+ '$ref': 'https://example.com/doc-3/components/parameters/planetId#',
179
+ },
180
+ },
181
+ },
182
+ 'x-scalar-active-auth': 'test',
183
+ })
184
+ })
185
+ })
186
+
187
+ describe('ssg', () => {
188
+ test('should generate the workspace file and also all the related chunks', async () => {
189
+ const dir = 'temp'
190
+
191
+ const store = createServerWorkspaceStore({
192
+ mode: 'static',
193
+ directory: dir,
194
+ documents: [
195
+ {
196
+ document: exampleDocument(),
197
+ name: 'doc-1',
198
+ meta: {
199
+ 'x-scalar-active-auth': 'test',
200
+ 'x-scalar-active-server': 'test',
201
+ },
202
+ },
203
+ ],
204
+ meta: {
205
+ 'x-scalar-active-document': 'test',
206
+ 'x-scalar-dark-mode': true,
207
+ 'x-scalar-default-client': 'node',
208
+ 'x-scalar-theme': 'default',
209
+ },
210
+ })
211
+
212
+ store.addDocument(exampleDocument(), {
213
+ name: 'doc-2',
214
+ 'x-scalar-active-auth': 'test',
215
+ 'x-scalar-active-server': 'test',
216
+ })
217
+ await store.generateWorkspaceChunks()
218
+
219
+ const basePath = `${cwd()}/${dir}`
220
+
221
+ // check the workspace is the correct format
222
+ expect(JSON.parse(await fs.readFile(`${basePath}/scalar-workspace.json`, { encoding: 'utf-8' }))).toEqual({
223
+ documents: {
224
+ 'doc-1': {
225
+ 'x-scalar-active-auth': 'test',
226
+ 'x-scalar-active-server': 'test',
227
+ 'openapi': '3.1.1',
228
+ 'info': {
229
+ 'title': 'Scalar Galaxy',
230
+ 'version': '0.3.2',
231
+ },
232
+ 'paths': {
233
+ '/planets': {
234
+ get: { '$ref': 'temp/chunks/doc-1/operations/~1planets/get.json#' },
235
+ },
236
+ },
237
+ 'components': {
238
+ 'parameters': { planetId: { '$ref': 'temp/chunks/doc-1/components/parameters/planetId.json#' } },
239
+ },
240
+ },
241
+ 'doc-2': {
242
+ 'x-scalar-active-auth': 'test',
243
+ 'x-scalar-active-server': 'test',
244
+ 'openapi': '3.1.1',
245
+ 'info': {
246
+ 'title': 'Scalar Galaxy',
247
+ 'version': '0.3.2',
248
+ },
249
+ 'paths': {
250
+ '/planets': {
251
+ get: { '$ref': 'temp/chunks/doc-2/operations/~1planets/get.json#' },
252
+ },
253
+ },
254
+ 'components': {
255
+ 'parameters': { planetId: { '$ref': 'temp/chunks/doc-2/components/parameters/planetId.json#' } },
256
+ },
257
+ },
258
+ },
259
+ 'x-scalar-active-document': 'test',
260
+ 'x-scalar-dark-mode': true,
261
+ 'x-scalar-default-client': 'node',
262
+ 'x-scalar-theme': 'default',
263
+ })
264
+
265
+ // check the generated chucks
266
+ expect(
267
+ await allFilesMatch([
268
+ {
269
+ content: JSON.stringify({
270
+ ...exampleDocument().components.parameters.planetId,
271
+ }),
272
+ path: `${basePath}/chunks/doc-1/components/parameters/planetId.json`,
273
+ },
274
+ {
275
+ content: JSON.stringify({
276
+ ...exampleDocument().paths['/planets'].get,
277
+ }),
278
+ path: `${basePath}/chunks/doc-1/operations/~1planets/get.json`,
279
+ },
280
+ ]),
281
+ ).toBe(true)
282
+
283
+ // clean up generated files
284
+ await fs.rmdir(basePath, { recursive: true })
285
+ })
286
+ })
287
+ })
288
+
289
+ describe('filter-http-methods-only', () => {
290
+ test('should only keep the http methods', () => {
291
+ const result = filterHttpMethodsOnly({
292
+ '/path': {
293
+ get: { description: 'some description' },
294
+ 'x-scalar-test': 'test',
295
+ servers: [],
296
+ parameters: [{ name: 'name', in: 'path' }],
297
+ },
298
+ })
299
+
300
+ // check that all the other keys are filtered
301
+ expect(Object.keys(result['/path'] ?? {})).toEqual(['get'])
302
+
303
+ // check the contents of the operation
304
+ expect(result['/path']?.get).toEqual({ description: 'some description' })
305
+ })
306
+ })
307
+
308
+ describe('escape-paths', () => {
309
+ test('should correctly escape / paths', () => {
310
+ const result = escapePaths({ '/hello/users': { get: { description: 'some description' } } })
311
+ expect(Object.keys(result)).toEqual(['~1hello~1users'])
312
+ expect(result['~1hello~1users']).toEqual({ get: { description: 'some description' } })
313
+ })
314
+
315
+ test('should correctly escape ~ paths', () => {
316
+ const result = escapePaths({ '/hello~world/users': { get: { description: 'some description' } } })
317
+ expect(Object.keys(result)).toEqual(['~1hello~0world~1users'])
318
+
319
+ expect(result['~1hello~0world~1users']).toEqual({ get: { description: 'some description' } })
320
+ })
321
+ })
322
+
323
+ describe('externalize-component-references', () => {
324
+ test('should convert the components with refs correctly for ssr mode', () => {
325
+ const result = externalizeComponentReferences(
326
+ {
327
+ components: {
328
+ schemas: {
329
+ 'User': {
330
+ 'type': 'object',
331
+ 'required': ['id', 'name', 'email'],
332
+ 'properties': {
333
+ 'id': {
334
+ 'type': 'string',
335
+ 'format': 'uuid',
336
+ 'example': '123e4567-e89b-12d3-a456-426614174000',
337
+ },
338
+ },
339
+ },
340
+ },
341
+ },
342
+ },
343
+ {
344
+ mode: 'ssr',
345
+ name: 'name',
346
+ baseUrl: 'https://example.com',
347
+ },
348
+ )
349
+
350
+ expect(result).toEqual({
351
+ schemas: { User: { '$ref': 'https://example.com/name/components/schemas/User#' } },
352
+ })
353
+ })
354
+
355
+ test('should convert the components with refs correctly for ssg mode', () => {
356
+ const result = externalizeComponentReferences(
357
+ {
358
+ components: {
359
+ schemas: {
360
+ 'User': {
361
+ 'type': 'object',
362
+ 'required': ['id', 'name', 'email'],
363
+ 'properties': {
364
+ 'id': {
365
+ 'type': 'string',
366
+ 'format': 'uuid',
367
+ 'example': '123e4567-e89b-12d3-a456-426614174000',
368
+ },
369
+ },
370
+ },
371
+ },
372
+ },
373
+ },
374
+ {
375
+ mode: 'static',
376
+ name: 'name',
377
+ directory: 'assets',
378
+ },
379
+ )
380
+
381
+ expect(result).toEqual({ schemas: { User: { '$ref': 'assets/chunks/name/components/schemas/User.json#' } } })
382
+ })
383
+ })
384
+
385
+ describe('externalize-path-references', () => {
386
+ test('should correctly replace the contents with a ref for ssr mode', () => {
387
+ const result = externalizePathReferences(
388
+ {
389
+ paths: {
390
+ '/test': {
391
+ get: {
392
+ description: 'string',
393
+ },
394
+ },
395
+ },
396
+ },
397
+ {
398
+ mode: 'ssr',
399
+ baseUrl: 'https://example.com',
400
+ name: 'name',
401
+ },
402
+ )
403
+
404
+ expect(result).toEqual({
405
+ '/test': { get: { '$ref': 'https://example.com/name/operations/~1test/get#' } },
406
+ })
407
+ })
408
+
409
+ test('should correctly replace the contents with a ref for ssg mode', () => {
410
+ const result = externalizePathReferences(
411
+ {
412
+ paths: {
413
+ '/test': {
414
+ get: {
415
+ description: 'string',
416
+ },
417
+ },
418
+ },
419
+ },
420
+ {
421
+ mode: 'static',
422
+ directory: 'assets',
423
+ name: 'name',
424
+ },
425
+ )
426
+
427
+ expect(result).toEqual({ '/test': { get: { '$ref': 'assets/chunks/name/operations/~1test/get.json#' } } })
428
+ })
429
+ })