@gitbook/react-openapi 1.0.3 → 1.0.5

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 (68) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/InteractiveSection.jsx +10 -9
  3. package/dist/OpenAPICodeSample.jsx +8 -9
  4. package/dist/OpenAPIDisclosure.d.ts +2 -1
  5. package/dist/OpenAPIDisclosure.jsx +2 -1
  6. package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
  7. package/dist/OpenAPIDisclosureGroup.jsx +3 -2
  8. package/dist/OpenAPIOperation.jsx +2 -2
  9. package/dist/OpenAPIPath.d.ts +3 -2
  10. package/dist/OpenAPIPath.jsx +4 -15
  11. package/dist/OpenAPIRequestBody.jsx +1 -1
  12. package/dist/OpenAPIResponse.jsx +1 -1
  13. package/dist/OpenAPIResponseExample.jsx +10 -10
  14. package/dist/OpenAPIResponses.d.ts +1 -1
  15. package/dist/OpenAPIResponses.jsx +5 -5
  16. package/dist/OpenAPISchema.d.ts +5 -1
  17. package/dist/OpenAPISchema.jsx +30 -21
  18. package/dist/OpenAPISchemaName.d.ts +4 -3
  19. package/dist/OpenAPISchemaName.jsx +1 -1
  20. package/dist/OpenAPISecurities.jsx +2 -2
  21. package/dist/OpenAPISpec.jsx +3 -4
  22. package/dist/OpenAPITabs.d.ts +3 -3
  23. package/dist/OpenAPITabs.jsx +52 -49
  24. package/dist/ScalarApiButton.jsx +1 -1
  25. package/dist/StaticSection.d.ts +10 -0
  26. package/dist/StaticSection.jsx +23 -0
  27. package/dist/code-samples.js +11 -11
  28. package/dist/generateSchemaExample.js +2 -1
  29. package/dist/resolveOpenAPIOperation.d.ts +3 -3
  30. package/dist/resolveOpenAPIOperation.js +1 -1
  31. package/dist/tsconfig.build.tsbuildinfo +1 -1
  32. package/dist/useSyncedTabsGlobalState.d.ts +10 -1
  33. package/dist/useSyncedTabsGlobalState.js +19 -15
  34. package/dist/util/server.d.ts +1 -1
  35. package/dist/util/server.js +1 -3
  36. package/dist/utils.d.ts +1 -1
  37. package/dist/utils.js +4 -6
  38. package/package.json +2 -7
  39. package/src/InteractiveSection.tsx +13 -21
  40. package/src/OpenAPICodeSample.tsx +11 -12
  41. package/src/OpenAPIDisclosure.tsx +5 -3
  42. package/src/OpenAPIDisclosureGroup.tsx +13 -11
  43. package/src/OpenAPIOperation.tsx +3 -3
  44. package/src/OpenAPIOperationContext.tsx +1 -1
  45. package/src/OpenAPIPath.tsx +11 -10
  46. package/src/OpenAPIRequestBody.tsx +2 -2
  47. package/src/OpenAPIResponse.tsx +3 -3
  48. package/src/OpenAPIResponseExample.tsx +12 -19
  49. package/src/OpenAPIResponses.tsx +7 -7
  50. package/src/OpenAPISchema.test.ts +5 -5
  51. package/src/OpenAPISchema.tsx +77 -27
  52. package/src/OpenAPISchemaName.tsx +5 -4
  53. package/src/OpenAPISecurities.tsx +3 -3
  54. package/src/OpenAPISpec.tsx +3 -5
  55. package/src/OpenAPITabs.tsx +56 -67
  56. package/src/ScalarApiButton.tsx +3 -3
  57. package/src/StaticSection.tsx +59 -0
  58. package/src/code-samples.test.ts +66 -66
  59. package/src/code-samples.ts +14 -14
  60. package/src/generateSchemaExample.ts +3 -3
  61. package/src/json2xml.test.ts +1 -1
  62. package/src/resolveOpenAPIOperation.test.ts +6 -6
  63. package/src/resolveOpenAPIOperation.ts +7 -7
  64. package/src/stringifyOpenAPI.ts +1 -1
  65. package/src/useSyncedTabsGlobalState.ts +33 -21
  66. package/src/util/server.test.ts +3 -3
  67. package/src/util/server.ts +2 -3
  68. package/src/utils.ts +4 -4
@@ -1,5 +1,5 @@
1
- import { it, expect, describe } from 'bun:test';
2
- import { codeSampleGenerators, CodeSampleInput, parseHostAndPath } from './code-samples';
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { type CodeSampleInput, codeSampleGenerators, parseHostAndPath } from './code-samples';
3
3
 
4
4
  it('should parse host and path on url strings properly', () => {
5
5
  const testUrls = [
@@ -67,10 +67,10 @@ describe('curL code sample generator', () => {
67
67
  },
68
68
  };
69
69
 
70
- const output = generator!.generate(input);
70
+ const output = generator?.generate(input);
71
71
 
72
72
  expect(output).toBe(
73
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\n --data 'key=value'",
73
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/x-www-form-urlencoded' \\\n --data 'key=value'"
74
74
  );
75
75
  });
76
76
 
@@ -86,10 +86,10 @@ describe('curL code sample generator', () => {
86
86
  },
87
87
  };
88
88
 
89
- const output = generator!.generate(input);
89
+ const output = generator?.generate(input);
90
90
 
91
91
  expect(output).toBe(
92
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"key\": \"value\"\n }'",
92
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/json' \\\n --data '{\n \"key\": \"value\"\n }'"
93
93
  );
94
94
  });
95
95
 
@@ -103,10 +103,10 @@ describe('curL code sample generator', () => {
103
103
  body: '<key>value</key>',
104
104
  };
105
105
 
106
- const output = generator!.generate(input);
106
+ const output = generator?.generate(input);
107
107
 
108
108
  expect(output).toBe(
109
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/xml' \\\n --data-binary $'<key>value</key>'",
109
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/xml' \\\n --data-binary $'<key>value</key>'"
110
110
  );
111
111
  });
112
112
 
@@ -120,10 +120,10 @@ describe('curL code sample generator', () => {
120
120
  body: '{ key }',
121
121
  };
122
122
 
123
- const output = generator!.generate(input);
123
+ const output = generator?.generate(input);
124
124
 
125
125
  expect(output).toBe(
126
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/json' \\\n --data '\"{ key }\"'",
126
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/json' \\\n --data '\"{ key }\"'"
127
127
  );
128
128
  });
129
129
 
@@ -137,10 +137,10 @@ describe('curL code sample generator', () => {
137
137
  body: 'key,value',
138
138
  };
139
139
 
140
- const output = generator!.generate(input);
140
+ const output = generator?.generate(input);
141
141
 
142
142
  expect(output).toBe(
143
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: text/csv' \\\n --data-binary $'key,value'",
143
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: text/csv' \\\n --data-binary $'key,value'"
144
144
  );
145
145
  });
146
146
 
@@ -154,10 +154,10 @@ describe('curL code sample generator', () => {
154
154
  body: 'file',
155
155
  };
156
156
 
157
- const output = generator!.generate(input);
157
+ const output = generator?.generate(input);
158
158
 
159
159
  expect(output).toBe(
160
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/pdf' \\\n --data-binary '@file'",
160
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: application/pdf' \\\n --data-binary '@file'"
161
161
  );
162
162
  });
163
163
 
@@ -171,10 +171,10 @@ describe('curL code sample generator', () => {
171
171
  body: 'value',
172
172
  };
173
173
 
174
- const output = generator!.generate(input);
174
+ const output = generator?.generate(input);
175
175
 
176
176
  expect(output).toBe(
177
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: text/plain' \\\n --data 'value'",
177
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: text/plain' \\\n --data 'value'"
178
178
  );
179
179
  });
180
180
 
@@ -190,10 +190,10 @@ describe('curL code sample generator', () => {
190
190
  },
191
191
  };
192
192
 
193
- const output = generator!.generate(input);
193
+ const output = generator?.generate(input);
194
194
 
195
195
  expect(output).toBe(
196
- "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: multipart/form-data' \\\n --form 'key=value'",
196
+ "curl -L \\\n --url 'https://example.com/path' \\\n --header 'Content-Type: multipart/form-data' \\\n --form 'key=value'"
197
197
  );
198
198
  });
199
199
  });
@@ -215,10 +215,10 @@ describe('javascript code sample generator', () => {
215
215
  },
216
216
  };
217
217
 
218
- const output = generator!.generate(input);
218
+ const output = generator?.generate(input);
219
219
 
220
220
  expect(output).toBe(
221
- 'const params = new URLSearchParams();\n\nparams.append("key", "value");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/x-www-form-urlencoded"\n },\n body: params.toString()\n});\n\nconst data = await response.json();',
221
+ 'const params = new URLSearchParams();\n\nparams.append("key", "value");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/x-www-form-urlencoded"\n },\n body: params.toString()\n});\n\nconst data = await response.json();'
222
222
  );
223
223
  });
224
224
 
@@ -234,10 +234,10 @@ describe('javascript code sample generator', () => {
234
234
  },
235
235
  };
236
236
 
237
- const output = generator!.generate(input);
237
+ const output = generator?.generate(input);
238
238
 
239
239
  expect(output).toBe(
240
- 'const response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/json"\n },\n body: JSON.stringify({\n "key": "value"\n })\n});\n\nconst data = await response.json();',
240
+ 'const response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/json"\n },\n body: JSON.stringify({\n "key": "value"\n })\n});\n\nconst data = await response.json();'
241
241
  );
242
242
  });
243
243
 
@@ -251,10 +251,10 @@ describe('javascript code sample generator', () => {
251
251
  body: '<key>value</key>',
252
252
  };
253
253
 
254
- const output = generator!.generate(input);
254
+ const output = generator?.generate(input);
255
255
 
256
256
  expect(output).toBe(
257
- 'const xml = `\n <key>value</key>`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/xml"\n },\n body: xml\n});\n\nconst data = await response.json();',
257
+ 'const xml = `\n <key>value</key>`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/xml"\n },\n body: xml\n});\n\nconst data = await response.json();'
258
258
  );
259
259
  });
260
260
 
@@ -268,10 +268,10 @@ describe('javascript code sample generator', () => {
268
268
  body: '{ key }',
269
269
  };
270
270
 
271
- const output = generator!.generate(input);
271
+ const output = generator?.generate(input);
272
272
 
273
273
  expect(output).toBe(
274
- 'const query = `\n { key }`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/graphql"\n },\n body: JSON.stringify(query)\n});\n\nconst data = await response.json();',
274
+ 'const query = `\n { key }`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/graphql"\n },\n body: JSON.stringify(query)\n});\n\nconst data = await response.json();'
275
275
  );
276
276
  });
277
277
 
@@ -285,10 +285,10 @@ describe('javascript code sample generator', () => {
285
285
  body: 'key,value',
286
286
  };
287
287
 
288
- const output = generator!.generate(input);
288
+ const output = generator?.generate(input);
289
289
 
290
290
  expect(output).toBe(
291
- 'const csv = `\n key,value`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "text/csv"\n },\n body: csv\n});\n\nconst data = await response.json();',
291
+ 'const csv = `\n key,value`;\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "text/csv"\n },\n body: csv\n});\n\nconst data = await response.json();'
292
292
  );
293
293
  });
294
294
 
@@ -302,10 +302,10 @@ describe('javascript code sample generator', () => {
302
302
  body: 'file',
303
303
  };
304
304
 
305
- const output = generator!.generate(input);
305
+ const output = generator?.generate(input);
306
306
 
307
307
  expect(output).toBe(
308
- 'const formData = new FormData();\n\nformData.append("file", "file");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/pdf"\n },\n body: formData\n});\n\nconst data = await response.json();',
308
+ 'const formData = new FormData();\n\nformData.append("file", "file");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "application/pdf"\n },\n body: formData\n});\n\nconst data = await response.json();'
309
309
  );
310
310
  });
311
311
 
@@ -319,10 +319,10 @@ describe('javascript code sample generator', () => {
319
319
  body: 'value',
320
320
  };
321
321
 
322
- const output = generator!.generate(input);
322
+ const output = generator?.generate(input);
323
323
 
324
324
  expect(output).toBe(
325
- 'const response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "text/plain"\n },\n body: "value"\n});\n\nconst data = await response.json();',
325
+ 'const response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "text/plain"\n },\n body: "value"\n});\n\nconst data = await response.json();'
326
326
  );
327
327
  });
328
328
 
@@ -338,10 +338,10 @@ describe('javascript code sample generator', () => {
338
338
  },
339
339
  };
340
340
 
341
- const output = generator!.generate(input);
341
+ const output = generator?.generate(input);
342
342
 
343
343
  expect(output).toBe(
344
- 'const formData = new FormData();\n\nformData.append("key", "value");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "multipart/form-data"\n },\n body: formData\n});\n\nconst data = await response.json();',
344
+ 'const formData = new FormData();\n\nformData.append("key", "value");\n\nconst response = await fetch(\'https://example.com/path\', {\n method: \'GET\',\n headers: {\n "Content-Type": "multipart/form-data"\n },\n body: formData\n});\n\nconst data = await response.json();'
345
345
  );
346
346
  });
347
347
  });
@@ -363,10 +363,10 @@ describe('python code sample generator', () => {
363
363
  },
364
364
  };
365
365
 
366
- const output = generator!.generate(input);
366
+ const output = generator?.generate(input);
367
367
 
368
368
  expect(output).toBe(
369
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/x-www-form-urlencoded"},\n data={"key":"value"}\n)\n\ndata = response.json()',
369
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/x-www-form-urlencoded"},\n data={"key":"value"}\n)\n\ndata = response.json()'
370
370
  );
371
371
  });
372
372
 
@@ -382,10 +382,10 @@ describe('python code sample generator', () => {
382
382
  },
383
383
  };
384
384
 
385
- const output = generator!.generate(input);
385
+ const output = generator?.generate(input);
386
386
 
387
387
  expect(output).toBe(
388
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/json"},\n data={"key":"value"}\n)\n\ndata = response.json()',
388
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/json"},\n data={"key":"value"}\n)\n\ndata = response.json()'
389
389
  );
390
390
  });
391
391
 
@@ -399,10 +399,10 @@ describe('python code sample generator', () => {
399
399
  body: '<key>value</key>',
400
400
  };
401
401
 
402
- const output = generator!.generate(input);
402
+ const output = generator?.generate(input);
403
403
 
404
404
  expect(output).toBe(
405
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/xml"},\n data="<key>value</key>"\n)\n\ndata = response.json()',
405
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/xml"},\n data="<key>value</key>"\n)\n\ndata = response.json()'
406
406
  );
407
407
  });
408
408
 
@@ -416,10 +416,10 @@ describe('python code sample generator', () => {
416
416
  body: '{ key }',
417
417
  };
418
418
 
419
- const output = generator!.generate(input);
419
+ const output = generator?.generate(input);
420
420
 
421
421
  expect(output).toBe(
422
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/graphql"},\n data="{ key }"\n)\n\ndata = response.json()',
422
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/graphql"},\n data="{ key }"\n)\n\ndata = response.json()'
423
423
  );
424
424
  });
425
425
 
@@ -433,10 +433,10 @@ describe('python code sample generator', () => {
433
433
  body: 'key,value',
434
434
  };
435
435
 
436
- const output = generator!.generate(input);
436
+ const output = generator?.generate(input);
437
437
 
438
438
  expect(output).toBe(
439
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"text/csv"},\n data="key,value"\n)\n\ndata = response.json()',
439
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"text/csv"},\n data="key,value"\n)\n\ndata = response.json()'
440
440
  );
441
441
  });
442
442
 
@@ -450,10 +450,10 @@ describe('python code sample generator', () => {
450
450
  body: 'file',
451
451
  };
452
452
 
453
- const output = generator!.generate(input);
453
+ const output = generator?.generate(input);
454
454
 
455
455
  expect(output).toBe(
456
- 'import requests\n\nfiles = {\n "file": "file",\n}\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/pdf"},\n files=files\n)\n\ndata = response.json()',
456
+ 'import requests\n\nfiles = {\n "file": "file",\n}\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"application/pdf"},\n files=files\n)\n\ndata = response.json()'
457
457
  );
458
458
  });
459
459
 
@@ -467,10 +467,10 @@ describe('python code sample generator', () => {
467
467
  body: 'value',
468
468
  };
469
469
 
470
- const output = generator!.generate(input);
470
+ const output = generator?.generate(input);
471
471
 
472
472
  expect(output).toBe(
473
- 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"text/plain"},\n data="value"\n)\n\ndata = response.json()',
473
+ 'import requests\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"text/plain"},\n data="value"\n)\n\ndata = response.json()'
474
474
  );
475
475
  });
476
476
 
@@ -486,10 +486,10 @@ describe('python code sample generator', () => {
486
486
  },
487
487
  };
488
488
 
489
- const output = generator!.generate(input);
489
+ const output = generator?.generate(input);
490
490
 
491
491
  expect(output).toBe(
492
- 'import requests\n\nfiles = {\n "key": "value",\n}\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"multipart/form-data"},\n files=files\n)\n\ndata = response.json()',
492
+ 'import requests\n\nfiles = {\n "key": "value",\n}\n\nresponse = requests.get(\n "https://example.com/path",\n headers={"Content-Type":"multipart/form-data"},\n files=files\n)\n\ndata = response.json()'
493
493
  );
494
494
  });
495
495
  });
@@ -511,10 +511,10 @@ describe('http code sample generator', () => {
511
511
  },
512
512
  };
513
513
 
514
- const output = generator!.generate(input);
514
+ const output = generator?.generate(input);
515
515
 
516
516
  expect(output).toBe(
517
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 15\nAccept: */*\n\n"key=value"',
517
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 15\nAccept: */*\n\n"key=value"'
518
518
  );
519
519
  });
520
520
 
@@ -530,10 +530,10 @@ describe('http code sample generator', () => {
530
530
  },
531
531
  };
532
532
 
533
- const output = generator!.generate(input);
533
+ const output = generator?.generate(input);
534
534
 
535
535
  expect(output).toBe(
536
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/json\nContent-Length: 15\nAccept: */*\n\n{\n "key": "value"\n}',
536
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/json\nContent-Length: 15\nAccept: */*\n\n{\n "key": "value"\n}'
537
537
  );
538
538
  });
539
539
 
@@ -547,10 +547,10 @@ describe('http code sample generator', () => {
547
547
  body: '<key>value</key>',
548
548
  };
549
549
 
550
- const output = generator!.generate(input);
550
+ const output = generator?.generate(input);
551
551
 
552
552
  expect(output).toBe(
553
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/xml\nContent-Length: 18\nAccept: */*\n\n"<key>value</key>"',
553
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/xml\nContent-Length: 18\nAccept: */*\n\n"<key>value</key>"'
554
554
  );
555
555
  });
556
556
 
@@ -564,10 +564,10 @@ describe('http code sample generator', () => {
564
564
  body: '{ key }',
565
565
  };
566
566
 
567
- const output = generator!.generate(input);
567
+ const output = generator?.generate(input);
568
568
 
569
569
  expect(output).toBe(
570
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/graphql\nContent-Length: 9\nAccept: */*\n\n"{ key }"',
570
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/graphql\nContent-Length: 9\nAccept: */*\n\n"{ key }"'
571
571
  );
572
572
  });
573
573
 
@@ -581,10 +581,10 @@ describe('http code sample generator', () => {
581
581
  body: 'key,value',
582
582
  };
583
583
 
584
- const output = generator!.generate(input);
584
+ const output = generator?.generate(input);
585
585
 
586
586
  expect(output).toBe(
587
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: text/csv\nContent-Length: 11\nAccept: */*\n\n"key,value"',
587
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: text/csv\nContent-Length: 11\nAccept: */*\n\n"key,value"'
588
588
  );
589
589
  });
590
590
 
@@ -598,10 +598,10 @@ describe('http code sample generator', () => {
598
598
  body: 'file',
599
599
  };
600
600
 
601
- const output = generator!.generate(input);
601
+ const output = generator?.generate(input);
602
602
 
603
603
  expect(output).toBe(
604
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/pdf\nContent-Length: 6\nAccept: */*\n\n"file"',
604
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: application/pdf\nContent-Length: 6\nAccept: */*\n\n"file"'
605
605
  );
606
606
  });
607
607
 
@@ -615,10 +615,10 @@ describe('http code sample generator', () => {
615
615
  body: 'value',
616
616
  };
617
617
 
618
- const output = generator!.generate(input);
618
+ const output = generator?.generate(input);
619
619
 
620
620
  expect(output).toBe(
621
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: text/plain\nContent-Length: 7\nAccept: */*\n\n"value"',
621
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: text/plain\nContent-Length: 7\nAccept: */*\n\n"value"'
622
622
  );
623
623
  });
624
624
 
@@ -634,10 +634,10 @@ describe('http code sample generator', () => {
634
634
  },
635
635
  };
636
636
 
637
- const output = generator!.generate(input);
637
+ const output = generator?.generate(input);
638
638
 
639
639
  expect(output).toBe(
640
- 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: multipart/form-data\nContent-Length: 15\nAccept: */*\n\n{\n "key": "value"\n}',
640
+ 'GET /path HTTP/1.1\nHost: example.com\nContent-Type: multipart/form-data\nContent-Length: 15\nAccept: */*\n\n{\n "key": "value"\n}'
641
641
  );
642
642
  });
643
643
  });
@@ -1,12 +1,12 @@
1
1
  import {
2
+ isCSV,
2
3
  isFormData,
3
- isPDF,
4
4
  isFormUrlEncoded,
5
- isText,
6
- isXML,
7
- isCSV,
8
5
  isGraphQL,
6
+ isPDF,
9
7
  isPlainObject,
8
+ isText,
9
+ isXML,
10
10
  } from './contentTypeChecks';
11
11
  import { stringifyOpenAPI } from './stringifyOpenAPI';
12
12
 
@@ -95,8 +95,8 @@ export const codeSampleGenerators: CodeSampleGenerator[] = [
95
95
  code += indent(`body: ${body}\n`, 4);
96
96
  }
97
97
 
98
- code += `});\n\n`;
99
- code += `const data = await response.json();`;
98
+ code += '});\n\n';
99
+ code += 'const data = await response.json();';
100
100
 
101
101
  return code;
102
102
  },
@@ -135,7 +135,7 @@ export const codeSampleGenerators: CodeSampleGenerator[] = [
135
135
  }
136
136
 
137
137
  code += ')\n\n';
138
- code += `data = response.json()`;
138
+ code += 'data = response.json()';
139
139
  return code;
140
140
  },
141
141
  },
@@ -169,11 +169,11 @@ export const codeSampleGenerators: CodeSampleGenerator[] = [
169
169
  }
170
170
 
171
171
  const headerString = headers
172
- ? Object.entries(headers)
172
+ ? `${Object.entries(headers)
173
173
  .map(([key, value]) =>
174
- key.toLowerCase() !== 'host' ? `${key}: ${value}` : ``,
174
+ key.toLowerCase() !== 'host' ? `${key}: ${value}` : ''
175
175
  )
176
- .join('\n') + '\n'
176
+ .join('\n')}\n`
177
177
  : '';
178
178
 
179
179
  const bodyString = body ? `\n${body}` : '';
@@ -200,7 +200,7 @@ export function parseHostAndPath(url: string) {
200
200
  const urlObj = new URL(url);
201
201
  const path = urlObj.pathname || '/';
202
202
  return { host: urlObj.host, path };
203
- } catch (e) {
203
+ } catch (_e) {
204
204
  // If the URL was invalid do our best to parse the URL.
205
205
  // Check for the protocol part and pull it off to grab the host
206
206
  const splitted = url.split('//');
@@ -211,7 +211,7 @@ export function parseHostAndPath(url: string) {
211
211
  // pull off the host (mutates)
212
212
  const host = parts.shift();
213
213
  // add a leading slash and join the paths again
214
- const path = '/' + parts.join('/');
214
+ const path = `/${parts.join('/')}`;
215
215
 
216
216
  return { host, path };
217
217
  }
@@ -332,7 +332,7 @@ const BodyGenerators = {
332
332
  code += 'files = {\n';
333
333
  if (isPlainObject(body)) {
334
334
  Object.entries(body).forEach(([key, value]) => {
335
- code += indent(`"${key}": "${String(value)}",`, 4) + '\n';
335
+ code += `${indent(`"${key}": "${String(value)}",`, 4)}\n`;
336
336
  });
337
337
  }
338
338
  code += '}\n\n';
@@ -341,7 +341,7 @@ const BodyGenerators = {
341
341
 
342
342
  if (isPDF(contentType)) {
343
343
  code += 'files = {\n';
344
- code += indent(`"file": "${body}",`, 4) + '\n';
344
+ code += `${indent(`"file": "${body}",`, 4)}\n`;
345
345
  code += '}\n\n';
346
346
  body = 'files';
347
347
  }
@@ -14,7 +14,7 @@ type GenerateSchemaExampleOptions = Pick<
14
14
  */
15
15
  export function generateSchemaExample(
16
16
  schema: OpenAPIV3.SchemaObject,
17
- options?: GenerateSchemaExampleOptions,
17
+ options?: GenerateSchemaExampleOptions
18
18
  ): JSONValue | undefined {
19
19
  return getExampleFromSchema(
20
20
  schema,
@@ -35,7 +35,7 @@ export function generateSchemaExample(
35
35
  },
36
36
  ...options,
37
37
  },
38
- 3, // Max depth for circular references
38
+ 3 // Max depth for circular references
39
39
  );
40
40
  }
41
41
 
@@ -44,7 +44,7 @@ export function generateSchemaExample(
44
44
  */
45
45
  export function generateMediaTypeExample(
46
46
  mediaType: OpenAPIV3.MediaTypeObject,
47
- options?: GenerateSchemaExampleOptions,
47
+ options?: GenerateSchemaExampleOptions
48
48
  ): JSONValue | undefined {
49
49
  if (mediaType.example) {
50
50
  return mediaType.example;
@@ -19,7 +19,7 @@ describe('getUrlFromServerState', () => {
19
19
  });
20
20
 
21
21
  expect(xml).toBe(
22
- '<?xml version="1.0"?>\n<urls>\n\t<url>https://example.com</url>\n\t<url>https://example.com</url>\n</urls>\n',
22
+ '<?xml version="1.0"?>\n<urls>\n\t<url>https://example.com</url>\n\t<url>https://example.com</url>\n</urls>\n'
23
23
  );
24
24
  });
25
25
 
@@ -1,7 +1,7 @@
1
- import { it, expect, describe } from 'bun:test';
1
+ import { describe, expect, it } from 'bun:test';
2
2
 
3
- import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
4
3
  import { parseOpenAPI, traverse } from '@gitbook/openapi-parser';
4
+ import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
5
5
 
6
6
  async function fetchFilesystem(url: string) {
7
7
  const response = await fetch(url);
@@ -19,7 +19,7 @@ async function fetchFilesystem(url: string) {
19
19
  describe('#resolveOpenAPIOperation', () => {
20
20
  it('should resolve refs', async () => {
21
21
  const filesystem = await fetchFilesystem(
22
- 'https://petstore3.swagger.io/api/v3/openapi.json',
22
+ 'https://petstore3.swagger.io/api/v3/openapi.json'
23
23
  );
24
24
  const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
25
25
 
@@ -49,7 +49,7 @@ describe('#resolveOpenAPIOperation', () => {
49
49
 
50
50
  it('should support yaml', async () => {
51
51
  const filesystem = await fetchFilesystem(
52
- 'https://petstore3.swagger.io/api/v3/openapi.yaml',
52
+ 'https://petstore3.swagger.io/api/v3/openapi.yaml'
53
53
  );
54
54
  const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
55
55
 
@@ -98,7 +98,7 @@ describe('#resolveOpenAPIOperation', () => {
98
98
 
99
99
  it('should resolve to null if the method is not supported', async () => {
100
100
  const filesystem = await fetchFilesystem(
101
- 'https://petstore3.swagger.io/api/v3/openapi.json',
101
+ 'https://petstore3.swagger.io/api/v3/openapi.json'
102
102
  );
103
103
  const resolved = await resolveOpenAPIOperation(filesystem, {
104
104
  method: 'dontexist',
@@ -144,7 +144,7 @@ describe('#resolveOpenAPIOperation', () => {
144
144
 
145
145
  it('should resolve a ref with whitespace', async () => {
146
146
  const filesystem = await fetchFilesystem(
147
- ' https://petstore3.swagger.io/api/v3/openapi.json',
147
+ ' https://petstore3.swagger.io/api/v3/openapi.json'
148
148
  );
149
149
  const resolved = await resolveOpenAPIOperation(filesystem, {
150
150
  method: 'put',
@@ -1,13 +1,13 @@
1
- import { toJSON, fromJSON } from 'flatted';
1
+ import { fromJSON, toJSON } from 'flatted';
2
2
 
3
3
  import {
4
- type OpenAPIV3xDocument,
5
4
  type Filesystem,
6
5
  type OpenAPIV3,
7
6
  type OpenAPIV3_1,
7
+ type OpenAPIV3xDocument,
8
8
  dereference,
9
9
  } from '@gitbook/openapi-parser';
10
- import { OpenAPIOperationData } from './types';
10
+ import type { OpenAPIOperationData } from './types';
11
11
  import { checkIsReference } from './utils';
12
12
 
13
13
  export { toJSON, fromJSON };
@@ -20,7 +20,7 @@ export async function resolveOpenAPIOperation(
20
20
  operationDescriptor: {
21
21
  path: string;
22
22
  method: string;
23
- },
23
+ }
24
24
  ): Promise<OpenAPIOperationData | null> {
25
25
  const { path, method } = operationDescriptor;
26
26
  const schema = await memoDereferenceFilesystem(filesystem);
@@ -102,7 +102,7 @@ async function dereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3x
102
102
  */
103
103
  function getPathObject(
104
104
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
105
- path: string,
105
+ path: string
106
106
  ): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
107
107
  if (schema.paths?.[path]) {
108
108
  return schema.paths[path];
@@ -115,7 +115,7 @@ function getPathObject(
115
115
  */
116
116
  function getPathObjectParameter(
117
117
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
118
- path: string,
118
+ path: string
119
119
  ):
120
120
  | (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
121
121
  | (OpenAPIV3.ParameterObject | OpenAPIV3_1.ReferenceObject)[]
@@ -133,7 +133,7 @@ function getPathObjectParameter(
133
133
  function getOperationByPathAndMethod(
134
134
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
135
135
  path: string,
136
- method: string,
136
+ method: string
137
137
  ): OpenAPIV3.OperationObject | null {
138
138
  // Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
139
139
  const pathObject = getPathObject(schema, path);
@@ -12,6 +12,6 @@ export function stringifyOpenAPI(body: unknown, _?: null, indent?: number): stri
12
12
 
13
13
  return value;
14
14
  },
15
- indent,
15
+ indent
16
16
  );
17
17
  }