fumadocs-openapi 10.0.2 → 10.0.4

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.
@@ -109,7 +109,7 @@ export default function PlaygroundClient({ route, method = 'GET', securities, pa
109
109
  const onSubmit = form.handleSubmit((value) => {
110
110
  testQuery.start(mapInputs(value));
111
111
  });
112
- return (_jsx(FormProvider, { ...form, children: _jsx(SchemaProvider, { fieldInfoMap: fieldInfoMap, references: references, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border shadow-md overflow-hidden bg-fd-card text-fd-card-foreground', rest.className), onSubmit: onSubmit, children: [_jsx(ServerSelect, {}), _jsxs("div", { className: "flex flex-row items-center gap-2 text-sm p-3 not-last:pb-0", children: [_jsx(MethodLabel, { children: method }), _jsx(Route, { route: route, className: "flex-1" }), _jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5'), disabled: testQuery.isLoading, children: testQuery.isLoading ? (_jsx(LoaderCircle, { className: "size-4 animate-spin" })) : ('Send') })] }), securities.length > 0 && (_jsx(SecurityTabs, { securities: securities, securityId: securityId, setSecurityId: setSecurityId, children: inputs.map((input) => (_jsx(Fragment, { children: input.children }, input.fieldName))) })), _jsx(FormBody, { body: body, parameters: parameters }), testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }) }) }));
112
+ return (_jsx(FormProvider, { ...form, children: _jsx(SchemaProvider, { fieldInfoMap: fieldInfoMap, references: references, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border shadow-md overflow-hidden bg-fd-card text-fd-card-foreground', rest.className), onSubmit: onSubmit, children: [_jsx(ServerSelect, {}), _jsxs("div", { className: "flex flex-row items-center gap-2 text-sm p-3 not-last:pb-0", children: [_jsx(MethodLabel, { children: method }), _jsx(Route, { route: route, className: "flex-1" }), _jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'w-14 py-1.5'), disabled: testQuery.isLoading, children: testQuery.isLoading ? (_jsx(LoaderCircle, { className: "size-4 animate-spin" })) : ('Send') })] }), securities.length > 0 && (_jsx(SecurityTabs, { securities: securities, securityId: securityId, setSecurityId: setSecurityId, children: inputs.map((input) => (_jsx(Fragment, { children: input.children }, input.fieldName))) })), _jsx(FormBody, { body: body, parameters: parameters }), testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }) }) }));
113
113
  }
114
114
  function SecurityTabs({ securities, setSecurityId, securityId, children, }) {
115
115
  const [open, setOpen] = useState(false);
@@ -265,7 +265,7 @@ function useAuthInputs(securities, transform) {
265
265
  for (const item of inputs) {
266
266
  if (!item.mapOutput)
267
267
  continue;
268
- set(cloned, item.fieldName, item.mapOutput(get(values, item.fieldName)));
268
+ set(cloned, item.fieldName, item.mapOutput(get(cloned, item.fieldName)));
269
269
  }
270
270
  return cloned;
271
271
  };
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../../src/playground/components/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkDxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,KAAK,CAAC,uDAwCxB;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CA8B7D;AA6FD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CA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,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,uDA2GA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,QAAQ,EACR,WAAkB,EAClB,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,kDA4KA"}
@@ -94,10 +94,12 @@ function DynamicProperties({ fieldName, filterKey = () => true, getType = () =>
94
94
  }
95
95
  export function FieldInput({ field, fieldName, isRequired, ...props }) {
96
96
  const form = useFormContext();
97
- const { field: { value, onChange, ...restField }, } = useController({
97
+ const { field: { value, onChange, ...restField }, fieldState, } = useController({
98
98
  control: form.control,
99
99
  name: fieldName,
100
100
  });
101
+ if (field.type === 'null')
102
+ return;
101
103
  if (field.type === 'string' && field.format === 'binary') {
102
104
  return (_jsxs("div", { ...props, children: [_jsx("label", { htmlFor: fieldName, className: cn(buttonVariants({
103
105
  color: 'secondary',
@@ -111,9 +113,20 @@ export function FieldInput({ field, fieldName, isRequired, ...props }) {
111
113
  if (field.type === 'boolean') {
112
114
  return (_jsxs(Select, { value: String(value), onValueChange: (value) => onChange(value === 'undefined' ? undefined : value === 'true'), disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), !isRequired && _jsx(SelectItem, { value: "undefined", children: "Unset" })] })] }));
113
115
  }
114
- if (field.type === 'null')
115
- return;
116
- return (_jsxs("div", { ...props, className: cn('flex flex-row gap-2', props.className), children: [_jsx(Input, { id: fieldName, placeholder: "Enter value", type: field.type === 'number' ? 'number' : 'text', step: field.type === 'number' ? 'any' : undefined, value: value ?? '', onChange: (e) => onChange(field.type === 'number' ? e.target.valueAsNumber : e.target.value), ...restField }), !isRequired && value !== undefined && (_jsx("button", { type: "button", onClick: () => onChange(undefined), className: "text-fd-muted-foreground", children: _jsx(X, { className: "size-4" }) }))] }));
116
+ const isNumber = field.type === 'integer' || field.type === 'number';
117
+ return (_jsxs("div", { ...props, className: cn('flex flex-row gap-2', props.className), children: [_jsx(Input, { id: fieldName, placeholder: "Enter value", type: isNumber ? 'number' : 'text', step: field.type === 'integer' ? 1 : undefined, value: value ?? '', onChange: (e) => {
118
+ if (isNumber && !Number.isNaN(e.target.valueAsNumber)) {
119
+ onChange(e.target.valueAsNumber);
120
+ }
121
+ else if (!isNumber) {
122
+ onChange(e.target.value);
123
+ }
124
+ }, ...restField }), fieldState.isDirty && (_jsx("button", { type: "button",
125
+ // TODO: `react-hook-form` doesn't support setting a value to `undefined` (aka remove the value), if there's a default value defined.
126
+ // the default value is kept by `react-hook-form` internally, we cannot manipulate it.
127
+ // hence, we can only support resetting to the default value.
128
+ // perhaps when we migrate to Tanstack Form, we can reconsider this.
129
+ onClick: () => form.resetField(fieldName), className: "text-fd-muted-foreground", children: _jsx(X, { className: "size-4" }) }))] }));
117
130
  }
118
131
  export function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth = 0, slotType, collapsible = true, ...props }) {
119
132
  const field = useResolvedSchema(_field);
@@ -159,7 +172,7 @@ function ArrayInput({ fieldName, items, ...props }) {
159
172
  const { fields, append, remove } = useFieldArray({
160
173
  name: fieldName,
161
174
  });
162
- return (_jsxs("div", { ...props, className: cn('flex flex-col gap-2', props.className), children: [fields.map((item, index) => (_jsx(FieldSet, { name: _jsxs("span", { className: "text-fd-muted-foreground", children: [name, "[", index, "]"] }), field: items, fieldName: `${fieldName}.${index}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
175
+ return (_jsxs("div", { ...props, className: cn('flex flex-col gap-2', props.className), children: [fields.map((item, index) => (_jsx(FieldSet, { name: _jsxs("span", { className: "text-fd-muted-foreground", children: [name, "[", index, "]"] }), field: items, isRequired: true, fieldName: `${fieldName}.${index}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
163
176
  color: 'outline',
164
177
  size: 'icon-xs',
165
178
  })), onClick: () => remove(index), children: _jsx(Trash2, {}) }) }, item.id))), _jsxs("button", { type: "button", className: cn(buttonVariants({
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { createContext, Fragment, use, useCallback, useEffect, useMemo, useRef, useState, } from 'react';
4
4
  import { Tabs, TabsContent, TabsList, TabsTrigger, } from 'fumadocs-ui/components/tabs';
5
5
  import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
@@ -43,7 +43,7 @@ function SchemaUIContent({ $type }) {
43
43
  const schema = refs[$type];
44
44
  if ((schema.readOnly && !readOnly) || (schema.writeOnly && !writeOnly))
45
45
  return;
46
- let child = _jsx(_Fragment, {});
46
+ let child = null;
47
47
  if (schema.type === 'or' && schema.items.length > 0) {
48
48
  child = (_jsxs(_Fragment, { children: [child, _jsxs(Tabs, { defaultValue: schema.items[0].$type, children: [_jsx(TabsList, { children: schema.items.map((item) => (_jsx(TabsTrigger, { value: item.$type, children: item.name }, item.$type))) }), schema.items.map((item) => (_jsx(TabsContent, { value: item.$type, forceMount: undefined, className: "py-0", children: _jsx(SchemaUIContent, { ...item }) }, item.$type)))] })] }));
49
49
  }
@@ -122,11 +122,17 @@ function generateSchemaUI({ ctx, root, }) {
122
122
  };
123
123
  refs[id] = out;
124
124
  for (const item of schema.oneOf) {
125
- const $type = getSchemaId(item);
126
- scanRefs($type, item);
125
+ if (typeof item !== 'object')
126
+ continue;
127
+ const key = `${id}_extends:${getSchemaId(item)}`;
128
+ const extended = {
129
+ ...schema,
130
+ ...item,
131
+ };
132
+ scanRefs(key, extended);
127
133
  out.items.push({
128
- name: schemaToString(item, ctx.schema, FormatFlags.UseAlias),
129
- $type,
134
+ $type: key,
135
+ name: schemaToString(extended, ctx.schema, FormatFlags.UseAlias),
130
136
  });
131
137
  }
132
138
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "10.0.2",
3
+ "version": "10.0.4",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -69,8 +69,8 @@
69
69
  "remark-rehype": "^11.1.2",
70
70
  "tinyglobby": "^0.2.15",
71
71
  "xml-js": "^1.6.11",
72
- "fumadocs-core": "16.0.8",
73
- "fumadocs-ui": "16.0.8"
72
+ "fumadocs-core": "16.0.10",
73
+ "fumadocs-ui": "16.0.10"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@scalar/api-client-react": "^1.3.48",