fumadocs-openapi 5.3.1 → 5.4.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/dist/index.d.ts CHANGED
@@ -49,7 +49,9 @@ interface APIPlaygroundProps {
49
49
  route: string;
50
50
  method: string;
51
51
  bodyType: 'json' | 'form-data';
52
- authorization?: PrimitiveRequestField;
52
+ authorization?: PrimitiveRequestField & {
53
+ authType: string;
54
+ };
53
55
  path?: PrimitiveRequestField[];
54
56
  query?: PrimitiveRequestField[];
55
57
  header?: PrimitiveRequestField[];
@@ -50,7 +50,9 @@ interface APIPlaygroundProps {
50
50
  route: string;
51
51
  method: string;
52
52
  bodyType: 'json' | 'form-data';
53
- authorization?: PrimitiveRequestField;
53
+ authorization?: PrimitiveRequestField & {
54
+ authType: string;
55
+ };
54
56
  path?: PrimitiveRequestField[];
55
57
  query?: PrimitiveRequestField[];
56
58
  header?: PrimitiveRequestField[];
@@ -317,6 +317,7 @@ function getAuthorizationField(method, ctx) {
317
317
  return {
318
318
  type: 'string',
319
319
  name: 'Authorization',
320
+ authType: scheme.type,
320
321
  defaultValue: scheme.type === 'oauth2' || scheme.type === 'http' && scheme.scheme === 'bearer' ? 'Bearer' : 'Basic',
321
322
  isRequired: security.every((requirements)=>Object.keys(requirements).length > 0),
322
323
  description: 'The Authorization access token'
@@ -468,6 +469,38 @@ function heading(depth, child, ctx) {
468
469
  }, id);
469
470
  }
470
471
 
472
+ /**
473
+ * Combine multiple object schemas into one
474
+ */ function combineSchema(schema) {
475
+ const result = {
476
+ type: 'object'
477
+ };
478
+ function add(s) {
479
+ if (s.properties) {
480
+ var _result;
481
+ (_result = result).properties ?? (_result.properties = {});
482
+ Object.assign(result.properties, s.properties);
483
+ }
484
+ if (s.additionalProperties === true) {
485
+ result.additionalProperties = true;
486
+ } else if (s.additionalProperties && typeof result.additionalProperties !== 'boolean') {
487
+ var _result1;
488
+ (_result1 = result).additionalProperties ?? (_result1.additionalProperties = {});
489
+ Object.assign(result.additionalProperties, s.additionalProperties);
490
+ }
491
+ if (s.required) {
492
+ var _result2;
493
+ (_result2 = result).required ?? (_result2.required = []);
494
+ result.required.push(...s.required);
495
+ }
496
+ if (s.allOf) {
497
+ noRef(s.allOf).forEach(add);
498
+ }
499
+ }
500
+ schema.forEach(add);
501
+ return result;
502
+ }
503
+
471
504
  const keys = {
472
505
  default: 'Default',
473
506
  minimum: 'Minimum',
@@ -613,32 +646,6 @@ function Schema({ name, schema, ctx }) {
613
646
  children: child
614
647
  });
615
648
  }
616
- /**
617
- * Combine multiple object schemas into one
618
- */ function combineSchema(schema) {
619
- const result = {
620
- type: 'object'
621
- };
622
- function add(s) {
623
- if (s.properties) {
624
- var _result;
625
- (_result = result).properties ?? (_result.properties = {});
626
- Object.assign(result.properties, s.properties);
627
- }
628
- if (s.additionalProperties === true) {
629
- result.additionalProperties = true;
630
- } else if (s.additionalProperties && typeof result.additionalProperties !== 'boolean') {
631
- var _result1;
632
- (_result1 = result).additionalProperties ?? (_result1.additionalProperties = {});
633
- Object.assign(result.additionalProperties, s.additionalProperties);
634
- }
635
- if (s.allOf) {
636
- noRef(s.allOf).forEach(add);
637
- }
638
- }
639
- schema.forEach(add);
640
- return result;
641
- }
642
649
  /**
643
650
  * Check if the schema needs another collapsible to explain
644
651
  */ function isComplexType(schema) {
@@ -64,7 +64,7 @@ function useSchemaContext() {
64
64
  return ctx;
65
65
  }
66
66
 
67
- const APIPlayground = dynamic(()=>import('./playground-client-CthJtmMz.js').then((mod)=>mod.APIPlayground));
67
+ const APIPlayground = dynamic(()=>import('./playground-client-CB0L6vUj.js').then((mod)=>mod.APIPlayground));
68
68
  function Root({ children, baseUrl, className, ...props }) {
69
69
  return /*#__PURE__*/ jsx("div", {
70
70
  className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className),
@@ -49,7 +49,9 @@ interface APIPlaygroundProps {
49
49
  route: string;
50
50
  method: string;
51
51
  bodyType: 'json' | 'form-data';
52
- authorization?: PrimitiveRequestField;
52
+ authorization?: PrimitiveRequestField & {
53
+ authType: string;
54
+ };
53
55
  path?: PrimitiveRequestField[];
54
56
  query?: PrimitiveRequestField[];
55
57
  header?: PrimitiveRequestField[];
package/dist/ui/index.js CHANGED
@@ -3,8 +3,8 @@ import { cn } from 'fumadocs-ui/components/api';
3
3
  import { Fragment } from 'react';
4
4
  import { Accordions, Accordion } from 'fumadocs-ui/components/accordion';
5
5
  import { cva } from 'class-variance-authority';
6
- import { C as CopyRouteButton } from './client-client-CgPBB3ii.js';
7
- export { A as APIPlayground, R as Root, u as useSchemaContext } from './client-client-CgPBB3ii.js';
6
+ import { C as CopyRouteButton } from './client-client-BUlxkJAI.js';
7
+ export { A as APIPlayground, R as Root, u as useSchemaContext } from './client-client-BUlxkJAI.js';
8
8
 
9
9
  const badgeVariants = cva('rounded border px-1.5 py-1 text-xs font-medium leading-[12px]', {
10
10
  variants: {
@@ -1,12 +1,12 @@
1
1
  'use client';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
- import { forwardRef, useId, createContext, useContext, useState, useCallback, useLayoutEffect, useRef, useMemo } from 'react';
4
+ import { forwardRef, useId, createContext, useContext, useState, useCallback, useLayoutEffect, useRef, useEffect, useMemo } from 'react';
5
5
  import { FormProvider, Controller, useFormContext, useFieldArray, useForm, useWatch } from 'react-hook-form';
6
6
  import useSWRImmutable from 'swr/immutable';
7
7
  import { Accordions, Accordion } from 'fumadocs-ui/components/accordion';
8
8
  import { cn, buttonVariants } from 'fumadocs-ui/components/api';
9
- import { u as useSchemaContext, a as useApiContext, S as SchemaContext } from './client-client-CgPBB3ii.js';
9
+ import { u as useSchemaContext, a as useApiContext, S as SchemaContext } from './client-client-BUlxkJAI.js';
10
10
  import { Slot } from '@radix-ui/react-slot';
11
11
  import { cva } from 'class-variance-authority';
12
12
  import { CircleCheckIcon, CircleXIcon, ChevronDown, ChevronUp, Check, Trash2, Plus } from 'lucide-react';
@@ -905,6 +905,20 @@ function APIPlayground({ route, method = 'GET', bodyType, authorization, path =
905
905
  }, {
906
906
  shouldRetryOnError: false
907
907
  });
908
+ useEffect(()=>{
909
+ if (!authorization) return;
910
+ const key = `__fumadocs_authorization_${authorization.authType}`;
911
+ const cached = localStorage.getItem(key);
912
+ if (cached) form.setValue('authorization', cached);
913
+ const subscription = form.watch((value, { name })=>{
914
+ if (name !== 'authorization' || !value.authorization) return;
915
+ localStorage.setItem(key, value.authorization);
916
+ });
917
+ return ()=>{
918
+ subscription.unsubscribe();
919
+ };
920
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mounted only once
921
+ }, []);
908
922
  const onSubmit = form.handleSubmit((value)=>{
909
923
  setInput(value);
910
924
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",