fumadocs-openapi 9.5.1 → 9.6.1
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/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +36 -64
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +24 -17
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +27 -27
- package/dist/render/operation/index.js +6 -8
- package/dist/render/renderer.d.ts +1 -1
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/schema/client.d.ts +18 -0
- package/dist/render/schema/client.d.ts.map +1 -0
- package/dist/render/schema/client.js +139 -0
- package/dist/render/schema/index.d.ts +7 -0
- package/dist/render/schema/index.d.ts.map +1 -0
- package/dist/render/schema/index.js +11 -0
- package/dist/render/schema/server.d.ts +43 -0
- package/dist/render/schema/server.d.ts.map +1 -0
- package/dist/render/schema/server.js +206 -0
- package/dist/render/schema/ui.d.ts +16 -0
- package/dist/render/schema/ui.d.ts.map +1 -0
- package/dist/render/schema/ui.js +14 -0
- package/dist/server/create.d.ts +11 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/ui/components/method-label.d.ts +1 -1
- package/dist/ui/contexts/code-example.d.ts +4 -1
- package/dist/ui/contexts/code-example.d.ts.map +1 -1
- package/dist/ui/contexts/code-example.js +1 -1
- package/dist/ui/index.d.ts +3 -7
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +2 -13
- package/dist/utils/schema-to-string.d.ts +5 -1
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +25 -24
- package/package.json +11 -11
- package/dist/render/schema.d.ts +0 -13
- package/dist/render/schema.d.ts.map +0 -1
- package/dist/render/schema.js +0 -239
package/dist/render/schema.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Fragment } from 'react';
|
|
3
|
-
import { combineSchema } from '../utils/combine-schema.js';
|
|
4
|
-
import { Markdown } from './markdown.js';
|
|
5
|
-
import { schemaToString } from '../utils/schema-to-string.js';
|
|
6
|
-
import { Tabs, TabsContent, TabsList, TabsTrigger, } from 'fumadocs-ui/components/tabs';
|
|
7
|
-
export function Schema({ name, schema, required = false, readOnly = false, writeOnly = false, as = 'property', ctx: renderContext, }) {
|
|
8
|
-
const { renderer } = renderContext;
|
|
9
|
-
function propertyBody(schema, renderPrimitive, ctx) {
|
|
10
|
-
if (ctx.stack.has(schema))
|
|
11
|
-
return;
|
|
12
|
-
const next = {
|
|
13
|
-
...ctx,
|
|
14
|
-
stack: ctx.stack.next(schema),
|
|
15
|
-
};
|
|
16
|
-
if (Array.isArray(schema.type)) {
|
|
17
|
-
const items = schema.type.flatMap((type) => {
|
|
18
|
-
const composed = {
|
|
19
|
-
...schema,
|
|
20
|
-
type,
|
|
21
|
-
};
|
|
22
|
-
if (!isComplexType(composed))
|
|
23
|
-
return [];
|
|
24
|
-
return composed;
|
|
25
|
-
});
|
|
26
|
-
if (items.length === 0)
|
|
27
|
-
return;
|
|
28
|
-
if (items.length === 1)
|
|
29
|
-
return propertyBody(items[0], renderPrimitive, next);
|
|
30
|
-
return (_jsxs(Tabs, { defaultValue: items[0].type, children: [_jsx(TabsList, { children: items.map((item) => (_jsx(TabsTrigger, { value: item.type, children: schemaToString(item, renderContext.schema) }, item.type))) }), items.map((item) => (_jsxs(TabsContent, { value: item.type, children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), renderPrimitive(item, ctx)] }, item.type)))] }));
|
|
31
|
-
}
|
|
32
|
-
if (schema.oneOf) {
|
|
33
|
-
const oneOf = schema.oneOf.filter((item) => isComplexType(item));
|
|
34
|
-
if (oneOf.length === 0 || oneOf.some((item) => ctx.stack.has(item)))
|
|
35
|
-
return;
|
|
36
|
-
if (oneOf.length === 1) {
|
|
37
|
-
return propertyBody(oneOf[0], renderPrimitive, next);
|
|
38
|
-
}
|
|
39
|
-
return (_jsxs(Tabs, { defaultValue: "0", children: [_jsx(TabsList, { children: oneOf.map((item, i) => (_jsx(TabsTrigger, { value: i.toString(), children: schemaToString(item, renderContext.schema) }, i))) }), oneOf.map((item, i) => (_jsxs(TabsContent, { value: i.toString(), children: [item.description && _jsx(Markdown, { text: item.description }), propertyInfo(item), propertyBody(item, (child, ctx) => primitiveBody(child, ctx, false, true), next)] }, i)))] }));
|
|
40
|
-
}
|
|
41
|
-
const of = schema.allOf ?? schema.anyOf;
|
|
42
|
-
if (of) {
|
|
43
|
-
if (of.length === 0)
|
|
44
|
-
return;
|
|
45
|
-
if (of.some((item) => typeof item === 'object' && ctx.stack.has(item)))
|
|
46
|
-
return;
|
|
47
|
-
const combined = combineSchema(of);
|
|
48
|
-
if (typeof combined === 'boolean')
|
|
49
|
-
return;
|
|
50
|
-
return renderPrimitive(combined, ctx);
|
|
51
|
-
}
|
|
52
|
-
return renderPrimitive(schema, ctx);
|
|
53
|
-
}
|
|
54
|
-
function propertyInfo(schema) {
|
|
55
|
-
const fields = [];
|
|
56
|
-
if (schema.default !== undefined) {
|
|
57
|
-
fields.push({
|
|
58
|
-
key: 'Default',
|
|
59
|
-
value: JSON.stringify(schema.default),
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (schema.pattern) {
|
|
63
|
-
fields.push({
|
|
64
|
-
key: 'Match',
|
|
65
|
-
value: schema.pattern,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (schema.format) {
|
|
69
|
-
fields.push({
|
|
70
|
-
key: 'Format',
|
|
71
|
-
value: schema.format,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
if (schema.multipleOf) {
|
|
75
|
-
fields.push({
|
|
76
|
-
key: 'Multiple Of',
|
|
77
|
-
value: String(schema.multipleOf),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
let range = getRange('value', schema.minimum, schema.exclusiveMinimum, schema.maximum, schema.exclusiveMaximum);
|
|
81
|
-
if (range)
|
|
82
|
-
fields.push({
|
|
83
|
-
key: 'Range',
|
|
84
|
-
value: range,
|
|
85
|
-
});
|
|
86
|
-
range = getRange('length', schema.minLength, undefined, schema.maxLength, undefined);
|
|
87
|
-
if (range)
|
|
88
|
-
fields.push({
|
|
89
|
-
key: 'Length',
|
|
90
|
-
value: range,
|
|
91
|
-
});
|
|
92
|
-
range = getRange('properties', schema.minProperties, undefined, schema.maxProperties, undefined);
|
|
93
|
-
if (range)
|
|
94
|
-
fields.push({
|
|
95
|
-
key: 'Properties',
|
|
96
|
-
value: range,
|
|
97
|
-
});
|
|
98
|
-
range = getRange('items', schema.minItems, undefined, schema.maxItems, undefined);
|
|
99
|
-
if (range)
|
|
100
|
-
fields.push({
|
|
101
|
-
key: 'Items',
|
|
102
|
-
value: range,
|
|
103
|
-
});
|
|
104
|
-
if (schema.enum) {
|
|
105
|
-
fields.push({
|
|
106
|
-
key: 'Value in',
|
|
107
|
-
value: schema.enum.map((value) => JSON.stringify(value)).join(' | '),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (fields.length === 0)
|
|
111
|
-
return;
|
|
112
|
-
return (_jsx("div", { className: "flex flex-wrap gap-2 not-prose", children: fields.map((field) => (_jsxs("div", { className: "bg-fd-secondary border rounded-lg text-xs p-1.5 shadow-md", children: [_jsx("span", { className: "font-medium me-2", children: field.key }), _jsx("code", { className: "text-fd-muted-foreground", children: field.value })] }, field.key))) }));
|
|
113
|
-
}
|
|
114
|
-
function primitiveBody(schema, ctx, collapsible, nested) {
|
|
115
|
-
if (ctx.stack.has(schema))
|
|
116
|
-
return _jsx("p", { children: "Recursive" });
|
|
117
|
-
if (schema.type === 'object') {
|
|
118
|
-
const props = Object.entries(schema.properties ?? {});
|
|
119
|
-
const patternProps = Object.entries(schema.patternProperties ?? {});
|
|
120
|
-
const next = {
|
|
121
|
-
...ctx,
|
|
122
|
-
stack: ctx.stack.next(schema),
|
|
123
|
-
};
|
|
124
|
-
if (props.length === 0 && patternProps.length === 0)
|
|
125
|
-
return _jsx("p", { children: "Empty Object" });
|
|
126
|
-
const children = (_jsxs(_Fragment, { children: [props.map(([key, value]) => (_jsx(Fragment, { children: property(key, value, next, {
|
|
127
|
-
required: schema.required?.includes(key) ?? false,
|
|
128
|
-
nested,
|
|
129
|
-
}) }, key))), patternProps.map(([key, value]) => (_jsx(Fragment, { children: property(key, value, next, { nested }) }, key))), schema.additionalProperties &&
|
|
130
|
-
property('[key: string]', schema.additionalProperties, next, {
|
|
131
|
-
nested,
|
|
132
|
-
})] }));
|
|
133
|
-
if (!collapsible)
|
|
134
|
-
return children;
|
|
135
|
-
return (_jsx(renderer.ObjectCollapsible, { name: "Show Attributes", children: children }));
|
|
136
|
-
}
|
|
137
|
-
if (schema.type === 'array') {
|
|
138
|
-
const items = schema.items;
|
|
139
|
-
if (!items || typeof items === 'boolean' || ctx.stack.has(items))
|
|
140
|
-
return;
|
|
141
|
-
return (_jsxs(renderer.ObjectCollapsible, { name: "Array Item", children: [_jsxs("div", { className: "text-sm border-t p-3 border-x prose-no-margin bg-fd-card last:rounded-b-xl first:rounded-tr-xl last:border-b empty:hidden", children: [_jsx(Markdown, { text: items.description ?? 'No Description' }), propertyInfo(items)] }), propertyBody(items, (child, ctx) => primitiveBody(child, ctx, false, true), {
|
|
142
|
-
...ctx,
|
|
143
|
-
stack: ctx.stack.next(schema),
|
|
144
|
-
})] }));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function property(key, schema, ctx, props) {
|
|
148
|
-
if (schema === true) {
|
|
149
|
-
return _jsx(renderer.Property, { name: key, type: "any", ...props });
|
|
150
|
-
}
|
|
151
|
-
else if (schema === false) {
|
|
152
|
-
return _jsx(renderer.Property, { name: key, type: "never", ...props });
|
|
153
|
-
}
|
|
154
|
-
if (ctx.stack.has(schema))
|
|
155
|
-
return;
|
|
156
|
-
if ((schema.readOnly && !readOnly) || (schema.writeOnly && !writeOnly))
|
|
157
|
-
return;
|
|
158
|
-
return (_jsxs(renderer.Property, { name: key, type: schemaToString(schema, renderContext.schema), deprecated: schema.deprecated, ...props, children: [schema.description && _jsx(Markdown, { text: schema.description }), propertyInfo(schema), propertyBody(schema, (child, ctx) => primitiveBody(child, ctx, true, true), ctx)] }));
|
|
159
|
-
}
|
|
160
|
-
const context = {
|
|
161
|
-
stack: schemaStack(renderContext),
|
|
162
|
-
};
|
|
163
|
-
if (typeof schema === 'boolean' ||
|
|
164
|
-
as === 'property' ||
|
|
165
|
-
!isComplexType(schema))
|
|
166
|
-
return property(name, schema, context, { required });
|
|
167
|
-
return propertyBody(schema, (child, ctx) => primitiveBody(child, ctx, false, false), context);
|
|
168
|
-
}
|
|
169
|
-
function schemaStack(renderContext, parent) {
|
|
170
|
-
const ids = new Set();
|
|
171
|
-
function getId(schema) {
|
|
172
|
-
if (typeof schema !== 'object')
|
|
173
|
-
return;
|
|
174
|
-
if (schema.title)
|
|
175
|
-
return schema.title;
|
|
176
|
-
return renderContext.schema.getRawRef(schema);
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
history: parent ? [...parent.history] : [],
|
|
180
|
-
next(...schemas) {
|
|
181
|
-
const child = schemaStack(renderContext, this);
|
|
182
|
-
for (const item of schemas) {
|
|
183
|
-
child.add(item);
|
|
184
|
-
}
|
|
185
|
-
return child;
|
|
186
|
-
},
|
|
187
|
-
add(schema) {
|
|
188
|
-
if (typeof schema !== 'object')
|
|
189
|
-
return;
|
|
190
|
-
const id = getId(schema);
|
|
191
|
-
if (id)
|
|
192
|
-
ids.add(id);
|
|
193
|
-
this.history.push(schema);
|
|
194
|
-
},
|
|
195
|
-
has(schema) {
|
|
196
|
-
if (this.history.length > 30) {
|
|
197
|
-
console.warn(`[Fumadocs OpenAPI] schema depth exceeded 30, this might be unexpected.`);
|
|
198
|
-
// stopping at here
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
if (parent && parent.has(schema))
|
|
202
|
-
return true;
|
|
203
|
-
const id = getId(schema);
|
|
204
|
-
if (id)
|
|
205
|
-
return ids.has(id);
|
|
206
|
-
return this.history.includes(schema);
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Check if the schema needs another collapsible to explain
|
|
212
|
-
*/
|
|
213
|
-
function isComplexType(schema) {
|
|
214
|
-
if (typeof schema === 'boolean')
|
|
215
|
-
return false;
|
|
216
|
-
const arr = schema.anyOf ?? schema.oneOf ?? schema.allOf;
|
|
217
|
-
if (arr && arr.some(isComplexType))
|
|
218
|
-
return true;
|
|
219
|
-
return (schema.type === 'object' ||
|
|
220
|
-
(schema.type === 'array' && schema.items != null));
|
|
221
|
-
}
|
|
222
|
-
function getRange(value, min, exclusiveMin, max, exclusiveMax) {
|
|
223
|
-
const out = [];
|
|
224
|
-
if (min !== undefined) {
|
|
225
|
-
out.push(`${min} <=`);
|
|
226
|
-
}
|
|
227
|
-
else if (exclusiveMin !== undefined) {
|
|
228
|
-
out.push(`${exclusiveMin} <`);
|
|
229
|
-
}
|
|
230
|
-
out.push(value);
|
|
231
|
-
if (max !== undefined) {
|
|
232
|
-
out.push(`<= ${max}`);
|
|
233
|
-
}
|
|
234
|
-
else if (exclusiveMax !== undefined) {
|
|
235
|
-
out.push(`< ${exclusiveMax}`);
|
|
236
|
-
}
|
|
237
|
-
if (out.length > 1)
|
|
238
|
-
return out.join(' ');
|
|
239
|
-
}
|