fumadocs-openapi 10.4.1 → 10.6.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.
- package/css/generated/shared.css +34 -22
- package/dist/generate-file.d.ts +21 -3
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +74 -28
- package/dist/generate-file.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/playground/client.d.ts +27 -7
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +51 -44
- package/dist/playground/client.js.map +1 -1
- package/dist/playground/components/inputs.js +1 -1
- package/dist/playground/components/inputs.js.map +1 -1
- package/dist/playground/components/server-select.js +3 -4
- package/dist/playground/components/server-select.js.map +1 -1
- package/dist/playground/index.d.ts +1 -1
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +2 -2
- package/dist/playground/index.js.map +1 -1
- package/dist/playground/schema.d.ts +0 -1
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +11 -13
- package/dist/playground/schema.js.map +1 -1
- package/dist/requests/generators/python.d.ts +2 -1
- package/dist/requests/generators/python.d.ts.map +1 -1
- package/dist/requests/generators/python.js +13 -2
- package/dist/requests/generators/python.js.map +1 -1
- package/dist/requests/media/adapter.js +1 -1
- package/dist/requests/string-utils.js +1 -1
- package/dist/scalar/index.d.ts +2 -1
- package/dist/scalar/index.d.ts.map +1 -1
- package/dist/server/create.d.ts +2 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +11 -8
- package/dist/server/create.js.map +1 -1
- package/dist/server/source-api.d.ts +9 -3
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/server/source-api.js +65 -6
- package/dist/server/source-api.js.map +1 -1
- package/dist/types.d.ts +2 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts +2 -2
- package/dist/ui/api-page.d.ts.map +1 -1
- package/dist/ui/api-page.js +4 -6
- package/dist/ui/api-page.js.map +1 -1
- package/dist/ui/base.d.ts +20 -16
- package/dist/ui/base.d.ts.map +1 -1
- package/dist/ui/base.js +18 -9
- package/dist/ui/base.js.map +1 -1
- package/dist/ui/{full.client.js → client/full.js} +3 -3
- package/dist/ui/client/full.js.map +1 -0
- package/dist/ui/client/index.d.ts +1 -1
- package/dist/ui/client/index.js.map +1 -1
- package/dist/ui/client/storage-key.js.map +1 -1
- package/dist/ui/components/server-tab.js +43 -0
- package/dist/ui/components/server-tab.js.map +1 -0
- package/dist/ui/contexts/api.js +18 -35
- package/dist/ui/contexts/api.js.map +1 -1
- package/dist/ui/create-client.d.ts +26 -0
- package/dist/ui/create-client.d.ts.map +1 -0
- package/dist/ui/create-client.js +132 -0
- package/dist/ui/create-client.js.map +1 -0
- package/dist/ui/index.d.ts +10 -2
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +21 -1
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/operation/client.js +44 -36
- package/dist/ui/operation/client.js.map +1 -1
- package/dist/ui/operation/{request-tabs.d.ts → get-example-requests.d.ts} +2 -3
- package/dist/ui/operation/get-example-requests.d.ts.map +1 -0
- package/dist/ui/operation/get-example-requests.js +83 -0
- package/dist/ui/operation/get-example-requests.js.map +1 -0
- package/dist/ui/operation/index.js +101 -63
- package/dist/ui/operation/index.js.map +1 -1
- package/dist/ui/operation/request-tabs.js +3 -81
- package/dist/ui/operation/request-tabs.js.map +1 -1
- package/dist/ui/operation/response-tabs.d.ts +1 -1
- package/dist/ui/operation/response-tabs.js +57 -54
- package/dist/ui/operation/response-tabs.js.map +1 -1
- package/dist/ui/operation/usage-tabs/client.js +7 -48
- package/dist/ui/operation/usage-tabs/client.js.map +1 -1
- package/dist/ui/operation/usage-tabs/index.js +14 -10
- package/dist/ui/operation/usage-tabs/index.js.map +1 -1
- package/dist/ui/operation/usage-tabs/lazy.js +1 -2
- package/dist/ui/operation/usage-tabs/lazy.js.map +1 -1
- package/dist/ui/schema/client.d.ts +1 -0
- package/dist/ui/schema/client.d.ts.map +1 -1
- package/dist/ui/schema/index.d.ts +2 -1
- package/dist/ui/schema/index.d.ts.map +1 -1
- package/dist/ui/schema/index.js +4 -2
- package/dist/ui/schema/index.js.map +1 -1
- package/dist/utils/pages/builder.d.ts +10 -11
- package/dist/utils/pages/builder.d.ts.map +1 -1
- package/dist/utils/pages/builder.js +30 -31
- package/dist/utils/pages/builder.js.map +1 -1
- package/dist/utils/pages/preset-auto.d.ts +6 -5
- package/dist/utils/pages/preset-auto.d.ts.map +1 -1
- package/dist/utils/pages/preset-auto.js +97 -35
- package/dist/utils/pages/preset-auto.js.map +1 -1
- package/dist/utils/pages/to-text.d.ts.map +1 -1
- package/dist/utils/pages/to-text.js +4 -12
- package/dist/utils/pages/to-text.js.map +1 -1
- package/dist/utils/process-document.d.ts +1 -1
- package/dist/utils/process-document.js +1 -32
- package/dist/utils/process-document.js.map +1 -1
- package/dist/utils/schema/dereference.js +37 -0
- package/dist/utils/schema/dereference.js.map +1 -0
- package/dist/utils/{schema.d.ts → schema/index.d.ts} +3 -3
- package/dist/utils/schema/index.d.ts.map +1 -0
- package/dist/utils/{schema.js → schema/index.js} +3 -3
- package/dist/utils/schema/index.js.map +1 -0
- package/dist/utils/schema/resolve-ref.js +21 -0
- package/dist/utils/schema/resolve-ref.js.map +1 -0
- package/dist/utils/{schema-to-string.js → schema/to-string.js} +2 -2
- package/dist/utils/schema/to-string.js.map +1 -0
- package/package.json +10 -9
- package/dist/requests/to-python-object.js +0 -17
- package/dist/requests/to-python-object.js.map +0 -1
- package/dist/ui/full.client.js.map +0 -1
- package/dist/ui/full.d.ts +0 -11
- package/dist/ui/full.d.ts.map +0 -1
- package/dist/ui/full.js +0 -36
- package/dist/ui/full.js.map +0 -1
- package/dist/ui/operation/request-tabs.d.ts.map +0 -1
- package/dist/utils/pages/to-body.js +0 -22
- package/dist/utils/pages/to-body.js.map +0 -1
- package/dist/utils/schema-to-string.js.map +0 -1
- package/dist/utils/schema.d.ts.map +0 -1
- package/dist/utils/schema.js.map +0 -1
- /package/dist/utils/{schema-to-string.d.ts → schema/to-string.d.ts} +0 -0
package/css/generated/shared.css
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
@source inline("!last");
|
|
3
3
|
@source inline("*:data-[collapsible=true]:order-last");
|
|
4
4
|
@source inline("*:min-w-0");
|
|
5
|
+
@source inline("---");
|
|
5
6
|
@source inline("--fd-docs-row-1");
|
|
6
7
|
@source inline("--initial-height");
|
|
7
8
|
@source inline("-mode");
|
|
@@ -107,6 +108,7 @@
|
|
|
107
108
|
@source inline("border-x");
|
|
108
109
|
@source inline("border-y");
|
|
109
110
|
@source inline("both");
|
|
111
|
+
@source inline("bundled");
|
|
110
112
|
@source inline("but");
|
|
111
113
|
@source inline("button");
|
|
112
114
|
@source inline("buttonVariants");
|
|
@@ -138,6 +140,7 @@
|
|
|
138
140
|
@source inline("cloned");
|
|
139
141
|
@source inline("cn");
|
|
140
142
|
@source inline("code");
|
|
143
|
+
@source inline("codeProps");
|
|
141
144
|
@source inline("codeUsages");
|
|
142
145
|
@source inline("codegen");
|
|
143
146
|
@source inline("codegens");
|
|
@@ -194,10 +197,11 @@
|
|
|
194
197
|
@source inline("data-collapsible");
|
|
195
198
|
@source inline("data-object-search-input");
|
|
196
199
|
@source inline("data-placeholder:text-fd-muted-foreground");
|
|
200
|
+
@source inline("data-type");
|
|
197
201
|
@source inline("dataEngine");
|
|
198
202
|
@source inline("declare");
|
|
199
203
|
@source inline("default");
|
|
200
|
-
@source inline("
|
|
204
|
+
@source inline("defaultAdapters");
|
|
201
205
|
@source inline("defaultColor");
|
|
202
206
|
@source inline("defaultExampleId");
|
|
203
207
|
@source inline("defaultItem");
|
|
@@ -209,12 +213,13 @@
|
|
|
209
213
|
@source inline("definitions");
|
|
210
214
|
@source inline("deprecated");
|
|
211
215
|
@source inline("depth");
|
|
216
|
+
@source inline("dereferenceMap");
|
|
217
|
+
@source inline("dereferenceSync");
|
|
212
218
|
@source inline("dereferenced");
|
|
213
219
|
@source inline("description");
|
|
214
220
|
@source inline("descriptionNode");
|
|
215
221
|
@source inline("development");
|
|
216
222
|
@source inline("deviceAuthorization");
|
|
217
|
-
@source inline("directive");
|
|
218
223
|
@source inline("disable");
|
|
219
224
|
@source inline("disabled");
|
|
220
225
|
@source inline("disabled:cursor-not-allowed");
|
|
@@ -226,13 +231,13 @@
|
|
|
226
231
|
@source inline("divide-fd-border");
|
|
227
232
|
@source inline("divide-y");
|
|
228
233
|
@source inline("document");
|
|
234
|
+
@source inline("doesn");
|
|
229
235
|
@source inline("domain");
|
|
230
236
|
@source inline("duplicated");
|
|
231
237
|
@source inline("duration-200");
|
|
232
238
|
@source inline("dynamic");
|
|
233
239
|
@source inline("e");
|
|
234
240
|
@source inline("each");
|
|
235
|
-
@source inline("either");
|
|
236
241
|
@source inline("element");
|
|
237
242
|
@source inline("else");
|
|
238
243
|
@source inline("empty");
|
|
@@ -254,13 +259,13 @@
|
|
|
254
259
|
@source inline("eslint-disable-next-line");
|
|
255
260
|
@source inline("example");
|
|
256
261
|
@source inline("exampleId");
|
|
262
|
+
@source inline("exampleRequests");
|
|
257
263
|
@source inline("examples");
|
|
258
264
|
@source inline("exclusiveMax");
|
|
259
265
|
@source inline("exclusiveMin");
|
|
260
266
|
@source inline("expand");
|
|
261
267
|
@source inline("export");
|
|
262
268
|
@source inline("extends");
|
|
263
|
-
@source inline("extra");
|
|
264
269
|
@source inline("factory");
|
|
265
270
|
@source inline("fallback");
|
|
266
271
|
@source inline("false");
|
|
@@ -300,6 +305,8 @@
|
|
|
300
305
|
@source inline("focus:ring");
|
|
301
306
|
@source inline("focus:ring-fd-ring");
|
|
302
307
|
@source inline("focus:text-fd-accent-foreground");
|
|
308
|
+
@source inline("folder");
|
|
309
|
+
@source inline("folderStyle");
|
|
303
310
|
@source inline("font-medium");
|
|
304
311
|
@source inline("font-mono");
|
|
305
312
|
@source inline("font-semibold");
|
|
@@ -335,11 +342,13 @@
|
|
|
335
342
|
@source inline("generate");
|
|
336
343
|
@source inline("generateDefault");
|
|
337
344
|
@source inline("generateTypeScriptDefinitions");
|
|
345
|
+
@source inline("generateTypeScriptSchema");
|
|
338
346
|
@source inline("generated");
|
|
339
347
|
@source inline("generated/defined");
|
|
340
|
-
@source inline("generator");
|
|
341
348
|
@source inline("generators");
|
|
342
349
|
@source inline("getAPIPageProps");
|
|
350
|
+
@source inline("getClientAPIPageProps");
|
|
351
|
+
@source inline("getExampleRequests");
|
|
343
352
|
@source inline("getSchema");
|
|
344
353
|
@source inline("getSchemaId");
|
|
345
354
|
@source inline("getStatusInfo");
|
|
@@ -390,9 +399,9 @@
|
|
|
390
399
|
@source inline("idx");
|
|
391
400
|
@source inline("if");
|
|
392
401
|
@source inline("ignore");
|
|
402
|
+
@source inline("img");
|
|
393
403
|
@source inline("implicit");
|
|
394
404
|
@source inline("import");
|
|
395
|
-
@source inline("imported");
|
|
396
405
|
@source inline("imports");
|
|
397
406
|
@source inline("in");
|
|
398
407
|
@source inline("include");
|
|
@@ -431,6 +440,7 @@
|
|
|
431
440
|
@source inline("j");
|
|
432
441
|
@source inline("json");
|
|
433
442
|
@source inline("json-schema-typed");
|
|
443
|
+
@source inline("json-schema-typed/draft-2020-12");
|
|
434
444
|
@source inline("justify-between");
|
|
435
445
|
@source inline("justify-center");
|
|
436
446
|
@source inline("k");
|
|
@@ -441,7 +451,6 @@
|
|
|
441
451
|
@source inline("labelVariants");
|
|
442
452
|
@source inline("lang");
|
|
443
453
|
@source inline("langs");
|
|
444
|
-
@source inline("language");
|
|
445
454
|
@source inline("last");
|
|
446
455
|
@source inline("last:border-b");
|
|
447
456
|
@source inline("last:border-b-0");
|
|
@@ -470,16 +479,20 @@
|
|
|
470
479
|
@source inline("max-w-[600px]");
|
|
471
480
|
@source inline("max-w-full");
|
|
472
481
|
@source inline("max-w-lg");
|
|
482
|
+
@source inline("may");
|
|
473
483
|
@source inline("mb-2");
|
|
474
484
|
@source inline("mb-4");
|
|
475
485
|
@source inline("md");
|
|
486
|
+
@source inline("mdxComponents");
|
|
476
487
|
@source inline("me-auto");
|
|
477
488
|
@source inline("media");
|
|
478
489
|
@source inline("mediaAdapters");
|
|
479
490
|
@source inline("mediaType");
|
|
480
491
|
@source inline("merge");
|
|
481
492
|
@source inline("mergeAllOf");
|
|
493
|
+
@source inline("merged");
|
|
482
494
|
@source inline("message");
|
|
495
|
+
@source inline("meta");
|
|
483
496
|
@source inline("metaData");
|
|
484
497
|
@source inline("method");
|
|
485
498
|
@source inline("min");
|
|
@@ -516,6 +529,8 @@
|
|
|
516
529
|
@source inline("next-themes");
|
|
517
530
|
@source inline("no-cache");
|
|
518
531
|
@source inline("node");
|
|
532
|
+
@source inline("node:path");
|
|
533
|
+
@source inline("non-RSC");
|
|
519
534
|
@source inline("non-string");
|
|
520
535
|
@source inline("not");
|
|
521
536
|
@source inline("not-last:pb-0");
|
|
@@ -575,13 +590,13 @@
|
|
|
575
590
|
@source inline("page");
|
|
576
591
|
@source inline("pageData");
|
|
577
592
|
@source inline("pages");
|
|
578
|
-
@source inline("panels");
|
|
579
593
|
@source inline("param");
|
|
580
594
|
@source inline("paramTypeKeys");
|
|
581
595
|
@source inline("parameter");
|
|
582
596
|
@source inline("parameterNode");
|
|
583
597
|
@source inline("parameters");
|
|
584
598
|
@source inline("params");
|
|
599
|
+
@source inline("parent");
|
|
585
600
|
@source inline("parsed");
|
|
586
601
|
@source inline("parsedState");
|
|
587
602
|
@source inline("parts");
|
|
@@ -590,13 +605,13 @@
|
|
|
590
605
|
@source inline("password");
|
|
591
606
|
@source inline("path");
|
|
592
607
|
@source inline("pathItem");
|
|
593
|
-
@source inline("pathItems");
|
|
594
608
|
@source inline("pathName");
|
|
595
609
|
@source inline("pathNodes");
|
|
596
610
|
@source inline("pathParameters");
|
|
597
611
|
@source inline("paths");
|
|
598
612
|
@source inline("pattern");
|
|
599
613
|
@source inline("patternProperties");
|
|
614
|
+
@source inline("payload");
|
|
600
615
|
@source inline("pb-0");
|
|
601
616
|
@source inline("pb-2");
|
|
602
617
|
@source inline("pe-2");
|
|
@@ -610,7 +625,6 @@
|
|
|
610
625
|
@source inline("placeholder:text-fd-muted-foreground");
|
|
611
626
|
@source inline("placeholders");
|
|
612
627
|
@source inline("playground");
|
|
613
|
-
@source inline("playground/index.tsx");
|
|
614
628
|
@source inline("playgroundEnabled");
|
|
615
629
|
@source inline("playgrounds");
|
|
616
630
|
@source inline("please");
|
|
@@ -618,7 +632,6 @@
|
|
|
618
632
|
@source inline("position");
|
|
619
633
|
@source inline("pre");
|
|
620
634
|
@source inline("prefix");
|
|
621
|
-
@source inline("preprocessed");
|
|
622
635
|
@source inline("prev");
|
|
623
636
|
@source inline("prevProperties");
|
|
624
637
|
@source inline("prevent");
|
|
@@ -627,7 +640,6 @@
|
|
|
627
640
|
@source inline("primitive");
|
|
628
641
|
@source inline("processed");
|
|
629
642
|
@source inline("processor");
|
|
630
|
-
@source inline("programming");
|
|
631
643
|
@source inline("prop");
|
|
632
644
|
@source inline("properties");
|
|
633
645
|
@source inline("property");
|
|
@@ -662,6 +674,7 @@
|
|
|
662
674
|
@source inline("react");
|
|
663
675
|
@source inline("react-hook-form");
|
|
664
676
|
@source inline("react-hooks/exhaustive-deps");
|
|
677
|
+
@source inline("react-hooks/rules-of-hooks");
|
|
665
678
|
@source inline("react/jsx-runtime");
|
|
666
679
|
@source inline("read");
|
|
667
680
|
@source inline("readOnly");
|
|
@@ -677,6 +690,7 @@
|
|
|
677
690
|
@source inline("registered");
|
|
678
691
|
@source inline("registry");
|
|
679
692
|
@source inline("rehype-react");
|
|
693
|
+
@source inline("relativePath");
|
|
680
694
|
@source inline("remark");
|
|
681
695
|
@source inline("remark-rehype");
|
|
682
696
|
@source inline("remarkGfm");
|
|
@@ -687,7 +701,6 @@
|
|
|
687
701
|
@source inline("render");
|
|
688
702
|
@source inline("renderAPIExampleLayout");
|
|
689
703
|
@source inline("renderAPIExampleUsageTabs");
|
|
690
|
-
@source inline("renderBodyField");
|
|
691
704
|
@source inline("renderOperationLayout");
|
|
692
705
|
@source inline("renderPageLayout");
|
|
693
706
|
@source inline("renderParameterField");
|
|
@@ -712,12 +725,11 @@
|
|
|
712
725
|
@source inline("requests");
|
|
713
726
|
@source inline("required");
|
|
714
727
|
@source inline("res");
|
|
715
|
-
@source inline("resType");
|
|
716
728
|
@source inline("reset");
|
|
717
729
|
@source inline("resize-none");
|
|
718
|
-
@source inline("resolution");
|
|
719
730
|
@source inline("resolve");
|
|
720
731
|
@source inline("resolveMediaAdapter");
|
|
732
|
+
@source inline("resolveRefSync");
|
|
721
733
|
@source inline("resolveRequestData");
|
|
722
734
|
@source inline("resolved");
|
|
723
735
|
@source inline("resolvedTheme");
|
|
@@ -733,6 +745,7 @@
|
|
|
733
745
|
@source inline("rest");
|
|
734
746
|
@source inline("result");
|
|
735
747
|
@source inline("return");
|
|
748
|
+
@source inline("returned");
|
|
736
749
|
@source inline("root");
|
|
737
750
|
@source inline("rotate-90");
|
|
738
751
|
@source inline("rounded-lg");
|
|
@@ -782,13 +795,14 @@
|
|
|
782
795
|
@source inline("selector");
|
|
783
796
|
@source inline("selectorNode");
|
|
784
797
|
@source inline("sep");
|
|
798
|
+
@source inline("separator");
|
|
785
799
|
@source inline("server");
|
|
786
800
|
@source inline("server-side");
|
|
787
801
|
@source inline("server-url");
|
|
788
802
|
@source inline("serverContext");
|
|
789
|
-
@source inline("serverRef");
|
|
790
803
|
@source inline("serverSchema");
|
|
791
804
|
@source inline("servers");
|
|
805
|
+
@source inline("set");
|
|
792
806
|
@source inline("setData");
|
|
793
807
|
@source inline("setError");
|
|
794
808
|
@source inline("setExample");
|
|
@@ -834,6 +848,7 @@
|
|
|
834
848
|
@source inline("slot");
|
|
835
849
|
@source inline("slotType");
|
|
836
850
|
@source inline("slots");
|
|
851
|
+
@source inline("slug");
|
|
837
852
|
@source inline("slugger");
|
|
838
853
|
@source inline("sm");
|
|
839
854
|
@source inline("sm:flex-row");
|
|
@@ -841,7 +856,6 @@
|
|
|
841
856
|
@source inline("sm:justify-end");
|
|
842
857
|
@source inline("sm:text-start");
|
|
843
858
|
@source inline("so");
|
|
844
|
-
@source inline("source");
|
|
845
859
|
@source inline("spec");
|
|
846
860
|
@source inline("specify");
|
|
847
861
|
@source inline("stack");
|
|
@@ -859,6 +873,7 @@
|
|
|
859
873
|
@source inline("step");
|
|
860
874
|
@source inline("stf");
|
|
861
875
|
@source inline("sticky");
|
|
876
|
+
@source inline("storageKey");
|
|
862
877
|
@source inline("storageKeyPrefix");
|
|
863
878
|
@source inline("storageKeys");
|
|
864
879
|
@source inline("store");
|
|
@@ -871,15 +886,14 @@
|
|
|
871
886
|
@source inline("submit");
|
|
872
887
|
@source inline("such");
|
|
873
888
|
@source inline("summary");
|
|
889
|
+
@source inline("support");
|
|
874
890
|
@source inline("supported");
|
|
875
|
-
@source inline("swallow");
|
|
876
891
|
@source inline("switch");
|
|
877
892
|
@source inline("t");
|
|
878
893
|
@source inline("tab");
|
|
879
894
|
@source inline("tabs");
|
|
880
895
|
@source inline("tag");
|
|
881
896
|
@source inline("takenIds");
|
|
882
|
-
@source inline("targetServer");
|
|
883
897
|
@source inline("testQuery");
|
|
884
898
|
@source inline("text");
|
|
885
899
|
@source inline("text-[0.8125rem]");
|
|
@@ -924,7 +938,6 @@
|
|
|
924
938
|
@source inline("titleRequestTabs");
|
|
925
939
|
@source inline("titleResponseBody");
|
|
926
940
|
@source inline("to");
|
|
927
|
-
@source inline("toBody");
|
|
928
941
|
@source inline("toJsxRuntime");
|
|
929
942
|
@source inline("toStaticData");
|
|
930
943
|
@source inline("toc");
|
|
@@ -972,18 +985,17 @@
|
|
|
972
985
|
@source inline("useApiClientModal");
|
|
973
986
|
@source inline("useApiContext");
|
|
974
987
|
@source inline("useCopyButton");
|
|
975
|
-
@source inline("useExampleRequests");
|
|
976
988
|
@source inline("useFieldValue");
|
|
977
989
|
@source inline("useForm");
|
|
978
990
|
@source inline("useI18n");
|
|
979
991
|
@source inline("useMemo");
|
|
980
992
|
@source inline("useNamespace");
|
|
981
993
|
@source inline("useObject");
|
|
994
|
+
@source inline("useOperationContext");
|
|
982
995
|
@source inline("useQuery");
|
|
983
996
|
@source inline("useRef");
|
|
984
997
|
@source inline("useResolvedSchema");
|
|
985
998
|
@source inline("useServerContext");
|
|
986
|
-
@source inline("useServerSelectContext");
|
|
987
999
|
@source inline("useState");
|
|
988
1000
|
@source inline("useStf");
|
|
989
1001
|
@source inline("useStorageKey");
|
package/dist/generate-file.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { OpenAPIServer } from "./server/create.js";
|
|
2
2
|
import { OutputEntry } from "./utils/pages/builder.js";
|
|
3
3
|
import { SchemaToPagesOptions } from "./utils/pages/preset-auto.js";
|
|
4
|
+
import { DistributiveOmit } from "./types.js";
|
|
4
5
|
import { ProcessedDocument } from "./utils/process-document.js";
|
|
5
6
|
import { PagesToTextOptions } from "./utils/pages/to-text.js";
|
|
6
7
|
|
|
@@ -23,13 +24,14 @@ interface IndexConfig {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
interface IndexItem {
|
|
27
|
+
/** output path of index page */
|
|
26
28
|
path: string;
|
|
27
29
|
title?: string;
|
|
28
30
|
description?: string;
|
|
29
31
|
/**
|
|
30
32
|
* Specify linked pages:
|
|
31
33
|
* - items in `inputs` to include all generated pages of a specific schema.
|
|
32
|
-
* -
|
|
34
|
+
* - file paths (using forward slash).
|
|
33
35
|
*/
|
|
34
36
|
only?: string[];
|
|
35
37
|
}
|
|
@@ -46,19 +48,35 @@ interface GenerateFilesConfig extends PagesToTextOptions {
|
|
|
46
48
|
* Generate index files with cards linking to generated pages.
|
|
47
49
|
*/
|
|
48
50
|
index?: IndexConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Generate `meta.json` files.
|
|
53
|
+
*
|
|
54
|
+
* Note: for flexibility, it's recommended to define them on your own.
|
|
55
|
+
*/
|
|
56
|
+
meta?: boolean | MetaOptions;
|
|
49
57
|
/**
|
|
50
58
|
* Can add/change/remove output files before writing to file system
|
|
51
59
|
**/
|
|
52
60
|
beforeWrite?: (this: BeforeWriteContext, files: OutputFile[]) => void | Promise<void>;
|
|
53
61
|
}
|
|
54
|
-
|
|
62
|
+
interface MetaOptions {
|
|
63
|
+
groupStyle?: 'folder' | 'separator';
|
|
64
|
+
}
|
|
65
|
+
type Config = SchemaToPagesOptions & GenerateFilesConfig & {
|
|
66
|
+
/**
|
|
67
|
+
* Re-generate when **schema files are changed**, ignores custom input functions & URLs.
|
|
68
|
+
*
|
|
69
|
+
* Note: it is recommended to configure & use `chokidar` on your own, this is only for simple cases.
|
|
70
|
+
*/
|
|
71
|
+
watch?: boolean;
|
|
72
|
+
};
|
|
55
73
|
interface BeforeWriteContext {
|
|
56
74
|
readonly generated: Record<string, OutputFile[]>;
|
|
57
75
|
readonly generatedEntries: Record<string, OutputEntry[]>;
|
|
58
76
|
readonly documents: Record<string, ProcessedDocument>;
|
|
59
77
|
}
|
|
60
78
|
declare function generateFiles(options: Config): Promise<void>;
|
|
61
|
-
declare function generateFilesOnly(options:
|
|
79
|
+
declare function generateFilesOnly(options: DistributiveOmit<Config, 'output'>): Promise<OutputFile[]>;
|
|
62
80
|
//#endregion
|
|
63
81
|
export { Config, OutputFile, generateFiles, generateFilesOnly };
|
|
64
82
|
//# sourceMappingURL=generate-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-file.d.ts","names":[],"sources":["../src/generate-file.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-file.d.ts","names":[],"sources":["../src/generate-file.ts"],"mappings":";;;;;;;;UAUiB,UAAA;EACf,IAAA;EACA,OAAA;AAAA;AAAA,UAGQ,WAAA;EACR,KAAA,EAAO,SAAA,OAAgB,GAAA,EAAK,kBAAA,KAAuB,SAAA;EALnD;;AAED;EAQC,GAAA,IACM,QAAA;IAEA,OAAA;IARC;;;IAYD,UAAA;EAAA;AAAA;AAAA,UAIE,SAAA;EAhBoB;EAkB5B,IAAA;EACA,KAAA;EACA,WAAA;EAdM;;;;;EAqBN,IAAA;AAAA;AAAA,UAGQ,mBAAA,SAA4B,kBAAA;EAdnB;;;EAkBjB,KAAA,EAAO,aAAA;EAPP;;;EAYA,MAAA;EAT4B;;;EAc5B,KAAA,GAAQ,WAAA;EAOS;;;;;EAAjB,IAAA,aAAiB,WAAA;EArBqC;;;EA0BtD,WAAA,IAAe,IAAA,EAAM,kBAAA,EAAoB,KAAA,EAAO,UAAA,cAAwB,OAAA;AAAA;AAAA,UAGhE,WAAA;EACR,UAAA;AAAA;AAAA,KAGU,MAAA,GAAS,oBAAA,GACnB,mBAAA;EARA;;;;;EAcE,KAAA;AAAA;AAAA,UAGM,kBAAA;EAAA,SACC,SAAA,EAAW,MAAA,SAAe,UAAA;EAAA,SAC1B,gBAAA,EAAkB,MAAA,SAAe,WAAA;EAAA,SACjC,SAAA,EAAW,MAAA,SAAe,iBAAA;AAAA;AAAA,iBAGf,aAAA,CAAc,OAAA,EAAS,MAAA,GAAS,OAAA;AAAA,iBA2BhC,iBAAA,CACpB,OAAA,EAAS,gBAAA,CAAiB,MAAA,cACzB,OAAA,CAAQ,UAAA"}
|
package/dist/generate-file.js
CHANGED
|
@@ -2,15 +2,26 @@ import { generateDocument, toText } from "./utils/pages/to-text.js";
|
|
|
2
2
|
import { createAutoPreset } from "./utils/pages/preset-auto.js";
|
|
3
3
|
import { fromSchema } from "./utils/pages/builder.js";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import { createGetUrl, getSlugs } from "fumadocs-core/source";
|
|
5
|
+
import * as path$1 from "node:path";
|
|
6
|
+
import { PathUtils, createGetUrl, getSlugs } from "fumadocs-core/source";
|
|
7
7
|
//#region src/generate-file.ts
|
|
8
8
|
async function generateFiles(options) {
|
|
9
|
+
if (options.watch) {
|
|
10
|
+
const { watch } = await import("chokidar");
|
|
11
|
+
const subOptions = {
|
|
12
|
+
...options,
|
|
13
|
+
watch: false
|
|
14
|
+
};
|
|
15
|
+
await generateFiles(subOptions);
|
|
16
|
+
const targets = options.input._getWatchPaths();
|
|
17
|
+
console.log(`[Fumadocs OpenAPI] watching ${targets.join(", ")}`);
|
|
18
|
+
watch(targets, { ignoreInitial: true }).on("all", () => generateFiles(subOptions));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
9
21
|
const files = await generateFilesOnly(options);
|
|
10
|
-
const { output } = options;
|
|
11
22
|
await Promise.all(files.map(async (file) => {
|
|
12
|
-
const filePath = path.join(output, file.path);
|
|
13
|
-
await mkdir(path.dirname(filePath), { recursive: true });
|
|
23
|
+
const filePath = path$1.join(options.output, file.path);
|
|
24
|
+
await mkdir(path$1.dirname(filePath), { recursive: true });
|
|
14
25
|
await writeFile(filePath, file.content);
|
|
15
26
|
console.log(`Generated: ${filePath}`);
|
|
16
27
|
}));
|
|
@@ -25,54 +36,87 @@ async function generateFilesOnly(options) {
|
|
|
25
36
|
const preset = createAutoPreset(options);
|
|
26
37
|
for (const [id, schema] of entries) {
|
|
27
38
|
const entries = fromSchema(id, schema, preset);
|
|
28
|
-
const schemaFiles =
|
|
39
|
+
const schemaFiles = [];
|
|
29
40
|
generatedEntries[id] = entries;
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
function scan(entry) {
|
|
42
|
+
if (entry.type === "group") {
|
|
43
|
+
for (const child of entry.entries) scan(child);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
schemaFiles.push({
|
|
32
47
|
path: entry.path,
|
|
33
48
|
content: toText(entry, schema, options)
|
|
34
|
-
};
|
|
35
|
-
schemaFiles.push(file);
|
|
36
|
-
files.push(file);
|
|
49
|
+
});
|
|
37
50
|
}
|
|
51
|
+
for (const entry of entries) scan(entry);
|
|
52
|
+
generated[id] = schemaFiles;
|
|
53
|
+
files.push(...schemaFiles);
|
|
38
54
|
}
|
|
39
55
|
const context = {
|
|
40
56
|
generated,
|
|
41
57
|
generatedEntries,
|
|
42
58
|
documents: schemas
|
|
43
59
|
};
|
|
44
|
-
if (options.index) writeIndexFiles(
|
|
60
|
+
if (options.index) files.push(...writeIndexFiles(context, options));
|
|
61
|
+
if (options.meta) files.push(...generateMeta(context, options.meta === true ? {} : options.meta));
|
|
45
62
|
await options.beforeWrite?.call(context, files);
|
|
46
63
|
return files;
|
|
47
64
|
}
|
|
48
|
-
function
|
|
65
|
+
function generateMeta(context, options) {
|
|
66
|
+
const files = [];
|
|
67
|
+
const { groupStyle = "folder" } = options;
|
|
68
|
+
function scan(entries, parent) {
|
|
69
|
+
const pages = [];
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
const relativePath = PathUtils.slash(parent ? path$1.relative(parent.path, entry.path) : entry.path);
|
|
72
|
+
if (entry.type === "group") {
|
|
73
|
+
scan(entry.entries, entry);
|
|
74
|
+
if (groupStyle === "folder") pages.push(relativePath);
|
|
75
|
+
else pages.push(`---${entry.info.title}---`, `...${relativePath}`);
|
|
76
|
+
} else pages.push(relativePath.slice(0, -path$1.extname(entry.path).length));
|
|
77
|
+
}
|
|
78
|
+
if (pages.length === 0) return;
|
|
79
|
+
files.push({
|
|
80
|
+
path: parent ? path$1.join(parent.path, "meta.json") : "meta.json",
|
|
81
|
+
content: JSON.stringify({
|
|
82
|
+
title: parent?.info.title,
|
|
83
|
+
description: parent?.info.description,
|
|
84
|
+
pages
|
|
85
|
+
}, null, 2)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
for (const entries of Object.values(context.generatedEntries)) scan(entries);
|
|
89
|
+
return files;
|
|
90
|
+
}
|
|
91
|
+
function writeIndexFiles(context, options) {
|
|
92
|
+
const files = [];
|
|
49
93
|
const { generatedEntries } = context;
|
|
94
|
+
const pathToEntry = /* @__PURE__ */ new Map();
|
|
50
95
|
const { items, url } = options.index;
|
|
96
|
+
function indexEntry(entry) {
|
|
97
|
+
pathToEntry.set(PathUtils.slash(entry.path), entry);
|
|
98
|
+
if (entry.type === "group") for (const child of entry.entries) indexEntry(child);
|
|
99
|
+
}
|
|
51
100
|
let urlFn;
|
|
52
101
|
if (typeof url === "object") {
|
|
53
102
|
const getUrl = createGetUrl(url.baseUrl);
|
|
54
|
-
urlFn = (file) => getUrl(getSlugs(path.relative(url.contentDir, file)));
|
|
103
|
+
urlFn = (file) => getUrl(getSlugs(path$1.relative(url.contentDir, file)));
|
|
55
104
|
} else urlFn = url;
|
|
56
|
-
function findEntryByPath(path) {
|
|
57
|
-
for (const entries of Object.values(generatedEntries)) {
|
|
58
|
-
const match = entries.find((entry) => entry.path === path);
|
|
59
|
-
if (match) return match;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
105
|
function fileContent(index) {
|
|
63
106
|
const content = [];
|
|
64
107
|
content.push("<Cards>");
|
|
65
|
-
const
|
|
108
|
+
const outputEntries = [];
|
|
66
109
|
const only = index.only ?? Object.keys(context.generated);
|
|
67
|
-
for (const item of only) if (generatedEntries[item]) for (const entry of generatedEntries[item])
|
|
110
|
+
for (const item of only) if (generatedEntries[item]) for (const entry of generatedEntries[item]) outputEntries.push(entry);
|
|
68
111
|
else {
|
|
69
|
-
const match =
|
|
112
|
+
const match = pathToEntry.get(item);
|
|
70
113
|
if (!match) throw new Error(`${item} does not exist on "input", available: ${Object.keys(generatedEntries).join(", ")}.`);
|
|
71
|
-
|
|
114
|
+
outputEntries.push(match);
|
|
72
115
|
}
|
|
73
|
-
for (const
|
|
74
|
-
|
|
75
|
-
|
|
116
|
+
for (const entry of outputEntries) {
|
|
117
|
+
if (entry.type === "group") continue;
|
|
118
|
+
const descriptionAttr = entry.info.description ? `description=${JSON.stringify(entry.info.description)} ` : "";
|
|
119
|
+
content.push(`<Card href="${urlFn(entry.path)}" title=${JSON.stringify(entry.info.title)} ${descriptionAttr}/>`);
|
|
76
120
|
}
|
|
77
121
|
content.push("</Cards>");
|
|
78
122
|
return generateDocument({
|
|
@@ -80,10 +124,12 @@ function writeIndexFiles(files, context, options) {
|
|
|
80
124
|
description: index.description
|
|
81
125
|
}, content.join("\n"), options);
|
|
82
126
|
}
|
|
127
|
+
for (const list of Object.values(context.generatedEntries)) for (const item of list) indexEntry(item);
|
|
83
128
|
for (const item of typeof items === "function" ? items(context) : items) files.push({
|
|
84
|
-
path: path.extname(item.path).length === 0 ? `${item.path}.mdx` : item.path,
|
|
129
|
+
path: path$1.extname(item.path).length === 0 ? `${item.path}.mdx` : item.path,
|
|
85
130
|
content: fileContent(item)
|
|
86
131
|
});
|
|
132
|
+
return files;
|
|
87
133
|
}
|
|
88
134
|
//#endregion
|
|
89
135
|
export { generateFiles, generateFilesOnly };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-file.js","names":[],"sources":["../src/generate-file.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { generateDocument, type PagesToTextOptions, toText } from './utils/pages/to-text';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type { OpenAPIServer } from '@/server';\nimport { createGetUrl, getSlugs } from 'fumadocs-core/source';\nimport { createAutoPreset, type SchemaToPagesOptions } from '@/utils/pages/preset-auto';\nimport { fromSchema, type OutputEntry } from '@/utils/pages/builder';\n\nexport interface OutputFile {\n path: string;\n content: string;\n}\n\ninterface IndexConfig {\n items: IndexItem[] | ((ctx: BeforeWriteContext) => IndexItem[]);\n\n /**\n * Generate URLs for cards\n */\n url:\n | ((filePath: string) => string)\n | {\n baseUrl: string;\n /**\n * Base content directory\n */\n contentDir: string;\n };\n}\n\ninterface IndexItem {\n path: string;\n title?: string;\n description?: string;\n\n /**\n * Specify linked pages:\n * - items in `inputs` to include all generated pages of a specific schema.\n * - specific Markdown/MDX files.\n */\n only?: string[];\n}\n\ninterface GenerateFilesConfig extends PagesToTextOptions {\n /**\n * the OpenAPI server object\n */\n input: OpenAPIServer;\n\n /**\n * Output directory\n */\n output: string;\n\n /**\n * Generate index files with cards linking to generated pages.\n */\n index?: IndexConfig;\n\n /**\n * Can add/change/remove output files before writing to file system\n **/\n beforeWrite?: (this: BeforeWriteContext, files: OutputFile[]) => void | Promise<void>;\n}\n\nexport type Config = SchemaToPagesOptions & GenerateFilesConfig;\n\ninterface BeforeWriteContext {\n readonly generated: Record<string, OutputFile[]>;\n readonly generatedEntries: Record<string, OutputEntry[]>;\n readonly documents: Record<string, ProcessedDocument>;\n}\n\nexport async function generateFiles(options: Config): Promise<void> {\n const files = await generateFilesOnly(options);\n const { output } = options;\n\n await Promise.all(\n files.map(async (file) => {\n const filePath = path.join(output, file.path);\n\n await mkdir(path.dirname(filePath), { recursive: true });\n await writeFile(filePath, file.content);\n console.log(`Generated: ${filePath}`);\n }),\n );\n}\n\nexport async function generateFilesOnly(\n options: SchemaToPagesOptions & Omit<GenerateFilesConfig, 'output'>,\n): Promise<OutputFile[]> {\n const schemas = await options.input.getSchemas();\n\n const files: OutputFile[] = [];\n const generated: Record<string, OutputFile[]> = {};\n const generatedEntries: Record<string, OutputEntry[]> = {};\n\n const entries = Object.entries(schemas);\n if (entries.length === 0) {\n throw new Error('No input files found.');\n }\n const preset = createAutoPreset(options);\n for (const [id, schema] of entries) {\n const entries = fromSchema(id, schema, preset);\n const schemaFiles = (generated[id] ??= []);\n\n generatedEntries[id] = entries;\n for (const entry of entries) {\n const file: OutputFile = {\n path: entry.path,\n content: toText(entry, schema, options),\n };\n\n schemaFiles.push(file);\n files.push(file);\n }\n }\n\n const context: BeforeWriteContext = {\n generated,\n generatedEntries,\n documents: schemas,\n };\n\n if (options.index) {\n writeIndexFiles(files, context, options);\n }\n\n await options.beforeWrite?.call(context, files);\n return files;\n}\n\nfunction writeIndexFiles(\n files: OutputFile[],\n context: BeforeWriteContext,\n options: SchemaToPagesOptions & Omit<GenerateFilesConfig, 'output'>,\n) {\n const { generatedEntries } = context;\n const { items, url } = options.index!;\n\n let urlFn: (path: string) => string;\n if (typeof url === 'object') {\n const getUrl = createGetUrl(url.baseUrl);\n\n urlFn = (file) => getUrl(getSlugs(path.relative(url.contentDir, file)));\n } else {\n urlFn = url;\n }\n\n function findEntryByPath(path: string) {\n for (const entries of Object.values(generatedEntries)) {\n const match = entries.find((entry) => entry.path === path);\n\n if (match) return match;\n }\n }\n\n function fileContent(index: IndexItem): string {\n const content: string[] = [];\n content.push('<Cards>');\n const pathToEntry = new Map<string, OutputEntry>();\n const only = index.only ?? Object.keys(context.generated);\n\n for (const item of only) {\n if (generatedEntries[item]) {\n for (const entry of generatedEntries[item]) {\n pathToEntry.set(entry.path, entry);\n }\n } else {\n const match = findEntryByPath(item);\n if (!match) {\n throw new Error(\n `${item} does not exist on \"input\", available: ${Object.keys(generatedEntries).join(', ')}.`,\n );\n }\n\n pathToEntry.set(match.path, match);\n }\n }\n\n for (const file of pathToEntry.values()) {\n const descriptionAttr = file.info.description\n ? `description=${JSON.stringify(file.info.description)} `\n : '';\n content.push(\n `<Card href=\"${urlFn(file.path)}\" title=${JSON.stringify(file.info.title)} ${descriptionAttr}/>`,\n );\n }\n\n content.push('</Cards>');\n return generateDocument(\n {\n title: index.title ?? 'Overview',\n description: index.description,\n },\n content.join('\\n'),\n options,\n );\n }\n\n for (const item of typeof items === 'function' ? items(context) : items) {\n files.push({\n path: path.extname(item.path).length === 0 ? `${item.path}.mdx` : item.path,\n content: fileContent(item),\n });\n }\n}\n"],"mappings":";;;;;;;AA0EA,eAAsB,cAAc,SAAgC;CAClE,MAAM,QAAQ,MAAM,kBAAkB,QAAQ;CAC9C,MAAM,EAAE,WAAW;AAEnB,OAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;EACxB,MAAM,WAAW,KAAK,KAAK,QAAQ,KAAK,KAAK;AAE7C,QAAM,MAAM,KAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACxD,QAAM,UAAU,UAAU,KAAK,QAAQ;AACvC,UAAQ,IAAI,cAAc,WAAW;GACrC,CACH;;AAGH,eAAsB,kBACpB,SACuB;CACvB,MAAM,UAAU,MAAM,QAAQ,MAAM,YAAY;CAEhD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M,QAAQ,OAAO,KAAK,QAAQ,UAAU;AAEzD,OAAK,MAAM,QAAQ,KACjB,KAAI,iBAAiB,MACnB,MAAK,MAAM,SAAS,iBAAiB,MACnC,aAAY,IAAI,MAAM,MAAM,MAAM;OAE/B;GACL,MAAM,QAAQ,gBAAgB,KAAK;AACnC,OAAI,CAAC,MACH,OAAM,IAAI,MACR,GAAG,KAAK,yCAAyC,OAAO,KAAK,iBAAiB,CAAC,KAAK,KAAK,CAAC,GAC3F;AAGH,eAAY,IAAI,MAAM,MAAM,MAAM;;AAItC,OAAK,MAAM,QAAQ,YAAY,QAAQ,EAAE;GACvC,MAAM,kBAAkB,KAAK,KAAK,cAC9B,eAAe,KAAK,UAAU,KAAK,KAAK,YAAY,CAAC,KACrD;AACJ,WAAQ,KACN,eAAe,MAAM,KAAK,KAAK,CAAC,UAAU,KAAK,UAAU,KAAK,KAAK,MAAM,CAAC,GAAG,gBAAgB,IAC9F;;AAGH,UAAQ,KAAK,WAAW;AACxB,SAAO,iBACL;GACE,OAAO,MAAM,SAAS;GACtB,aAAa,MAAM;GACpB,EACD,QAAQ,KAAK,KAAK,EAClB,QACD;;AAGH,MAAK,MAAM,QAAQ,OAAO,UAAU,aAAa,MAAM,QAAQ,GAAG,MAChE,OAAM,KAAK;EACT,MAAM,KAAK,QAAQ,KAAK,KAAK,CAAC,WAAW,IAAI,GAAG,KAAK,KAAK,QAAQ,KAAK;EACvE,SAAS,YAAY,KAAK;EAC3B,CAAC"}
|
|
1
|
+
{"version":3,"file":"generate-file.js","names":["path"],"sources":["../src/generate-file.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { generateDocument, type PagesToTextOptions, toText } from './utils/pages/to-text';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type { OpenAPIServer } from '@/server';\nimport { createGetUrl, getSlugs, PathUtils } from 'fumadocs-core/source';\nimport { createAutoPreset, type SchemaToPagesOptions } from '@/utils/pages/preset-auto';\nimport { fromSchema, type OutputGroup, type OutputEntry } from '@/utils/pages/builder';\nimport type { DistributiveOmit } from './types';\n\nexport interface OutputFile {\n path: string;\n content: string;\n}\n\ninterface IndexConfig {\n items: IndexItem[] | ((ctx: BeforeWriteContext) => IndexItem[]);\n\n /**\n * Generate URLs for cards\n */\n url:\n | ((filePath: string) => string)\n | {\n baseUrl: string;\n /**\n * Base content directory\n */\n contentDir: string;\n };\n}\n\ninterface IndexItem {\n /** output path of index page */\n path: string;\n title?: string;\n description?: string;\n\n /**\n * Specify linked pages:\n * - items in `inputs` to include all generated pages of a specific schema.\n * - file paths (using forward slash).\n */\n only?: string[];\n}\n\ninterface GenerateFilesConfig extends PagesToTextOptions {\n /**\n * the OpenAPI server object\n */\n input: OpenAPIServer;\n\n /**\n * Output directory\n */\n output: string;\n\n /**\n * Generate index files with cards linking to generated pages.\n */\n index?: IndexConfig;\n\n /**\n * Generate `meta.json` files.\n *\n * Note: for flexibility, it's recommended to define them on your own.\n */\n meta?: boolean | MetaOptions;\n\n /**\n * Can add/change/remove output files before writing to file system\n **/\n beforeWrite?: (this: BeforeWriteContext, files: OutputFile[]) => void | Promise<void>;\n}\n\ninterface MetaOptions {\n groupStyle?: 'folder' | 'separator';\n}\n\nexport type Config = SchemaToPagesOptions &\n GenerateFilesConfig & {\n /**\n * Re-generate when **schema files are changed**, ignores custom input functions & URLs.\n *\n * Note: it is recommended to configure & use `chokidar` on your own, this is only for simple cases.\n */\n watch?: boolean;\n };\n\ninterface BeforeWriteContext {\n readonly generated: Record<string, OutputFile[]>;\n readonly generatedEntries: Record<string, OutputEntry[]>;\n readonly documents: Record<string, ProcessedDocument>;\n}\n\nexport async function generateFiles(options: Config): Promise<void> {\n if (options.watch) {\n const { watch } = await import('chokidar');\n const subOptions: Config = { ...options, watch: false };\n\n await generateFiles(subOptions);\n const targets = options.input._getWatchPaths();\n console.log(`[Fumadocs OpenAPI] watching ${targets.join(', ')}`);\n watch(targets, {\n ignoreInitial: true,\n }).on('all', () => generateFiles(subOptions));\n return;\n }\n\n const files = await generateFilesOnly(options);\n\n await Promise.all(\n files.map(async (file) => {\n const filePath = path.join(options.output, file.path);\n\n await mkdir(path.dirname(filePath), { recursive: true });\n await writeFile(filePath, file.content);\n console.log(`Generated: ${filePath}`);\n }),\n );\n}\n\nexport async function generateFilesOnly(\n options: DistributiveOmit<Config, 'output'>,\n): Promise<OutputFile[]> {\n const schemas = await options.input.getSchemas();\n\n const files: OutputFile[] = [];\n const generated: Record<string, OutputFile[]> = {};\n const generatedEntries: Record<string, OutputEntry[]> = {};\n\n const entries = Object.entries(schemas);\n if (entries.length === 0) {\n throw new Error('No input files found.');\n }\n const preset = createAutoPreset(options);\n for (const [id, schema] of entries) {\n const entries = fromSchema(id, schema, preset);\n const schemaFiles: OutputFile[] = [];\n\n generatedEntries[id] = entries;\n function scan(entry: OutputEntry) {\n if (entry.type === 'group') {\n for (const child of entry.entries) scan(child);\n return;\n }\n\n schemaFiles.push({\n path: entry.path,\n content: toText(entry, schema, options),\n });\n }\n\n for (const entry of entries) scan(entry);\n generated[id] = schemaFiles;\n files.push(...schemaFiles);\n }\n\n const context: BeforeWriteContext = {\n generated,\n generatedEntries,\n documents: schemas,\n };\n\n if (options.index) {\n files.push(...writeIndexFiles(context, options));\n }\n\n if (options.meta) {\n files.push(...generateMeta(context, options.meta === true ? {} : options.meta));\n }\n\n await options.beforeWrite?.call(context, files);\n return files;\n}\n\nfunction generateMeta(context: BeforeWriteContext, options: MetaOptions): OutputFile[] {\n const files: OutputFile[] = [];\n const { groupStyle = 'folder' } = options;\n\n function scan(entries: OutputEntry[], parent?: OutputGroup) {\n const pages: string[] = [];\n\n for (const entry of entries) {\n const relativePath = PathUtils.slash(\n parent ? path.relative(parent.path, entry.path) : entry.path,\n );\n\n if (entry.type === 'group') {\n scan(entry.entries, entry);\n\n if (groupStyle === 'folder') {\n pages.push(relativePath);\n } else {\n pages.push(`---${entry.info.title}---`, `...${relativePath}`);\n }\n } else {\n pages.push(relativePath.slice(0, -path.extname(entry.path).length));\n }\n }\n\n if (pages.length === 0) return;\n files.push({\n path: parent ? path.join(parent.path, 'meta.json') : 'meta.json',\n content: JSON.stringify(\n {\n title: parent?.info.title,\n description: parent?.info.description,\n pages,\n },\n null,\n 2,\n ),\n });\n }\n\n for (const entries of Object.values(context.generatedEntries)) {\n scan(entries);\n }\n\n return files;\n}\n\nfunction writeIndexFiles(\n context: BeforeWriteContext,\n options: SchemaToPagesOptions & Omit<GenerateFilesConfig, 'output'>,\n): OutputFile[] {\n const files: OutputFile[] = [];\n const { generatedEntries } = context;\n const pathToEntry = new Map<string, OutputEntry>();\n const { items, url } = options.index!;\n\n function indexEntry(entry: OutputEntry) {\n pathToEntry.set(PathUtils.slash(entry.path), entry);\n if (entry.type === 'group') {\n for (const child of entry.entries) {\n indexEntry(child);\n }\n }\n }\n\n let urlFn: (path: string) => string;\n if (typeof url === 'object') {\n const getUrl = createGetUrl(url.baseUrl);\n\n urlFn = (file) => getUrl(getSlugs(path.relative(url.contentDir, file)));\n } else {\n urlFn = url;\n }\n\n function fileContent(index: IndexItem): string {\n const content: string[] = [];\n content.push('<Cards>');\n const outputEntries: OutputEntry[] = [];\n const only = index.only ?? Object.keys(context.generated);\n\n for (const item of only) {\n if (generatedEntries[item]) {\n for (const entry of generatedEntries[item]) {\n outputEntries.push(entry);\n }\n } else {\n const match = pathToEntry.get(item);\n if (!match) {\n throw new Error(\n `${item} does not exist on \"input\", available: ${Object.keys(generatedEntries).join(', ')}.`,\n );\n }\n\n outputEntries.push(match);\n }\n }\n\n for (const entry of outputEntries) {\n // cannot link to groups\n if (entry.type === 'group') continue;\n const descriptionAttr = entry.info.description\n ? `description=${JSON.stringify(entry.info.description)} `\n : '';\n content.push(\n `<Card href=\"${urlFn(entry.path)}\" title=${JSON.stringify(entry.info.title)} ${descriptionAttr}/>`,\n );\n }\n\n content.push('</Cards>');\n return generateDocument(\n {\n title: index.title ?? 'Overview',\n description: index.description,\n },\n content.join('\\n'),\n options,\n );\n }\n\n for (const list of Object.values(context.generatedEntries)) {\n for (const item of list) indexEntry(item);\n }\n\n for (const item of typeof items === 'function' ? items(context) : items) {\n files.push({\n path: path.extname(item.path).length === 0 ? `${item.path}.mdx` : item.path,\n content: fileContent(item),\n });\n }\n\n return files;\n}\n"],"mappings":";;;;;;;AA+FA,eAAsB,cAAc,SAAgC;AAClE,KAAI,QAAQ,OAAO;EACjB,MAAM,EAAE,UAAU,MAAM,OAAO;EAC/B,MAAM,aAAqB;GAAE,GAAG;GAAS,OAAO;GAAO;AAEvD,QAAM,cAAc,WAAW;EAC/B,MAAM,UAAU,QAAQ,MAAM,gBAAgB;AAC9C,UAAQ,IAAI,+BAA+B,QAAQ,KAAK,KAAK,GAAG;AAChE,QAAM,SAAS,EACb,eAAe,MAChB,CAAC,CAAC,GAAG,aAAa,cAAc,WAAW,CAAC;AAC7C;;CAGF,MAAM,QAAQ,MAAM,kBAAkB,QAAQ;AAE9C,OAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;EACxB,MAAM,WAAWA,OAAK,KAAK,QAAQ,QAAQ,KAAK,KAAK;AAErD,QAAM,MAAMA,OAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACxD,QAAM,UAAU,UAAU,KAAK,QAAQ;AACvC,UAAQ,IAAI,cAAc,WAAW;GACrC,CACH;;AAGH,eAAsB,kBACpB,SACuB;CACvB,MAAM,UAAU,MAAM,QAAQ,MAAM,YAAY;CAEhD,MAAM,QAAsB,EAAE;CAC9B,MAAM,YAA0C,EAAE;CAClD,MAAM,mBAAkD,EAAE;CAE1D,MAAM,UAAU,OAAO,QAAQ,QAAQ;AACvC,KAAI,QAAQ,WAAW,EACrB,OAAM,IAAI,MAAM,wBAAwB;CAE1C,MAAM,SAAS,iBAAiB,QAAQ;AACxC,MAAK,MAAM,CAAC,IAAI,WAAW,SAAS;EAClC,MAAM,UAAU,WAAW,IAAI,QAAQ,OAAO;EAC9C,MAAM,cAA4B,EA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U,MAAM,KAAK,YAAY,CAAC,KACtD;AACJ,WAAQ,KACN,eAAe,MAAM,MAAM,KAAK,CAAC,UAAU,KAAK,UAAU,MAAM,KAAK,MAAM,CAAC,GAAG,gBAAgB,IAChG;;AAGH,UAAQ,KAAK,WAAW;AACxB,SAAO,iBACL;GACE,OAAO,MAAM,SAAS;GACtB,aAAa,MAAM;GACpB,EACD,QAAQ,KAAK,KAAK,EAClB,QACD;;AAGH,MAAK,MAAM,QAAQ,OAAO,OAAO,QAAQ,iBAAiB,CACxD,MAAK,MAAM,QAAQ,KAAM,YAAW,KAAK;AAG3C,MAAK,MAAM,QAAQ,OAAO,UAAU,aAAa,MAAM,QAAQ,GAAG,MAChE,OAAM,KAAK;EACT,MAAMA,OAAK,QAAQ,KAAK,KAAK,CAAC,WAAW,IAAI,GAAG,KAAK,KAAK,QAAQ,KAAK;EACvE,SAAS,YAAY,KAAK;EAC3B,CAAC;AAGJ,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaAdapter } from "./requests/media/adapter.js";
|
|
2
|
-
import { OperationOutput, OutputEntry, OutputGroup, PagesBuilder, PagesBuilderConfig,
|
|
2
|
+
import { OperationOutput, OutputEntry, OutputGroup, PageOutput, PagesBuilder, PagesBuilderConfig, WebhookOutput, fromSchema, fromServer } from "./utils/pages/builder.js";
|
|
3
3
|
import { SchemaToPagesOptions, createAutoPreset } from "./utils/pages/preset-auto.js";
|
|
4
4
|
import { Awaitable, CallbackObject, DistributiveOmit, Document, ExampleObject, HttpMethods, MediaTypeObject, MethodInformation, OAuth2SecurityScheme, OperationObject, ParameterObject, PathItemObject, ReferenceObject, RenderContext, RequestBodyObject, ResponseObject, SecuritySchemeObject, ServerObject, ServerVariableObject, TagObject } from "./types.js";
|
|
5
5
|
import { Config, OutputFile, generateFiles, generateFilesOnly } from "./generate-file.js";
|
|
6
|
-
export { Awaitable, CallbackObject, Config, DistributiveOmit, Document, ExampleObject, HttpMethods, type MediaAdapter, MediaTypeObject, MethodInformation, OAuth2SecurityScheme, OperationObject, OperationOutput, OutputEntry, OutputFile, OutputGroup, PagesBuilder, PagesBuilderConfig, ParameterObject, PathItemObject, ReferenceObject, RenderContext, RequestBodyObject, ResponseObject, SchemaToPagesOptions, SecuritySchemeObject, ServerObject, ServerVariableObject, TagObject,
|
|
6
|
+
export { Awaitable, CallbackObject, Config, DistributiveOmit, Document, ExampleObject, HttpMethods, type MediaAdapter, MediaTypeObject, MethodInformation, OAuth2SecurityScheme, OperationObject, OperationOutput, OutputEntry, OutputFile, OutputGroup, PageOutput, PagesBuilder, PagesBuilderConfig, ParameterObject, PathItemObject, ReferenceObject, RenderContext, RequestBodyObject, ResponseObject, SchemaToPagesOptions, SecuritySchemeObject, ServerObject, ServerVariableObject, TagObject, WebhookOutput, createAutoPreset, fromSchema, fromServer, generateFiles, generateFilesOnly };
|