fumadocs-openapi 6.0.1 → 6.0.2
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/build-routes.d.ts +15 -0
- package/dist/build-routes.d.ts.map +1 -0
- package/dist/build-routes.js +38 -0
- package/dist/generate-file.d.ts +38 -0
- package/dist/generate-file.d.ts.map +1 -0
- package/dist/generate-file.js +118 -0
- package/dist/generate.d.ts +48 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +129 -0
- package/dist/index.d.ts +4 -274
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -389
- package/dist/render/codeblock.d.ts +9 -0
- package/dist/render/codeblock.d.ts.map +1 -0
- package/dist/render/codeblock.js +13 -0
- package/dist/render/heading.d.ts +4 -0
- package/dist/render/heading.d.ts.map +1 -0
- package/dist/render/heading.js +6 -0
- package/dist/render/markdown.d.ts +5 -0
- package/dist/render/markdown.d.ts.map +1 -0
- package/dist/render/markdown.js +25 -0
- package/dist/render/operation.d.ts +17 -0
- package/dist/render/operation.d.ts.map +1 -0
- package/dist/render/operation.js +230 -0
- package/dist/render/playground.d.ts +66 -0
- package/dist/render/playground.d.ts.map +1 -0
- package/dist/render/playground.js +181 -0
- package/dist/render/renderer.d.ts +76 -0
- package/dist/render/renderer.d.ts.map +1 -0
- package/dist/render/renderer.js +23 -0
- package/dist/render/schema.d.ts +29 -0
- package/dist/render/schema.d.ts.map +1 -0
- package/dist/render/schema.js +151 -0
- package/dist/requests/curl.d.ts +3 -0
- package/dist/requests/curl.d.ts.map +1 -0
- package/dist/requests/curl.js +33 -0
- package/dist/requests/go.d.ts +3 -0
- package/dist/requests/go.d.ts.map +1 -0
- package/dist/requests/go.js +54 -0
- package/dist/requests/javascript.d.ts +3 -0
- package/dist/requests/javascript.d.ts.map +1 -0
- package/dist/requests/javascript.js +49 -0
- package/dist/requests/python.d.ts +3 -0
- package/dist/requests/python.d.ts.map +1 -0
- package/dist/requests/python.js +45 -0
- package/dist/scalar/client.d.ts +6 -0
- package/dist/scalar/client.d.ts.map +1 -0
- package/dist/scalar/client.js +25 -0
- package/dist/scalar/index.d.ts +4 -173
- package/dist/scalar/index.d.ts.map +1 -0
- package/dist/scalar/index.js +4 -11
- package/dist/server/api-page.d.ts +33 -0
- package/dist/server/api-page.d.ts.map +1 -0
- package/dist/server/api-page.js +59 -0
- package/dist/server/create-method.d.ts +7 -0
- package/dist/server/create-method.d.ts.map +1 -0
- package/dist/server/create-method.js +12 -0
- package/dist/server/create.d.ts +16 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/create.js +11 -0
- package/dist/server/index.d.ts +3 -221
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +2 -1493
- package/dist/server/proxy.d.ts +8 -0
- package/dist/server/proxy.d.ts.map +1 -0
- package/dist/server/proxy.js +53 -0
- package/dist/server/source-api.d.ts +8 -0
- package/dist/server/source-api.d.ts.map +1 -0
- package/dist/server/source-api.js +34 -0
- package/dist/types.d.ts +60 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/ui/client.d.ts +22 -0
- package/dist/ui/client.d.ts.map +1 -0
- package/dist/ui/client.js +10 -0
- package/dist/ui/components/input.d.ts +6 -0
- package/dist/ui/components/input.d.ts.map +1 -0
- package/dist/ui/components/input.js +10 -0
- package/dist/ui/components/method-label.d.ts +5 -0
- package/dist/ui/components/method-label.d.ts.map +1 -0
- package/dist/ui/components/method-label.js +33 -0
- package/dist/ui/components/select.d.ts +14 -0
- package/dist/ui/components/select.d.ts.map +1 -0
- package/dist/ui/components/select.js +24 -0
- package/dist/ui/components/variants.d.ts +6 -0
- package/dist/ui/components/variants.d.ts.map +1 -0
- package/dist/ui/components/variants.js +26 -0
- package/dist/ui/contexts/api.d.ts +28 -0
- package/dist/ui/contexts/api.d.ts.map +1 -0
- package/dist/ui/contexts/api.js +74 -0
- package/dist/ui/contexts/schema.d.ts +17 -0
- package/dist/ui/contexts/schema.d.ts.map +1 -0
- package/dist/ui/contexts/schema.js +8 -0
- package/dist/ui/index.d.ts +12 -302
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +18 -98
- package/dist/ui/playground/fetcher.d.ts +34 -0
- package/dist/ui/playground/fetcher.d.ts.map +1 -0
- package/dist/ui/{fetcher-CsHhplmD.js → playground/fetcher.js} +45 -44
- package/dist/ui/playground/get-default-values.d.ts +4 -0
- package/dist/ui/playground/get-default-values.d.ts.map +1 -0
- package/dist/ui/playground/get-default-values.js +24 -0
- package/dist/ui/playground/index.d.ts +44 -0
- package/dist/ui/playground/index.d.ts.map +1 -0
- package/dist/ui/playground/index.js +187 -0
- package/dist/ui/playground/inputs.d.ts +23 -0
- package/dist/ui/playground/inputs.d.ts.map +1 -0
- package/dist/ui/playground/inputs.js +172 -0
- package/dist/ui/playground/resolve.d.ts +6 -0
- package/dist/ui/playground/resolve.d.ts.map +1 -0
- package/dist/ui/playground/resolve.js +14 -0
- package/dist/ui/playground/status-info.d.ts +8 -0
- package/dist/ui/playground/status-info.d.ts.map +1 -0
- package/dist/ui/playground/status-info.js +40 -0
- package/dist/ui/server-select.d.ts +3 -0
- package/dist/ui/server-select.d.ts.map +1 -0
- package/dist/ui/server-select.js +27 -0
- package/dist/utils/combine-schema.d.ts +6 -0
- package/dist/utils/combine-schema.d.ts.map +1 -0
- package/dist/utils/combine-schema.js +46 -0
- package/dist/utils/generate-document.d.ts +20 -0
- package/dist/utils/generate-document.d.ts.map +1 -0
- package/dist/utils/generate-document.js +82 -0
- package/dist/utils/generate-sample.d.ts +33 -0
- package/dist/utils/generate-sample.d.ts.map +1 -0
- package/dist/utils/generate-sample.js +97 -0
- package/dist/utils/get-security.d.ts +8 -0
- package/dist/utils/get-security.d.ts.map +1 -0
- package/dist/utils/get-security.js +23 -0
- package/dist/utils/get-typescript-schema.d.ts +4 -0
- package/dist/utils/get-typescript-schema.d.ts.map +1 -0
- package/dist/utils/get-typescript-schema.js +18 -0
- package/dist/utils/id-to-title.d.ts +2 -0
- package/dist/utils/id-to-title.d.ts.map +1 -0
- package/dist/utils/id-to-title.js +17 -0
- package/dist/utils/input-to-string.d.ts +5 -0
- package/dist/utils/input-to-string.d.ts.map +1 -0
- package/dist/utils/input-to-string.js +21 -0
- package/dist/utils/process-document.d.ts +14 -0
- package/dist/utils/process-document.d.ts.map +1 -0
- package/dist/utils/process-document.js +32 -0
- package/dist/utils/schema.d.ts +9 -0
- package/dist/utils/schema.d.ts.map +1 -0
- package/dist/utils/schema.js +16 -0
- package/dist/utils/server-url.d.ts +2 -0
- package/dist/utils/server-url.d.ts.map +1 -0
- package/dist/utils/server-url.js +7 -0
- package/dist/utils/use-query.d.ts +6 -0
- package/dist/utils/use-query.d.ts.map +1 -0
- package/dist/utils/use-query.js +22 -0
- package/package.json +7 -7
- package/dist/scalar/client-client-BXAjVueF.js +0 -93
- package/dist/ui/client-client-CYO00OiB.js +0 -107
- package/dist/ui/index-client-BUeWwFWK.js +0 -1116
- package/dist/ui/server-select-client-Ct_HJ46K.js +0 -86
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
import { generateSample } from '../utils/generate-sample';
|
|
4
|
+
import * as CURL from '../requests/curl';
|
|
5
|
+
import * as JS from '../requests/javascript';
|
|
6
|
+
import * as Go from '../requests/go';
|
|
7
|
+
import * as Python from '../requests/python';
|
|
8
|
+
import { getPreferredType } from '../utils/schema';
|
|
9
|
+
import { getTypescriptSchema } from '../utils/get-typescript-schema';
|
|
10
|
+
import { getSecurities, getSecurityPrefix } from '../utils/get-security';
|
|
11
|
+
import { idToTitle } from '../utils/id-to-title';
|
|
12
|
+
import { Markdown } from './markdown';
|
|
13
|
+
import { heading } from './heading';
|
|
14
|
+
import { Schema } from './schema';
|
|
15
|
+
import { createMethod } from '../server/create-method';
|
|
16
|
+
import { methodKeys } from '../build-routes';
|
|
17
|
+
export function Operation({ type = 'operation', path, method, ctx, hasHead, headingLevel = 2, }) {
|
|
18
|
+
const body = method.requestBody;
|
|
19
|
+
const security = method.security ?? ctx.schema.document.security;
|
|
20
|
+
let headNode = null;
|
|
21
|
+
let bodyNode = null;
|
|
22
|
+
let responseNode = null;
|
|
23
|
+
let callbacksNode = null;
|
|
24
|
+
if (hasHead) {
|
|
25
|
+
const title = method.summary ??
|
|
26
|
+
(method.operationId ? idToTitle(method.operationId) : path);
|
|
27
|
+
headNode = (_jsxs(_Fragment, { children: [heading(headingLevel, title, ctx), method.description ? (_jsx(Markdown, { text: method.description }, "description")) : null] }));
|
|
28
|
+
headingLevel++;
|
|
29
|
+
}
|
|
30
|
+
if (body) {
|
|
31
|
+
const type = getPreferredType(body.content);
|
|
32
|
+
if (!type)
|
|
33
|
+
throw new Error(`No supported media type for body content: ${path}`);
|
|
34
|
+
bodyNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Request Body', ctx), _jsxs("div", { className: "mb-8 flex flex-row items-center justify-between gap-2", children: [_jsx("code", { children: type }), _jsx("span", { children: body.required ? 'Required' : 'Optional' })] }), body.description ? _jsx(Markdown, { text: body.description }) : null, _jsx(Schema, { name: "body", schema: body.content[type].schema ?? {}, ctx: {
|
|
35
|
+
readOnly: method.method === 'GET',
|
|
36
|
+
writeOnly: method.method !== 'GET',
|
|
37
|
+
required: body.required ?? false,
|
|
38
|
+
render: ctx,
|
|
39
|
+
allowFile: type === 'multipart/form-data',
|
|
40
|
+
} })] }));
|
|
41
|
+
}
|
|
42
|
+
if (method.responses && ctx.showResponseSchema) {
|
|
43
|
+
responseNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Response Body', ctx), Object.entries(method.responses).map(([status, response]) => {
|
|
44
|
+
if (!response.content)
|
|
45
|
+
return;
|
|
46
|
+
const mediaType = getPreferredType(response.content);
|
|
47
|
+
if (!mediaType)
|
|
48
|
+
return null;
|
|
49
|
+
const content = response.content[mediaType];
|
|
50
|
+
if (!content.schema)
|
|
51
|
+
return null;
|
|
52
|
+
return (_jsxs(Fragment, { children: [heading(headingLevel + 1, status, ctx), _jsx(Markdown, { text: response.description }), _jsx(Schema, { name: "response", schema: content.schema, ctx: {
|
|
53
|
+
render: ctx,
|
|
54
|
+
writeOnly: false,
|
|
55
|
+
readOnly: true,
|
|
56
|
+
required: true,
|
|
57
|
+
} })] }, status));
|
|
58
|
+
})] }));
|
|
59
|
+
}
|
|
60
|
+
const parameterGroups = new Map();
|
|
61
|
+
const endpoint = generateSample(path, method, ctx);
|
|
62
|
+
for (const param of method.parameters ?? []) {
|
|
63
|
+
const pInfo = endpoint.parameters.find((item) => item.name === param.name && item.in === param.in);
|
|
64
|
+
if (!pInfo)
|
|
65
|
+
continue;
|
|
66
|
+
const schema = pInfo.schema;
|
|
67
|
+
const groupName = {
|
|
68
|
+
path: 'Path Parameters',
|
|
69
|
+
query: 'Query Parameters',
|
|
70
|
+
header: 'Header Parameters',
|
|
71
|
+
cookie: 'Cookie Parameters',
|
|
72
|
+
}[param.in] ?? 'Other Parameters';
|
|
73
|
+
const group = parameterGroups.get(groupName) ?? [];
|
|
74
|
+
group.push(_jsx(Schema, { name: param.name, schema: {
|
|
75
|
+
...schema,
|
|
76
|
+
description: param.description ?? schema.description,
|
|
77
|
+
deprecated: (param.deprecated ?? false) || (schema.deprecated ?? false),
|
|
78
|
+
}, ctx: {
|
|
79
|
+
parseObject: false,
|
|
80
|
+
readOnly: method.method === 'GET',
|
|
81
|
+
writeOnly: method.method !== 'GET',
|
|
82
|
+
required: param.required ?? false,
|
|
83
|
+
render: ctx,
|
|
84
|
+
} }, param.name));
|
|
85
|
+
parameterGroups.set(groupName, group);
|
|
86
|
+
}
|
|
87
|
+
if (method.callbacks) {
|
|
88
|
+
callbacksNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Webhooks', ctx), Object.entries(method.callbacks).map(([name, callback]) => (_jsx(WebhookCallback, { callback: callback, ctx: ctx, headingLevel: headingLevel }, name)))] }));
|
|
89
|
+
}
|
|
90
|
+
const info = (_jsxs(ctx.renderer.APIInfo, { head: headNode, method: method.method, route: path, children: [type === 'operation' ? (_jsx(ctx.renderer.APIPlayground, { path: path, method: method, ctx: ctx })) : null, security ? (_jsxs(_Fragment, { children: [heading(headingLevel, 'Authorization', ctx), _jsx(AuthSection, { requirements: security, ctx: ctx })] })) : null, bodyNode, Array.from(parameterGroups.entries()).map(([group, params]) => {
|
|
91
|
+
return (_jsxs(Fragment, { children: [heading(headingLevel, group, ctx), params] }, group));
|
|
92
|
+
}), responseNode, callbacksNode] }));
|
|
93
|
+
if (type === 'operation') {
|
|
94
|
+
return (_jsxs(ctx.renderer.API, { children: [info, _jsx(APIExample, { method: method, endpoint: endpoint, ctx: ctx })] }));
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return info;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const defaultSamples = [
|
|
101
|
+
{
|
|
102
|
+
label: 'cURL',
|
|
103
|
+
source: CURL.getSampleRequest,
|
|
104
|
+
lang: 'bash',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: 'JavaScript',
|
|
108
|
+
source: JS.getSampleRequest,
|
|
109
|
+
lang: 'js',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
label: 'Go',
|
|
113
|
+
source: Go.getSampleRequest,
|
|
114
|
+
lang: 'go',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
label: 'Python',
|
|
118
|
+
source: Python.getSampleRequest,
|
|
119
|
+
lang: 'python',
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
async function APIExample({ method, endpoint, ctx, }) {
|
|
123
|
+
const renderer = ctx.renderer;
|
|
124
|
+
const children = [];
|
|
125
|
+
const samples = dedupe([
|
|
126
|
+
...defaultSamples,
|
|
127
|
+
...(ctx.generateCodeSamples ? await ctx.generateCodeSamples(endpoint) : []),
|
|
128
|
+
...(method['x-codeSamples'] ?? []),
|
|
129
|
+
]).flatMap((sample) => {
|
|
130
|
+
if (sample.source === false)
|
|
131
|
+
return [];
|
|
132
|
+
const result = typeof sample.source === 'function'
|
|
133
|
+
? sample.source(endpoint)
|
|
134
|
+
: sample.source;
|
|
135
|
+
if (result === undefined)
|
|
136
|
+
return [];
|
|
137
|
+
return {
|
|
138
|
+
...sample,
|
|
139
|
+
source: result,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
if (samples.length > 0) {
|
|
143
|
+
children.push(_jsx(renderer.Requests, { items: samples.map((s) => s.label), children: samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }, "requests"));
|
|
144
|
+
}
|
|
145
|
+
children.push(_jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint }, "responses"));
|
|
146
|
+
return _jsx(renderer.APIExample, { children: children });
|
|
147
|
+
}
|
|
148
|
+
function WebhookCallback({ callback, ctx, headingLevel, }) {
|
|
149
|
+
return Object.entries(callback).map(([path, pathItem]) => {
|
|
150
|
+
const pathNodes = methodKeys.map((method) => {
|
|
151
|
+
const operation = pathItem[method];
|
|
152
|
+
if (!operation)
|
|
153
|
+
return null;
|
|
154
|
+
return (_jsx(Operation, { type: "webhook", hasHead: true, path: path, headingLevel: headingLevel + 1, method: createMethod(method, pathItem, operation), ctx: ctx }, method));
|
|
155
|
+
});
|
|
156
|
+
return _jsx(Fragment, { children: pathNodes }, path);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Remove duplicated labels
|
|
161
|
+
*/
|
|
162
|
+
function dedupe(samples) {
|
|
163
|
+
const set = new Set();
|
|
164
|
+
const out = [];
|
|
165
|
+
for (let i = samples.length - 1; i >= 0; i--) {
|
|
166
|
+
if (set.has(samples[i].label))
|
|
167
|
+
continue;
|
|
168
|
+
set.add(samples[i].label);
|
|
169
|
+
out.unshift(samples[i]);
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
function AuthSection({ ctx: { schema: { document }, renderer, }, requirements, }) {
|
|
174
|
+
let id = 0;
|
|
175
|
+
const info = [];
|
|
176
|
+
for (const requirement of requirements) {
|
|
177
|
+
for (const schema of getSecurities(requirement, document)) {
|
|
178
|
+
const prefix = getSecurityPrefix(schema);
|
|
179
|
+
const scopeElement = schema.scopes.length > 0 ? (_jsxs("p", { children: ["Scope: ", _jsx("code", { children: schema.scopes.join(', ') })] })) : null;
|
|
180
|
+
if (schema.type === 'http' || schema.type === 'oauth2') {
|
|
181
|
+
info.push(_jsxs(renderer.Property, { name: "Authorization", type: prefix ? `${prefix} <token>` : '<token>', required: true, children: [schema.description ? _jsx(Markdown, { text: schema.description }) : null, _jsxs("p", { children: ["In: ", _jsx("code", { children: "header" })] }), scopeElement] }, id++));
|
|
182
|
+
}
|
|
183
|
+
if (schema.type === 'apiKey') {
|
|
184
|
+
info.push(_jsxs(renderer.Property, { name: schema.name, type: "<token>", children: [schema.description ? _jsx(Markdown, { text: schema.description }) : null, _jsxs("p", { children: ["In: ", _jsx("code", { children: schema.in }), scopeElement] })] }, id++));
|
|
185
|
+
}
|
|
186
|
+
if (schema.type === 'openIdConnect') {
|
|
187
|
+
info.push(_jsxs(renderer.Property, { name: "OpenID Connect", type: "<token>", required: true, children: [schema.description ? _jsx(Markdown, { text: schema.description }) : null, scopeElement] }, id++));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return info;
|
|
192
|
+
}
|
|
193
|
+
async function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
|
|
194
|
+
const items = [];
|
|
195
|
+
const children = [];
|
|
196
|
+
if (!operation.responses)
|
|
197
|
+
return null;
|
|
198
|
+
for (const code of Object.keys(operation.responses)) {
|
|
199
|
+
const types = [];
|
|
200
|
+
let description = operation.responses[code].description;
|
|
201
|
+
if (!description && code in endpoint.responses)
|
|
202
|
+
description = endpoint.responses[code].schema.description ?? '';
|
|
203
|
+
if (code in endpoint.responses) {
|
|
204
|
+
types.push({
|
|
205
|
+
lang: 'json',
|
|
206
|
+
label: 'Response',
|
|
207
|
+
code: JSON.stringify(endpoint.responses[code].sample, null, 2),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
let ts;
|
|
211
|
+
if (generateTypeScriptSchema) {
|
|
212
|
+
ts = await generateTypeScriptSchema(endpoint, code);
|
|
213
|
+
}
|
|
214
|
+
else if (generateTypeScriptSchema === undefined) {
|
|
215
|
+
ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
|
|
216
|
+
}
|
|
217
|
+
if (ts) {
|
|
218
|
+
types.push({
|
|
219
|
+
code: ts,
|
|
220
|
+
lang: 'ts',
|
|
221
|
+
label: 'TypeScript',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
items.push(code);
|
|
225
|
+
children.push(_jsxs(renderer.Response, { value: code, children: [_jsx(Markdown, { text: description }), types.length > 0 ? (_jsx(renderer.ResponseTypes, { children: types.map((type) => (_jsx(renderer.ResponseType, { ...type }, type.lang))) })) : null] }, code));
|
|
226
|
+
}
|
|
227
|
+
if (items.length === 0)
|
|
228
|
+
return null;
|
|
229
|
+
return _jsx(renderer.Responses, { items: items, children: children });
|
|
230
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MethodInformation, RenderContext } from '../types';
|
|
3
|
+
import { type Security } from '../utils/get-security';
|
|
4
|
+
interface BaseRequestField {
|
|
5
|
+
name: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
interface BaseSchema {
|
|
9
|
+
description?: string;
|
|
10
|
+
isRequired: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
|
|
13
|
+
interface PrimitiveSchema extends BaseSchema {
|
|
14
|
+
type: 'boolean' | 'string' | 'number';
|
|
15
|
+
defaultValue: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ReferenceSchema extends BaseSchema {
|
|
18
|
+
type: 'ref';
|
|
19
|
+
schema: string;
|
|
20
|
+
}
|
|
21
|
+
interface ArraySchema extends BaseSchema {
|
|
22
|
+
type: 'array';
|
|
23
|
+
/**
|
|
24
|
+
* Reference to item schema or the schema
|
|
25
|
+
*/
|
|
26
|
+
items: string | RequestSchema;
|
|
27
|
+
}
|
|
28
|
+
interface FileSchema extends BaseSchema {
|
|
29
|
+
type: 'file';
|
|
30
|
+
}
|
|
31
|
+
interface ObjectSchema extends BaseSchema {
|
|
32
|
+
type: 'object';
|
|
33
|
+
properties: Record<string, RequestSchema | ReferenceSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* Reference to schema, or true if it's `any`
|
|
36
|
+
*/
|
|
37
|
+
additionalProperties?: boolean | string;
|
|
38
|
+
}
|
|
39
|
+
interface SwitcherSchema extends BaseSchema {
|
|
40
|
+
type: 'switcher';
|
|
41
|
+
items: Record<string, ReferenceSchema | RequestSchema>;
|
|
42
|
+
}
|
|
43
|
+
interface NullSchema extends BaseSchema {
|
|
44
|
+
type: 'null';
|
|
45
|
+
}
|
|
46
|
+
export type RequestSchema = PrimitiveSchema | ArraySchema | ObjectSchema | SwitcherSchema | NullSchema | FileSchema;
|
|
47
|
+
export interface APIPlaygroundProps {
|
|
48
|
+
route: string;
|
|
49
|
+
method: string;
|
|
50
|
+
authorization?: Security;
|
|
51
|
+
path?: PrimitiveRequestField[];
|
|
52
|
+
query?: PrimitiveRequestField[];
|
|
53
|
+
header?: PrimitiveRequestField[];
|
|
54
|
+
body?: RequestSchema & {
|
|
55
|
+
mediaType: string;
|
|
56
|
+
};
|
|
57
|
+
schemas: Record<string, RequestSchema>;
|
|
58
|
+
proxyUrl?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function Playground({ path, method, ctx, }: {
|
|
61
|
+
path: string;
|
|
62
|
+
method: MethodInformation;
|
|
63
|
+
ctx: RenderContext;
|
|
64
|
+
}): ReactNode;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=playground.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../../src/render/playground.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EACV,iBAAiB,EAEjB,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGpE,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,UAAU;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAEvE,UAAU,eAAgB,SAAQ,UAAU;IAC1C,IAAI,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACtC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,WAAY,SAAQ,UAAU;IACtC,IAAI,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC;CAC/B;AAED,UAAU,UAAW,SAAQ,UAAU;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,YAAa,SAAQ,UAAU;IACvC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC,CAAC;IAE5D;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACzC;AAED,UAAU,cAAe,SAAQ,UAAU;IACzC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,aAAa,CAAC,CAAC;CACxD;AAED,UAAU,UAAW,SAAQ,UAAU;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,WAAW,GACX,YAAY,GACZ,cAAc,GACd,UAAU,GACV,UAAU,CAAC;AAUf,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,IAAI,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,qBAAqB,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAC;IACjC,IAAI,CAAC,EAAE,aAAa,GAAG;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,GAAG,SAAS,CA6CZ"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getPreferredType, } from '../utils/schema';
|
|
3
|
+
import { getSecurities } from '../utils/get-security';
|
|
4
|
+
import { APIPlayground } from '../ui';
|
|
5
|
+
export function Playground({ path, method, ctx, }) {
|
|
6
|
+
let currentId = 0;
|
|
7
|
+
const bodyContent = method.requestBody?.content;
|
|
8
|
+
const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;
|
|
9
|
+
const context = {
|
|
10
|
+
allowFile: mediaType === 'multipart/form-data',
|
|
11
|
+
references: {},
|
|
12
|
+
nextId() {
|
|
13
|
+
return String(currentId++);
|
|
14
|
+
},
|
|
15
|
+
registered: new WeakMap(),
|
|
16
|
+
render: ctx,
|
|
17
|
+
};
|
|
18
|
+
const bodySchema = bodyContent && mediaType && bodyContent[mediaType].schema
|
|
19
|
+
? toSchema(bodyContent[mediaType].schema, true, context)
|
|
20
|
+
: undefined;
|
|
21
|
+
const props = {
|
|
22
|
+
authorization: getAuthorizationField(method, ctx),
|
|
23
|
+
method: method.method,
|
|
24
|
+
route: path,
|
|
25
|
+
path: method.parameters
|
|
26
|
+
?.filter((v) => v.in === 'path')
|
|
27
|
+
.map((v) => parameterToField(v, context)),
|
|
28
|
+
query: method.parameters
|
|
29
|
+
?.filter((v) => v.in === 'query')
|
|
30
|
+
.map((v) => parameterToField(v, context)),
|
|
31
|
+
header: method.parameters
|
|
32
|
+
?.filter((v) => v.in === 'header')
|
|
33
|
+
.map((v) => parameterToField(v, context)),
|
|
34
|
+
body: bodySchema && mediaType
|
|
35
|
+
? {
|
|
36
|
+
...bodySchema,
|
|
37
|
+
mediaType: mediaType,
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
schemas: context.references,
|
|
41
|
+
proxyUrl: ctx.proxyUrl,
|
|
42
|
+
};
|
|
43
|
+
return _jsx(APIPlayground, { ...props });
|
|
44
|
+
}
|
|
45
|
+
function getAuthorizationField(method, { schema: { document } }) {
|
|
46
|
+
const security = method.security ?? document.security ?? [];
|
|
47
|
+
if (security.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
const singular = security.find((requirements) => Object.keys(requirements).length === 1);
|
|
50
|
+
if (!singular)
|
|
51
|
+
return;
|
|
52
|
+
return getSecurities(singular, document)[0];
|
|
53
|
+
}
|
|
54
|
+
function getIdFromSchema(schema, required, ctx) {
|
|
55
|
+
const registered = ctx.registered.get(schema);
|
|
56
|
+
if (registered === undefined) {
|
|
57
|
+
const id = ctx.nextId();
|
|
58
|
+
ctx.registered.set(schema, id);
|
|
59
|
+
ctx.references[id] = toSchema(schema, required, ctx);
|
|
60
|
+
return id;
|
|
61
|
+
}
|
|
62
|
+
return registered;
|
|
63
|
+
}
|
|
64
|
+
function parameterToField(v, ctx) {
|
|
65
|
+
return {
|
|
66
|
+
name: v.name,
|
|
67
|
+
...toSchema(v.schema ?? { type: 'string' }, v.required ?? false, ctx),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function toReference(schema, required, ctx) {
|
|
71
|
+
return {
|
|
72
|
+
type: 'ref',
|
|
73
|
+
isRequired: required,
|
|
74
|
+
schema: getIdFromSchema(schema, false, ctx),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function toSchema(schema, required, ctx) {
|
|
78
|
+
if (schema.type === 'array') {
|
|
79
|
+
return {
|
|
80
|
+
type: 'array',
|
|
81
|
+
description: schema.description ?? schema.title,
|
|
82
|
+
isRequired: required,
|
|
83
|
+
items: getIdFromSchema(schema.items, false, ctx),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (schema.type === 'object' ||
|
|
87
|
+
schema.properties !== undefined ||
|
|
88
|
+
schema.allOf !== undefined) {
|
|
89
|
+
const properties = {};
|
|
90
|
+
Object.entries(schema.properties ?? {}).forEach(([key, prop]) => {
|
|
91
|
+
properties[key] = toReference(prop, schema.required?.includes(key) ?? false, ctx);
|
|
92
|
+
});
|
|
93
|
+
schema.allOf?.forEach((c) => {
|
|
94
|
+
const field = toSchema(c, true, ctx);
|
|
95
|
+
if (field.type === 'object')
|
|
96
|
+
Object.assign(properties, field.properties);
|
|
97
|
+
});
|
|
98
|
+
const additional = schema.additionalProperties;
|
|
99
|
+
let additionalProperties;
|
|
100
|
+
if (additional && typeof additional === 'object') {
|
|
101
|
+
if ((!additional.type || additional.type.length === 0) &&
|
|
102
|
+
!additional.anyOf &&
|
|
103
|
+
!additional.allOf &&
|
|
104
|
+
!additional.oneOf) {
|
|
105
|
+
additionalProperties = true;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
additionalProperties = getIdFromSchema(additional, false, ctx);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
additionalProperties = additional;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
type: 'object',
|
|
116
|
+
isRequired: required,
|
|
117
|
+
description: schema.description ?? schema.title,
|
|
118
|
+
properties,
|
|
119
|
+
additionalProperties,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (schema.type === undefined) {
|
|
123
|
+
const combine = schema.anyOf ?? schema.oneOf;
|
|
124
|
+
if (combine) {
|
|
125
|
+
return {
|
|
126
|
+
type: 'switcher',
|
|
127
|
+
description: schema.description ?? schema.title,
|
|
128
|
+
items: Object.fromEntries(combine.map((item, idx) => {
|
|
129
|
+
return [
|
|
130
|
+
item.title ?? item.type ?? `Item ${idx.toString()}`,
|
|
131
|
+
toReference(item, true, ctx),
|
|
132
|
+
];
|
|
133
|
+
})),
|
|
134
|
+
isRequired: required,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
type: 'null',
|
|
139
|
+
isRequired: false,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (ctx.allowFile && schema.type === 'string' && schema.format === 'binary') {
|
|
143
|
+
return {
|
|
144
|
+
type: 'file',
|
|
145
|
+
isRequired: required,
|
|
146
|
+
description: schema.description ?? schema.title,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (Array.isArray(schema.type)) {
|
|
150
|
+
const items = {};
|
|
151
|
+
for (const type of schema.type) {
|
|
152
|
+
if (type === 'array') {
|
|
153
|
+
items[type] = {
|
|
154
|
+
type,
|
|
155
|
+
items: 'items' in schema && schema.items
|
|
156
|
+
? toSchema(schema.items, false, ctx)
|
|
157
|
+
: toSchema({}, required, ctx),
|
|
158
|
+
isRequired: required,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
items[type] = toSchema({
|
|
163
|
+
...schema,
|
|
164
|
+
type,
|
|
165
|
+
}, required, ctx);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
type: 'switcher',
|
|
170
|
+
description: schema.description ?? schema.title,
|
|
171
|
+
items,
|
|
172
|
+
isRequired: required,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
type: schema.type === 'integer' ? 'number' : schema.type,
|
|
177
|
+
defaultValue: (schema.example ?? ''),
|
|
178
|
+
isRequired: required,
|
|
179
|
+
description: schema.description ?? schema.title,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { MethodInformation, RenderContext, ServerObject } from '../types';
|
|
3
|
+
export interface ResponsesProps {
|
|
4
|
+
items: string[];
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export interface ResponseProps {
|
|
8
|
+
value: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export interface APIInfoProps {
|
|
12
|
+
method: string;
|
|
13
|
+
route: string;
|
|
14
|
+
head: ReactNode;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export interface PropertyProps {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
deprecated?: boolean;
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
export interface ObjectCollapsibleProps {
|
|
25
|
+
name: string;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export interface RequestProps {
|
|
29
|
+
language: string;
|
|
30
|
+
name: string;
|
|
31
|
+
code: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ResponseTypeProps {
|
|
34
|
+
lang: string;
|
|
35
|
+
code: string;
|
|
36
|
+
label: string;
|
|
37
|
+
}
|
|
38
|
+
export interface RootProps {
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
servers: ServerObject[];
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
export interface Renderer {
|
|
44
|
+
Root: ComponentType<RootProps>;
|
|
45
|
+
API: ComponentType<{
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}>;
|
|
48
|
+
APIInfo: ComponentType<APIInfoProps>;
|
|
49
|
+
APIExample: ComponentType<{
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}>;
|
|
52
|
+
Responses: ComponentType<ResponsesProps>;
|
|
53
|
+
Response: ComponentType<ResponseProps>;
|
|
54
|
+
Requests: ComponentType<{
|
|
55
|
+
items: string[];
|
|
56
|
+
children: ReactNode;
|
|
57
|
+
}>;
|
|
58
|
+
Request: ComponentType<RequestProps>;
|
|
59
|
+
ResponseTypes: ComponentType<{
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
}>;
|
|
62
|
+
ResponseType: ComponentType<ResponseTypeProps>;
|
|
63
|
+
/**
|
|
64
|
+
* Collapsible to show object schemas
|
|
65
|
+
*/
|
|
66
|
+
ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
|
|
67
|
+
Property: ComponentType<PropertyProps>;
|
|
68
|
+
APIPlayground: ComponentType<{
|
|
69
|
+
path: string;
|
|
70
|
+
method: MethodInformation;
|
|
71
|
+
ctx: RenderContext;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
export type { APIPlaygroundProps, RequestSchema, PrimitiveRequestField, ReferenceSchema, } from '../render/playground';
|
|
75
|
+
export declare function createRenders(shikiOptions: RenderContext['shikiOptions']): Renderer;
|
|
76
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAYtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG9E,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/B,GAAG,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAC5C,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,UAAU,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAEnD,SAAS,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,QAAQ,EAAE,aAAa,CAAC;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IAClE,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;QAAE,QAAQ,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;IACtD,YAAY,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE/C;;OAEG;IACH,iBAAiB,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IACzD,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;QAC3B,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,iBAAiB,CAAC;QAC1B,GAAG,EAAE,aAAa,CAAC;KACpB,CAAC,CAAC;CACJ;AAED,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,aAAa,CAC3B,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GAC1C,QAAQ,CA+CV"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
3
|
+
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
|
|
4
|
+
import { CodeBlock } from '../render/codeblock';
|
|
5
|
+
import { API, Root, APIInfo, APIExample, Property, ObjectCollapsible, } from '../ui';
|
|
6
|
+
import { Playground } from '../render/playground';
|
|
7
|
+
export function createRenders(shikiOptions) {
|
|
8
|
+
return {
|
|
9
|
+
Root: (props) => (_jsx(Root, { shikiOptions: shikiOptions, ...props, children: props.children })),
|
|
10
|
+
API,
|
|
11
|
+
APIInfo: ({ children, head }) => (_jsxs(APIInfo, { children: [head, children] })),
|
|
12
|
+
APIExample,
|
|
13
|
+
Responses: Tabs,
|
|
14
|
+
Response: Tab,
|
|
15
|
+
ResponseTypes: (props) => (_jsx(Accordions, { type: "single", className: "!-m-4 border-none pt-2", defaultValue: "Response", children: props.children })),
|
|
16
|
+
ResponseType: (props) => (_jsx(Accordion, { title: props.label, children: _jsx(CodeBlock, { code: props.code, lang: props.lang, options: shikiOptions }) })),
|
|
17
|
+
Property,
|
|
18
|
+
ObjectCollapsible,
|
|
19
|
+
Requests: (props) => (_jsx(Tabs, { groupId: "fumadocs_openapi_requests", ...props })),
|
|
20
|
+
Request: (props) => (_jsx(Tab, { value: props.name, children: _jsx(CodeBlock, { lang: props.language, code: props.code, options: shikiOptions }) })),
|
|
21
|
+
APIPlayground: Playground,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { NoReference, type ParsedSchema } from '../utils/schema';
|
|
3
|
+
import type { RenderContext } from '../types';
|
|
4
|
+
interface Context {
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
writeOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Render the full object
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue true
|
|
12
|
+
* */
|
|
13
|
+
parseObject?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Parse binary format string to be files
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue false
|
|
18
|
+
*/
|
|
19
|
+
allowFile?: boolean;
|
|
20
|
+
stack?: ParsedSchema[];
|
|
21
|
+
render: RenderContext;
|
|
22
|
+
}
|
|
23
|
+
export declare function Schema({ name, schema, ctx, }: {
|
|
24
|
+
name: string;
|
|
25
|
+
schema: NoReference<ParsedSchema>;
|
|
26
|
+
ctx: Context;
|
|
27
|
+
}): ReactNode;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAc,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7C,UAAU,OAAO;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IAEnB,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;SAIK;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IAEvB,MAAM,EAAE,aAAa,CAAC;CACvB;AAUD,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,EAAE,OAAO,CAAC;CACd,GAAG,SAAS,CA8JZ"}
|