fumadocs-openapi 10.0.11 → 10.1.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/generate-file.d.ts +6 -5
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +44 -37
- package/dist/playground/client.d.ts +9 -7
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +7 -7
- package/dist/playground/components/inputs.d.ts +6 -6
- package/dist/playground/components/inputs.d.ts.map +1 -1
- package/dist/playground/components/inputs.js +13 -12
- package/dist/playground/get-default-values.d.ts +2 -2
- package/dist/playground/get-default-values.d.ts.map +1 -1
- package/dist/playground/index.d.ts +1 -2
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +2 -0
- package/dist/playground/schema.d.ts +22 -8
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +29 -34
- package/dist/requests/generators/index.d.ts +1 -1
- package/dist/requests/generators/index.d.ts.map +1 -1
- package/dist/server/create.d.ts +1 -1
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/source-api.d.ts +5 -3
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/server/source-api.js +13 -7
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts +16 -8
- package/dist/ui/api-page.d.ts.map +1 -1
- package/dist/ui/api-page.js +7 -7
- package/dist/ui/client/index.d.ts +2 -2
- package/dist/ui/client/index.d.ts.map +1 -1
- package/dist/ui/operation/index.d.ts +4 -3
- package/dist/ui/operation/index.d.ts.map +1 -1
- package/dist/ui/operation/index.js +37 -20
- package/dist/ui/operation/request-tabs.d.ts +18 -0
- package/dist/ui/operation/request-tabs.d.ts.map +1 -0
- package/dist/ui/operation/request-tabs.js +143 -0
- package/dist/ui/operation/response-tabs.d.ts +32 -0
- package/dist/ui/operation/response-tabs.d.ts.map +1 -0
- package/dist/ui/operation/response-tabs.js +59 -0
- package/dist/ui/operation/usage-tabs/client.d.ts +23 -0
- package/dist/ui/operation/usage-tabs/client.d.ts.map +1 -0
- package/dist/ui/operation/{example-panel → usage-tabs}/client.js +50 -6
- package/dist/ui/operation/usage-tabs/index.d.ts +26 -0
- package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -0
- package/dist/ui/operation/usage-tabs/index.js +52 -0
- package/dist/ui/operation/usage-tabs/lazy.d.ts +4 -0
- package/dist/ui/operation/usage-tabs/lazy.d.ts.map +1 -0
- package/dist/ui/operation/usage-tabs/lazy.js +5 -0
- package/dist/ui/schema/client.d.ts +1 -3
- package/dist/ui/schema/client.d.ts.map +1 -1
- package/dist/ui/schema/client.js +13 -17
- package/dist/ui/schema/index.d.ts +19 -5
- package/dist/ui/schema/index.d.ts.map +1 -1
- package/dist/ui/schema/index.js +69 -29
- package/dist/utils/deep-equal.d.ts +2 -0
- package/dist/utils/deep-equal.d.ts.map +1 -0
- package/dist/utils/deep-equal.js +27 -0
- package/dist/utils/merge-schema.d.ts +7 -0
- package/dist/utils/merge-schema.d.ts.map +1 -0
- package/dist/utils/merge-schema.js +179 -0
- package/dist/utils/pages/to-body.d.ts.map +1 -1
- package/dist/utils/pages/to-body.js +2 -3
- package/dist/utils/pages/to-text.d.ts.map +1 -1
- package/dist/utils/pages/to-text.js +31 -16
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +8 -5
- package/dist/utils/use-query.d.ts +1 -0
- package/dist/utils/use-query.d.ts.map +1 -1
- package/dist/utils/use-query.js +5 -0
- package/package.json +8 -8
- package/dist/ui/contexts/operation.d.ts +0 -20
- package/dist/ui/contexts/operation.d.ts.map +0 -1
- package/dist/ui/contexts/operation.js +0 -48
- package/dist/ui/contexts/operation.lazy.d.ts +0 -2
- package/dist/ui/contexts/operation.lazy.d.ts.map +0 -1
- package/dist/ui/contexts/operation.lazy.js +0 -3
- package/dist/ui/operation/example-panel/client.d.ts +0 -4
- package/dist/ui/operation/example-panel/client.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/index.d.ts +0 -58
- package/dist/ui/operation/example-panel/index.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/index.js +0 -140
- package/dist/ui/operation/example-panel/lazy.d.ts +0 -3
- package/dist/ui/operation/example-panel/lazy.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/lazy.js +0 -4
- package/dist/ui/operation/get-request-data.d.ts +0 -4
- package/dist/ui/operation/get-request-data.d.ts.map +0 -1
- package/dist/ui/operation/get-request-data.js +0 -70
- package/dist/utils/combine-schema.d.ts +0 -6
- package/dist/utils/combine-schema.d.ts.map +0 -1
- package/dist/utils/combine-schema.js +0 -51
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Ajv2020 } from 'ajv/dist/2020';
|
|
3
|
-
import { createContext,
|
|
3
|
+
import { createContext, use, useMemo, useState } from 'react';
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
5
|
import { getDefaultValue } from '../playground/get-default-values.js';
|
|
6
|
+
import { mergeAllOf } from '../utils/merge-schema.js';
|
|
6
7
|
const SchemaContext = createContext(undefined);
|
|
7
8
|
export const anyFields = {
|
|
8
9
|
type: ['string', 'number', 'boolean', 'array', 'object'],
|
|
9
10
|
items: true,
|
|
10
11
|
additionalProperties: true,
|
|
11
12
|
};
|
|
12
|
-
export function SchemaProvider({ references, fieldInfoMap, children, }) {
|
|
13
|
+
export function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children, }) {
|
|
13
14
|
const ajv = useMemo(() => new Ajv2020({
|
|
14
15
|
strict: false,
|
|
15
16
|
validateSchema: false,
|
|
16
17
|
validateFormats: false,
|
|
17
18
|
schemas: references,
|
|
18
19
|
}), [references]);
|
|
19
|
-
return (_jsx(SchemaContext.Provider, { value: useMemo(() => ({ references, fieldInfoMap, ajv }), [fieldInfoMap,
|
|
20
|
+
return (_jsx(SchemaContext.Provider, { value: useMemo(() => ({ references, fieldInfoMap, ajv, readOnly, writeOnly }), [references, fieldInfoMap, ajv, readOnly, writeOnly]), children: children }));
|
|
21
|
+
}
|
|
22
|
+
export function useSchemaScope() {
|
|
23
|
+
return use(SchemaContext);
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* A hook to store dynamic info of a field, such as selected schema of `oneOf`.
|
|
@@ -26,38 +30,43 @@ export function SchemaProvider({ references, fieldInfoMap, children, }) {
|
|
|
26
30
|
* @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
|
|
27
31
|
*/
|
|
28
32
|
export function useFieldInfo(fieldName, schema, depth) {
|
|
29
|
-
const { fieldInfoMap, ajv } =
|
|
33
|
+
const { fieldInfoMap, ajv } = use(SchemaContext);
|
|
30
34
|
const form = useFormContext();
|
|
31
35
|
const keyName = `${fieldName}:${depth}`;
|
|
32
|
-
const value = form.getValues(fieldName);
|
|
33
36
|
const [info, setInfo] = useState(() => {
|
|
37
|
+
const value = form.getValues(fieldName);
|
|
34
38
|
const initialInfo = fieldInfoMap.get(keyName);
|
|
35
39
|
if (initialInfo)
|
|
36
40
|
return initialInfo;
|
|
41
|
+
const out = {
|
|
42
|
+
oneOf: -1,
|
|
43
|
+
};
|
|
37
44
|
const union = getUnion(schema);
|
|
38
45
|
if (union) {
|
|
39
46
|
const [members, field] = union;
|
|
40
|
-
|
|
41
|
-
if (oneOf === -1)
|
|
42
|
-
oneOf = 0;
|
|
43
|
-
|
|
44
|
-
oneOf,
|
|
45
|
-
unionField: field,
|
|
46
|
-
};
|
|
47
|
+
out.oneOf = members.findIndex((item) => ajv.validate(item, value));
|
|
48
|
+
if (out.oneOf === -1)
|
|
49
|
+
out.oneOf = 0;
|
|
50
|
+
out.unionField = field;
|
|
47
51
|
}
|
|
48
52
|
if (Array.isArray(schema.type)) {
|
|
49
53
|
const types = schema.type;
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
out.selectedType =
|
|
55
|
+
types.find((type) => {
|
|
52
56
|
schema.type = type;
|
|
53
57
|
const match = ajv.validate(schema, value);
|
|
54
58
|
schema.type = types;
|
|
55
59
|
return match;
|
|
56
|
-
}) ?? types.at(0)
|
|
57
|
-
oneOf: -1,
|
|
58
|
-
};
|
|
60
|
+
}) ?? types.at(0);
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
if (schema.allOf) {
|
|
63
|
+
const merged = mergeAllOf(schema);
|
|
64
|
+
if (typeof merged !== 'boolean')
|
|
65
|
+
out.intersection = {
|
|
66
|
+
merged,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
61
70
|
});
|
|
62
71
|
fieldInfoMap.set(keyName, info);
|
|
63
72
|
return {
|
|
@@ -86,7 +95,7 @@ export function useFieldInfo(fieldName, schema, depth) {
|
|
|
86
95
|
* Resolve `$ref` in the schema, **not recursive**.
|
|
87
96
|
*/
|
|
88
97
|
export function useResolvedSchema(schema) {
|
|
89
|
-
const { references } =
|
|
98
|
+
const { references } = use(SchemaContext);
|
|
90
99
|
return useMemo(() => {
|
|
91
100
|
if (typeof schema === 'boolean')
|
|
92
101
|
return anyFields;
|
|
@@ -98,24 +107,10 @@ export function useResolvedSchema(schema) {
|
|
|
98
107
|
export function fallbackAny(schema) {
|
|
99
108
|
return typeof schema === 'boolean' ? anyFields : schema;
|
|
100
109
|
}
|
|
101
|
-
/**
|
|
102
|
-
* We automatically merge `allOf` | `anyOf` if all members are objects, but it's also possible for them to behave same as a union (`oneOf`).
|
|
103
|
-
*/
|
|
104
|
-
function isUnion(anyOrAllOf) {
|
|
105
|
-
return anyOrAllOf.every((item) => {
|
|
106
|
-
if (typeof item === 'boolean')
|
|
107
|
-
return true;
|
|
108
|
-
const u = item.anyOf || item.allOf;
|
|
109
|
-
return item.type !== 'object' && (!u || isUnion(u));
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
110
|
function getUnion(schema) {
|
|
113
|
-
if (schema.anyOf
|
|
111
|
+
if (schema.anyOf) {
|
|
114
112
|
return [schema.anyOf, 'anyOf'];
|
|
115
113
|
}
|
|
116
|
-
if (schema.allOf && isUnion(schema.allOf)) {
|
|
117
|
-
return [schema.allOf, 'allOf'];
|
|
118
|
-
}
|
|
119
114
|
if (schema.oneOf)
|
|
120
115
|
return [schema.oneOf, 'oneOf'];
|
|
121
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requests/generators/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requests/generators/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,eAAO,MAAM,cAAc,EAAE,kBAAkB,EAqC9C,CAAC"}
|
package/dist/server/create.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createProxy } from '../server/proxy.js';
|
|
2
2
|
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
|
|
3
3
|
import { type ProcessedDocument } from '../utils/process-document.js';
|
|
4
|
-
import type { CodeUsageGenerator } from '../ui/operation/
|
|
4
|
+
import type { CodeUsageGenerator } from '../ui/operation/usage-tabs/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* schema id -> file path, URL, or downloaded schema object
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE;;GAEG;AACH,KAAK,SAAS,GAAG,MAAM,CACrB,MAAM,EACN,MAAM,GAAG,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CACnD,CAAC;AACF,KAAK,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAE1D,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,UAAU,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CAiCzE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GACtC,kBAAkB,CAQpB"}
|
|
@@ -7,11 +7,13 @@ declare module 'fumadocs-core/source' {
|
|
|
7
7
|
/**
|
|
8
8
|
* Added by Fumadocs OpenAPI
|
|
9
9
|
*/
|
|
10
|
-
_openapi?:
|
|
11
|
-
method?: string;
|
|
12
|
-
};
|
|
10
|
+
_openapi?: InternalOpenAPIMeta;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
13
|
+
export interface InternalOpenAPIMeta {
|
|
14
|
+
method?: string;
|
|
15
|
+
webhook?: boolean;
|
|
16
|
+
}
|
|
15
17
|
/**
|
|
16
18
|
* Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
|
|
17
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,MAAM,EAEP,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,QAAQ;QACvB;;WAEG;QACH,QAAQ,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,MAAM,EAEP,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,QAAQ;QACvB;;WAEG;QACH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;KAChC;CACF;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,YAAY,CAqC5C;AAED,UAAU,eAAgB,SAAQ,QAAQ;IACxC,eAAe,EAAE,MAAM,YAAY,CAAC;CACrC;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,aAAa,EACnB,OAAO,GAAE,oBAAoB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CACR,MAAM,CAAC;IACL,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC,CACH,CAoCA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,mBAAmB,CAExD"}
|
|
@@ -14,13 +14,14 @@ export function openapiPlugin() {
|
|
|
14
14
|
const file = this.storage.read(filePath);
|
|
15
15
|
if (!file || file.format !== 'page')
|
|
16
16
|
return node;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const openApiData = file.data._openapi;
|
|
18
|
+
if (!openApiData || typeof openApiData !== 'object')
|
|
19
|
+
return node;
|
|
20
|
+
if (openApiData.webhook) {
|
|
21
|
+
node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx("span", { className: "ms-auto border border-current px-1 rounded-lg text-xs text-nowrap font-mono", children: "Webhook" })] }));
|
|
21
22
|
}
|
|
22
|
-
if (method) {
|
|
23
|
-
node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx(MethodLabel, { className: "ms-auto text-xs text-nowrap", children: method })] }));
|
|
23
|
+
else if (openApiData.method) {
|
|
24
|
+
node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx(MethodLabel, { className: "ms-auto text-xs text-nowrap", children: openApiData.method })] }));
|
|
24
25
|
}
|
|
25
26
|
return node;
|
|
26
27
|
},
|
|
@@ -43,11 +44,16 @@ export async function openapiSource(from, options = {}) {
|
|
|
43
44
|
path: `${baseDir}/${entry.path}`,
|
|
44
45
|
data: {
|
|
45
46
|
...entry.info,
|
|
46
|
-
getAPIPageProps
|
|
47
|
+
getAPIPageProps() {
|
|
48
|
+
const props = toBody(entry);
|
|
49
|
+
props.showDescription ?? (props.showDescription = true);
|
|
50
|
+
return props;
|
|
51
|
+
},
|
|
47
52
|
_openapi: {
|
|
48
53
|
method: entry.type === 'operation' || entry.type === 'webhook'
|
|
49
54
|
? entry.item.method
|
|
50
55
|
: undefined,
|
|
56
|
+
webhook: entry.type === 'webhook',
|
|
51
57
|
},
|
|
52
58
|
},
|
|
53
59
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { ProcessedDocument } from './utils/process-document.js';
|
|
|
5
5
|
import type { MediaAdapter } from './requests/media/adapter.js';
|
|
6
6
|
import type { OpenAPIOptions } from './server/index.js';
|
|
7
7
|
import type { CreateAPIPageOptions } from './ui/api-page.js';
|
|
8
|
-
import type { CodeUsageGenerator } from './ui/operation/
|
|
9
|
-
import type { ReactNode } from 'react';
|
|
8
|
+
import type { CodeUsageGenerator } from './ui/operation/usage-tabs/index.js';
|
|
9
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
10
10
|
export type Document = V3_1.Document;
|
|
11
11
|
export type OperationObject = V3_1.OperationObject;
|
|
12
12
|
export type ParameterObject = V3_1.ParameterObject;
|
|
@@ -32,7 +32,7 @@ export interface RenderContext extends Pick<OpenAPIOptions, 'proxyUrl'>, CreateA
|
|
|
32
32
|
*/
|
|
33
33
|
schema: ProcessedDocument;
|
|
34
34
|
mediaAdapters: Record<string, MediaAdapter>;
|
|
35
|
-
renderHeading: (depth: number, text: string) => ReactNode;
|
|
35
|
+
renderHeading: (depth: number, text: string, props?: HTMLAttributes<HTMLHeadingElement>) => ReactNode;
|
|
36
36
|
renderMarkdown: (text: string) => ReactNode;
|
|
37
37
|
renderCodeBlock: (lang: string, code: string) => ReactNode;
|
|
38
38
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvD,MAAM,MAAM,QAAQ,GA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C,SAAS,CAAC;IACf,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;IAC5C,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;CAC5D"}
|
package/dist/ui/api-page.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MethodInformation, RenderContext } from '../types.js';
|
|
2
|
-
import { type NoReference
|
|
2
|
+
import { type NoReference } from '../utils/schema.js';
|
|
3
3
|
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
4
4
|
import type { ProcessedDocument } from '../utils/process-document.js';
|
|
5
5
|
import { MediaAdapter } from '../requests/media/adapter.js';
|
|
@@ -7,8 +7,10 @@ import type { FC, ReactNode } from 'react';
|
|
|
7
7
|
import { type HighlightOptionsCommon, type HighlightOptionsThemes } from 'fumadocs-core/highlight';
|
|
8
8
|
import type { OpenAPIServer } from '../server/index.js';
|
|
9
9
|
import type { APIPageClientOptions } from './client/index.js';
|
|
10
|
-
import type { CodeUsageGenerator
|
|
11
|
-
import type {
|
|
10
|
+
import type { CodeUsageGenerator } from './operation/usage-tabs/index.js';
|
|
11
|
+
import type { SchemaUIOptions } from './schema/index.js';
|
|
12
|
+
import type { ResponseTab } from './operation/response-tabs.js';
|
|
13
|
+
import type { ExampleRequestItem } from './operation/request-tabs.js';
|
|
12
14
|
type Awaitable<T> = T | Promise<T>;
|
|
13
15
|
export interface CreateAPIPageOptions {
|
|
14
16
|
/**
|
|
@@ -40,6 +42,10 @@ export interface CreateAPIPageOptions {
|
|
|
40
42
|
*/
|
|
41
43
|
content?: {
|
|
42
44
|
renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => Awaitable<ReactNode>;
|
|
45
|
+
renderRequestTabs: (items: ExampleRequestItem[], ctx: RenderContext & {
|
|
46
|
+
route: string;
|
|
47
|
+
operation: NoReference<MethodInformation>;
|
|
48
|
+
}) => Awaitable<ReactNode>;
|
|
43
49
|
renderAPIExampleLayout?: (slots: {
|
|
44
50
|
selector: ReactNode;
|
|
45
51
|
usageTabs: ReactNode;
|
|
@@ -64,6 +70,7 @@ export interface CreateAPIPageOptions {
|
|
|
64
70
|
}, ctx: RenderContext) => Awaitable<ReactNode>;
|
|
65
71
|
renderOperationLayout?: (slots: {
|
|
66
72
|
header: ReactNode;
|
|
73
|
+
description: ReactNode;
|
|
67
74
|
apiExample: ReactNode;
|
|
68
75
|
apiPlayground: ReactNode;
|
|
69
76
|
authSchemes: ReactNode;
|
|
@@ -71,12 +78,14 @@ export interface CreateAPIPageOptions {
|
|
|
71
78
|
body: ReactNode;
|
|
72
79
|
responses: ReactNode;
|
|
73
80
|
callbacks: ReactNode;
|
|
74
|
-
}, ctx: RenderContext, method: MethodInformation) => Awaitable<ReactNode>;
|
|
81
|
+
}, ctx: RenderContext, method: NoReference<MethodInformation>) => Awaitable<ReactNode>;
|
|
75
82
|
renderWebhookLayout?: (slots: {
|
|
76
83
|
header: ReactNode;
|
|
84
|
+
description: ReactNode;
|
|
77
85
|
authSchemes: ReactNode;
|
|
78
86
|
paremeters: ReactNode;
|
|
79
87
|
body: ReactNode;
|
|
88
|
+
requests: ReactNode;
|
|
80
89
|
responses: ReactNode;
|
|
81
90
|
callbacks: ReactNode;
|
|
82
91
|
}) => Awaitable<ReactNode>;
|
|
@@ -85,9 +94,7 @@ export interface CreateAPIPageOptions {
|
|
|
85
94
|
* Info UI for JSON schemas
|
|
86
95
|
*/
|
|
87
96
|
schemaUI?: {
|
|
88
|
-
render?: (options:
|
|
89
|
-
root: ResolvedSchema;
|
|
90
|
-
}, ctx: RenderContext) => Awaitable<ReactNode>;
|
|
97
|
+
render?: (options: SchemaUIOptions, ctx: RenderContext) => Awaitable<ReactNode>;
|
|
91
98
|
/**
|
|
92
99
|
* Show examples under the generated content of JSON schemas.
|
|
93
100
|
*
|
|
@@ -116,7 +123,8 @@ export interface CreateAPIPageOptions {
|
|
|
116
123
|
}
|
|
117
124
|
export interface ApiPageProps {
|
|
118
125
|
document: Promise<ProcessedDocument> | string | ProcessedDocument;
|
|
119
|
-
|
|
126
|
+
showTitle?: boolean;
|
|
127
|
+
showDescription?: boolean;
|
|
120
128
|
/**
|
|
121
129
|
* An array of operations
|
|
122
130
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/ui/api-page.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/ui/api-page.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAmB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAcjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE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slint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */
|
|
3
3
|
import Slugger from 'github-slugger';
|
|
4
4
|
import { Operation } from '../ui/operation/index.js';
|
|
5
|
-
import { createMethod
|
|
5
|
+
import { createMethod } from '../utils/schema.js';
|
|
6
6
|
import { defaultAdapters } from '../requests/media/adapter.js';
|
|
7
7
|
import { highlight, } from 'fumadocs-core/highlight';
|
|
8
8
|
import { ApiProviderLazy } from './contexts/api.lazy.js';
|
|
@@ -60,9 +60,9 @@ export function createAPIPage(server, options = {}) {
|
|
|
60
60
|
...options.mediaAdapters,
|
|
61
61
|
},
|
|
62
62
|
slugger,
|
|
63
|
-
renderHeading(depth, text) {
|
|
63
|
+
renderHeading(depth, text, props) {
|
|
64
64
|
const id = slugger.slug(text);
|
|
65
|
-
return (_jsx(Heading, { id: id, as: `h${depth}`, children: text }, id));
|
|
65
|
+
return (_jsx(Heading, { id: id, as: `h${depth}`, ...props, children: text }, id));
|
|
66
66
|
},
|
|
67
67
|
async renderMarkdown(text) {
|
|
68
68
|
processor ?? (processor = createMarkdownProcessor());
|
|
@@ -85,10 +85,10 @@ export function createAPIPage(server, options = {}) {
|
|
|
85
85
|
return _jsx(APIPage, { ...props, ctx: ctx });
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
async function APIPage({ hasHead = false, operations, webhooks, ctx, }) {
|
|
88
|
+
async function APIPage({ showTitle: hasHead = false, showDescription, operations, webhooks, ctx, }) {
|
|
89
89
|
const { dereferenced } = ctx.schema;
|
|
90
90
|
let { renderPageLayout } = ctx.content ?? {};
|
|
91
|
-
renderPageLayout ?? (renderPageLayout = (slots) => (_jsxs("div", { className: "flex flex-col gap-24 text-sm", children: [slots.operations?.map((op) => op.children), slots.webhooks?.map((op) => op.children)] })));
|
|
91
|
+
renderPageLayout ?? (renderPageLayout = (slots) => (_jsxs("div", { className: "flex flex-col gap-24 text-sm @container", children: [slots.operations?.map((op) => op.children), slots.webhooks?.map((op) => op.children)] })));
|
|
92
92
|
const content = await renderPageLayout({
|
|
93
93
|
operations: operations?.map((item) => {
|
|
94
94
|
const pathItem = dereferenced.paths?.[item.path];
|
|
@@ -100,7 +100,7 @@ async function APIPage({ hasHead = false, operations, webhooks, ctx, }) {
|
|
|
100
100
|
const method = createMethod(item.method, pathItem, operation);
|
|
101
101
|
return {
|
|
102
102
|
item,
|
|
103
|
-
children: (_jsx(Operation, { method: method, path: item.path, ctx: ctx,
|
|
103
|
+
children: (_jsx(Operation, { method: method, path: item.path, ctx: ctx, showTitle: hasHead, showDescription: showDescription }, `${item.path}:${item.method}`)),
|
|
104
104
|
};
|
|
105
105
|
}),
|
|
106
106
|
webhooks: webhooks?.map((item) => {
|
|
@@ -112,7 +112,7 @@ async function APIPage({ hasHead = false, operations, webhooks, ctx, }) {
|
|
|
112
112
|
throw new Error(`[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`);
|
|
113
113
|
return {
|
|
114
114
|
item,
|
|
115
|
-
children: (_jsx(Operation, { type: "webhook", method: createMethod(item.method, webhook, hook), ctx: ctx, path: `/${item.name}`,
|
|
115
|
+
children: (_jsx(Operation, { type: "webhook", method: createMethod(item.method, webhook, hook), ctx: ctx, path: `/${item.name}`, showTitle: hasHead, showDescription: showDescription }, `${item.name}:${item.method}`)),
|
|
116
116
|
};
|
|
117
117
|
}),
|
|
118
118
|
}, ctx);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PlaygroundClientOptions } from '../../playground/client.js';
|
|
2
2
|
import type { MediaAdapter } from '../../requests/media/adapter.js';
|
|
3
|
-
import type { APIExampleItem } from '../operation/example-panel/index.js';
|
|
4
3
|
import type { FC } from 'react';
|
|
4
|
+
import type { ExampleRequestItem } from '../operation/request-tabs.js';
|
|
5
5
|
export interface APIPageClientOptions {
|
|
6
6
|
playground?: PlaygroundClientOptions;
|
|
7
7
|
operation?: OperationClientOptions;
|
|
@@ -20,7 +20,7 @@ export interface APIPageClientOptions {
|
|
|
20
20
|
}
|
|
21
21
|
export interface OperationClientOptions {
|
|
22
22
|
APIExampleSelector?: FC<{
|
|
23
|
-
items:
|
|
23
|
+
items: ExampleRequestItem[];
|
|
24
24
|
value: string | undefined;
|
|
25
25
|
onValueChange: (id: string) => void;
|
|
26
26
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/client/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/client/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,SAAS,CAAC,EAAE,sBAAsB,CAAC;IAEnC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,sBAAsB;IACrC,kBAAkB,CAAC,EAAE,EAAE,CAAC;QACtB,KAAK,EAAE,kBAAkB,EAAE,CAAC;QAE5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;KACrC,CAAC,CAAC;CACJ;AAED,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,oBAAyB,GACjC,oBAAoB,CAEtB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
3
|
-
export declare function Operation({ type, path, method, ctx,
|
|
3
|
+
export declare function Operation({ type, path, method, ctx, showTitle, showDescription, headingLevel, }: {
|
|
4
4
|
type?: 'webhook' | 'operation';
|
|
5
5
|
path: string;
|
|
6
6
|
method: MethodInformation;
|
|
7
7
|
ctx: RenderContext;
|
|
8
|
-
|
|
8
|
+
showTitle?: boolean;
|
|
9
|
+
showDescription?: boolean;
|
|
9
10
|
headingLevel?: number;
|
|
10
|
-
}): Promise<string | number | bigint | boolean |
|
|
11
|
+
}): Promise<string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | null | undefined>;
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAEV,iBAAiB,EACjB,aAAa,EAEd,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACtE,OAAO,KAAK,EAEV,iBAAiB,EACjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAsCjB,wBAAsB,SAAS,CAAC,EAC9B,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,SAAS,EACT,eAAe,EACf,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,kIA8RA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
3
|
import { createMethod, methodKeys, } from '../../utils/schema.js';
|
|
4
4
|
import { idToTitle } from '../../utils/id-to-title.js';
|
|
5
5
|
import { Schema } from '../schema/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { UsageTabs } from '../../ui/operation/usage-tabs/index.js';
|
|
7
7
|
import { MethodLabel } from '../../ui/components/method-label.js';
|
|
8
8
|
import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
|
|
9
9
|
import { CopyResponseTypeScript, SelectTab, SelectTabs, SelectTabTrigger, } from './client.js';
|
|
@@ -11,35 +11,45 @@ import { AccordionContent, AccordionHeader, AccordionItem, Accordions, Accordion
|
|
|
11
11
|
import { isMediaTypeSupported } from '../../requests/media/adapter.js';
|
|
12
12
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
13
13
|
import { APIPlayground } from '../../playground/index.js';
|
|
14
|
-
import {
|
|
14
|
+
import { RequestTabs, getExampleRequests } from './request-tabs.js';
|
|
15
|
+
import { UsageTabsProviderLazy } from './usage-tabs/lazy.js';
|
|
15
16
|
const ParamTypes = {
|
|
16
17
|
path: 'Path Parameters',
|
|
17
18
|
query: 'Query Parameters',
|
|
18
19
|
header: 'Header Parameters',
|
|
19
20
|
cookie: 'Cookie Parameters',
|
|
20
21
|
};
|
|
21
|
-
export async function Operation({ type = 'operation', path, method, ctx,
|
|
22
|
+
export async function Operation({ type = 'operation', path, method, ctx, showTitle, showDescription, headingLevel = 2, }) {
|
|
22
23
|
const { schema: { dereferenced }, } = ctx;
|
|
23
24
|
const body = method.requestBody;
|
|
24
25
|
let headNode = null;
|
|
26
|
+
const descriptionNode = showDescription &&
|
|
27
|
+
method.description &&
|
|
28
|
+
ctx.renderMarkdown(method.description);
|
|
25
29
|
let bodyNode = null;
|
|
26
30
|
let authNode = null;
|
|
27
31
|
let responseNode = null;
|
|
28
32
|
let callbacksNode = null;
|
|
29
|
-
if (
|
|
33
|
+
if (showTitle) {
|
|
30
34
|
const title = method.summary ??
|
|
31
35
|
(method.operationId ? idToTitle(method.operationId) : path);
|
|
32
|
-
headNode =
|
|
36
|
+
headNode = ctx.renderHeading(headingLevel, title);
|
|
33
37
|
headingLevel++;
|
|
34
38
|
}
|
|
35
39
|
const contentTypes = body ? Object.entries(body.content) : null;
|
|
36
40
|
if (body && contentTypes && contentTypes.length > 0) {
|
|
37
41
|
const [defaultValue] = contentTypes[0];
|
|
38
|
-
bodyNode = (_jsxs(SelectTabs, { defaultValue: defaultValue, children: [_jsxs("div", { className: "flex gap-2 items-end justify-between", children: [ctx.renderHeading(headingLevel, 'Request Body'
|
|
42
|
+
bodyNode = (_jsxs(SelectTabs, { defaultValue: defaultValue, children: [_jsxs("div", { className: "flex gap-2 items-end justify-between", children: [ctx.renderHeading(headingLevel, 'Request Body', {
|
|
43
|
+
className: 'my-0!',
|
|
44
|
+
}), contentTypes.length > 1 ? (_jsx(SelectTabTrigger, { items: contentTypes.map(([key]) => key) })) : (_jsx("p", { className: "text-sm text-fd-muted-foreground font-medium not-prose", children: defaultValue }))] }), body.description && ctx.renderMarkdown(body.description), contentTypes.map(([type, content]) => {
|
|
39
45
|
if (!isMediaTypeSupported(type, ctx.mediaAdapters)) {
|
|
40
46
|
throw new Error(`Media type ${type} is not supported (in ${path})`);
|
|
41
47
|
}
|
|
42
|
-
return (_jsx(SelectTab, { value: type, children: _jsx(Schema, {
|
|
48
|
+
return (_jsx(SelectTab, { value: type, children: _jsx(Schema, { client: {
|
|
49
|
+
name: 'body',
|
|
50
|
+
as: 'body',
|
|
51
|
+
required: body.required,
|
|
52
|
+
}, root: (content.schema ?? {}), readOnly: method.method === 'GET', writeOnly: method.method !== 'GET', ctx: ctx }) }, type));
|
|
43
53
|
})] }));
|
|
44
54
|
}
|
|
45
55
|
if (method.responses && ctx.showResponseSchema !== false) {
|
|
@@ -50,18 +60,21 @@ export async function Operation({ type = 'operation', path, method, ctx, hasHead
|
|
|
50
60
|
const params = method.parameters?.filter((param) => param.in === type);
|
|
51
61
|
if (!params || params.length === 0)
|
|
52
62
|
return;
|
|
53
|
-
return (_jsxs(Fragment, { children: [ctx.renderHeading(headingLevel, title), _jsx("div", { className: "flex flex-col", children: params.map((param) => (_jsx(Schema, {
|
|
63
|
+
return (_jsxs(Fragment, { children: [ctx.renderHeading(headingLevel, title), _jsx("div", { className: "flex flex-col", children: params.map((param) => (_jsx(Schema, { client: {
|
|
64
|
+
name: param.name,
|
|
65
|
+
required: param.required,
|
|
66
|
+
}, root: {
|
|
54
67
|
...param.schema,
|
|
55
68
|
description: param.description ?? param.schema?.description,
|
|
56
69
|
deprecated: (param.deprecated ?? false) ||
|
|
57
70
|
(param.schema?.deprecated ?? false),
|
|
58
|
-
},
|
|
71
|
+
}, readOnly: method.method === 'GET', writeOnly: method.method !== 'GET', ctx: ctx }, param.name))) })] }, type));
|
|
59
72
|
});
|
|
60
73
|
const securities = (method.security ?? dereferenced.security ?? []).filter((v) => Object.keys(v).length > 0);
|
|
61
74
|
if (type === 'operation' && securities.length > 0) {
|
|
62
75
|
const securitySchemes = dereferenced.components?.securitySchemes;
|
|
63
76
|
const names = securities.map((security) => Object.keys(security).join(' & '));
|
|
64
|
-
authNode = (_jsxs(SelectTabs, { defaultValue: names[0], children: [_jsxs("div", { className: "flex items-end justify-between gap-2", children: [ctx.renderHeading(headingLevel, 'Authorization'), _jsx(SelectTabTrigger, { items: names, className: "mb-4" })] }), securities.map((security, i) => (_jsx(SelectTab, { value: names[i], children: Object.entries(security).map(([key, scopes]) => {
|
|
77
|
+
authNode = (_jsxs(SelectTabs, { defaultValue: names[0], children: [_jsxs("div", { className: "flex items-end justify-between gap-2", children: [ctx.renderHeading(headingLevel, 'Authorization'), names.length > 1 ? (_jsx(SelectTabTrigger, { items: names, className: "mb-4" })) : (_jsx("p", { className: "text-sm text-fd-muted-foreground font-medium not-prose mb-7", children: names[0] }))] }), securities.map((security, i) => (_jsx(SelectTab, { value: names[i], children: Object.entries(security).map(([key, scopes]) => {
|
|
65
78
|
const scheme = securitySchemes?.[key];
|
|
66
79
|
if (!scheme)
|
|
67
80
|
return;
|
|
@@ -71,37 +84,38 @@ export async function Operation({ type = 'operation', path, method, ctx, hasHead
|
|
|
71
84
|
const callbacks = method.callbacks ? Object.entries(method.callbacks) : null;
|
|
72
85
|
if (callbacks && callbacks.length > 0) {
|
|
73
86
|
const [defaultValue] = callbacks[0];
|
|
74
|
-
callbacksNode = (_jsxs(SelectTabs, { defaultValue: defaultValue, children: [_jsxs("div", { className: "flex justify-between gap-2 items-end", children: [ctx.renderHeading(headingLevel, 'Callbacks'), _jsx(SelectTabTrigger, { items: callbacks.map(([key]) => key), className: "mb-4" })] }), callbacks.map(([name, callback]) => (_jsx(SelectTab, { value: name, children: _jsx(WebhookCallback, { callback: callback, ctx: ctx, headingLevel: headingLevel }) }, name)))] }));
|
|
87
|
+
callbacksNode = (_jsxs(SelectTabs, { defaultValue: defaultValue, children: [_jsxs("div", { className: "flex justify-between gap-2 items-end", children: [ctx.renderHeading(headingLevel, 'Callbacks'), callbacks.length > 1 ? (_jsx(SelectTabTrigger, { items: callbacks.map(([key]) => key), className: "mb-4" })) : (_jsx("p", { className: "text-sm text-fd-muted-foreground font-medium not-prose mb-7", children: defaultValue }))] }), callbacks.map(([name, callback]) => (_jsx(SelectTab, { value: name, children: _jsx(WebhookCallback, { callback: callback, ctx: ctx, headingLevel: headingLevel }) }, name)))] }));
|
|
75
88
|
}
|
|
76
89
|
let { renderOperationLayout, renderWebhookLayout } = ctx.content ?? {};
|
|
77
90
|
if (type === 'operation') {
|
|
78
91
|
renderOperationLayout ?? (renderOperationLayout = (slots) => {
|
|
79
|
-
return (_jsxs("div", { className: "flex flex-col gap-x-6 gap-y-4
|
|
80
|
-
'--fd-api-info-top': 'calc(12px + var(--fd-nav-height) + var(--fd-banner-height) + var(--fd-tocnav-height, 0px))',
|
|
81
|
-
}, children: [_jsxs("div", { className: "min-w-0 flex-1", children: [slots.header, slots.apiPlayground, slots.authSchemes, slots.paremeters, slots.body, slots.responses, slots.callbacks] }), slots.apiExample] }));
|
|
92
|
+
return (_jsxs("div", { className: "flex flex-col gap-x-6 gap-y-4 @4xl:flex-row @4xl:items-start", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [slots.header, slots.apiPlayground, slots.description, slots.authSchemes, slots.paremeters, slots.body, slots.responses, slots.callbacks] }), _jsx("div", { className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-1,2rem)+1rem)] @4xl:w-[400px]", children: slots.apiExample })] }));
|
|
82
93
|
});
|
|
83
94
|
const playgroundEnabled = ctx.playground?.enabled ?? true;
|
|
84
95
|
const content = await renderOperationLayout({
|
|
85
96
|
header: headNode,
|
|
97
|
+
description: descriptionNode,
|
|
86
98
|
authSchemes: authNode,
|
|
87
99
|
body: bodyNode,
|
|
88
100
|
callbacks: callbacksNode,
|
|
89
101
|
paremeters: parameterNode,
|
|
90
102
|
responses: responseNode,
|
|
91
103
|
apiPlayground: playgroundEnabled ? (_jsx(APIPlayground, { path: path, method: method, ctx: ctx })) : (_jsxs("div", { className: "flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose", children: [_jsx(MethodLabel, { className: "text-xs", children: method.method }), _jsx("code", { className: "flex-1 overflow-auto text-nowrap text-[0.8125rem] text-fd-muted-foreground", children: path })] })),
|
|
92
|
-
apiExample: _jsx(
|
|
104
|
+
apiExample: _jsx(UsageTabs, { method: method, ctx: ctx }),
|
|
93
105
|
}, ctx, method);
|
|
94
|
-
return (_jsx(
|
|
106
|
+
return (_jsx(UsageTabsProviderLazy, { defaultExampleId: method['x-exclusiveCodeSample'] ?? method['x-selectedCodeSample'], route: path, examples: getExampleRequests(path, method, ctx), children: content }));
|
|
95
107
|
}
|
|
96
108
|
else {
|
|
97
|
-
renderWebhookLayout ?? (renderWebhookLayout = (slots) => (_jsxs("div", { children: [slots.header, slots.authSchemes, slots.paremeters, slots.body, slots.responses, slots.callbacks] })));
|
|
109
|
+
renderWebhookLayout ?? (renderWebhookLayout = (slots) => (_jsxs("div", { className: "flex flex-col-reverse gap-x-6 gap-y-4 @4xl:flex-row @4xl:items-start", children: [_jsxs("div", { className: "min-w-0 flex-1", children: [slots.header, slots.description, slots.authSchemes, slots.paremeters, slots.body, slots.responses, slots.callbacks] }), _jsx("div", { className: "@4xl:sticky @4xl:top-[calc(var(--fd-docs-row-1,2rem)+1rem)] @4xl:w-[400px]", children: slots.requests })] })));
|
|
98
110
|
return renderWebhookLayout({
|
|
99
111
|
header: headNode,
|
|
112
|
+
description: descriptionNode,
|
|
100
113
|
authSchemes: authNode,
|
|
101
114
|
body: bodyNode,
|
|
102
115
|
callbacks: callbacksNode,
|
|
103
116
|
paremeters: parameterNode,
|
|
104
117
|
responses: responseNode,
|
|
118
|
+
requests: _jsx(RequestTabs, { path: path, operation: method, ctx: ctx }),
|
|
105
119
|
});
|
|
106
120
|
}
|
|
107
121
|
}
|
|
@@ -117,7 +131,7 @@ async function ResponseAccordion({ status, operation, ctx, }) {
|
|
|
117
131
|
contentTypes.length === 1 ? (_jsx("p", { className: "text-sm text-fd-muted-foreground", children: defaultValue })) : (_jsx(SelectTabTrigger, { items: contentTypes.map(([key]) => key) }));
|
|
118
132
|
wrapper = (children) => (_jsx(SelectTabs, { defaultValue: defaultValue, children: children }));
|
|
119
133
|
}
|
|
120
|
-
return wrapper(_jsxs(AccordionItem, { value: status, children: [_jsxs(AccordionHeader, { children: [_jsx(AccordionTrigger, { className: "font-mono", children: status }), selectorNode] }), _jsxs(AccordionContent, { className: "ps-4.5", children: [response.description && (_jsx("div", { className: "prose-no-margin", children: ctx.renderMarkdown(response.description) })), contentTypes.map(async ([type, resType]) => {
|
|
134
|
+
return wrapper(_jsxs(AccordionItem, { value: status, children: [_jsxs(AccordionHeader, { children: [_jsx(AccordionTrigger, { className: "font-mono", children: status }), selectorNode] }), _jsxs(AccordionContent, { className: "ps-4.5", children: [response.description && (_jsx("div", { className: "prose-no-margin mb-2", children: ctx.renderMarkdown(response.description) })), contentTypes.map(async ([type, resType]) => {
|
|
121
135
|
const schema = resType.schema;
|
|
122
136
|
let ts;
|
|
123
137
|
if (generateTypeScriptSchema) {
|
|
@@ -126,7 +140,10 @@ async function ResponseAccordion({ status, operation, ctx, }) {
|
|
|
126
140
|
else if (generateTypeScriptSchema === undefined && schema) {
|
|
127
141
|
ts = await getTypescriptSchema(schema, ctx);
|
|
128
142
|
}
|
|
129
|
-
return (_jsxs(SelectTab, { value: type, className: "
|
|
143
|
+
return (_jsxs(SelectTab, { value: type, className: "mb-2", children: [ts && _jsx(CopyResponseTypeScript, { code: ts }), schema && (_jsx("div", { className: "border px-3 py-2 rounded-lg", children: _jsx(Schema, { client: {
|
|
144
|
+
name: 'response',
|
|
145
|
+
as: 'body',
|
|
146
|
+
}, root: schema, readOnly: true, ctx: ctx }) }))] }, type));
|
|
130
147
|
})] })] }));
|
|
131
148
|
}
|
|
132
149
|
function WebhookCallback({ callback, ctx, headingLevel, }) {
|