fumadocs-openapi 10.0.10 → 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 +45 -24
- 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 +6 -6
- 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
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { wrapLazy } from '../../../utils/lazy.js';
|
|
3
|
+
export const UsageTabsSelectorLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.UsageTabsSelector })));
|
|
4
|
+
export const UsageTabLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.UsageTab })));
|
|
5
|
+
export const UsageTabsProviderLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.UsageTabsProvider })));
|
|
@@ -3,9 +3,7 @@ export interface SchemaUIProps {
|
|
|
3
3
|
name: string;
|
|
4
4
|
required?: boolean;
|
|
5
5
|
as?: 'property' | 'body';
|
|
6
|
-
readOnly?: boolean;
|
|
7
|
-
writeOnly?: boolean;
|
|
8
6
|
generated: SchemaUIGeneratedData;
|
|
9
7
|
}
|
|
10
|
-
export declare function SchemaUI({ name, required, as, generated,
|
|
8
|
+
export declare function SchemaUI({ name, required, as, generated, }: SchemaUIProps): import("react/jsx-runtime").JSX.Element;
|
|
11
9
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/ui/schema/client.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAc,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/ui/schema/client.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAc,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAuDrE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAEzB,SAAS,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,QAAgB,EAChB,EAAe,EACf,SAAS,GACV,EAAE,aAAa,2CAoBf"}
|
package/dist/ui/schema/client.js
CHANGED
|
@@ -26,23 +26,17 @@ function useData() {
|
|
|
26
26
|
function useProperty() {
|
|
27
27
|
return use(PropertyContext);
|
|
28
28
|
}
|
|
29
|
-
export function SchemaUI({ name, required = false, as = 'property', generated,
|
|
29
|
+
export function SchemaUI({ name, required = false, as = 'property', generated, }) {
|
|
30
30
|
const schema = generated.refs[generated.$root];
|
|
31
|
-
const context = useMemo(() =>
|
|
32
|
-
...generated,
|
|
33
|
-
readOnly,
|
|
34
|
-
writeOnly,
|
|
35
|
-
}), [generated, readOnly, writeOnly]);
|
|
31
|
+
const context = useMemo(() => generated, [generated]);
|
|
36
32
|
const isProperty = as === 'property' || !isExpandable(schema);
|
|
37
33
|
return (_jsx(DataContext, { value: context, children: isProperty ? (_jsx(SchemaUIProperty, { name: name, "$type": generated.$root, overrides: {
|
|
38
34
|
required,
|
|
39
35
|
} })) : (_jsx(SchemaUIContent, { "$type": generated.$root })) }));
|
|
40
36
|
}
|
|
41
37
|
function SchemaUIContent({ $type }) {
|
|
42
|
-
const { refs
|
|
38
|
+
const { refs } = useData();
|
|
43
39
|
const schema = refs[$type];
|
|
44
|
-
if ((schema.readOnly && !readOnly) || (schema.writeOnly && !writeOnly))
|
|
45
|
-
return;
|
|
46
40
|
let child = null;
|
|
47
41
|
if (schema.type === 'or' && schema.items.length > 0) {
|
|
48
42
|
child = (_jsxs(_Fragment, { children: [child, _jsxs(Tabs, { defaultValue: schema.items[0].$type, children: [_jsx(TabsList, { children: schema.items.map((item) => (_jsx(TabsTrigger, { value: item.$type, children: item.name }, item.$type))) }), schema.items.map((item) => (_jsx(TabsContent, { value: item.$type, forceMount: undefined, className: "py-0", children: _jsx(SchemaUIContent, { ...item }) }, item.$type)))] })] }));
|
|
@@ -51,16 +45,14 @@ function SchemaUIContent({ $type }) {
|
|
|
51
45
|
child = (_jsxs(_Fragment, { children: [child, schema.props.map((prop) => (_jsx(SchemaUIProperty, { name: prop.name, "$type": prop.$type, overrides: { required: prop.required } }, prop.name)))] }));
|
|
52
46
|
}
|
|
53
47
|
if (schema.type === 'array') {
|
|
54
|
-
child = (_jsxs(_Fragment, { children: [child,
|
|
48
|
+
child = (_jsxs(_Fragment, { children: [child, _jsxs(Collapsible, { className: "my-2", children: [_jsxs(CollapsibleTrigger, { className: cn(buttonVariants({ color: 'secondary', size: 'sm' }), 'group px-3 py-2 data-[state=open]:rounded-b-none'), children: ["Array Item", _jsx(ChevronDown, { className: "size-4 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { className: "-mt-px bg-fd-card px-3 rounded-lg rounded-tl-none border shadow-sm", children: _jsx(SchemaUIContent, { "$type": schema.item.$type }) })] })] }));
|
|
55
49
|
}
|
|
56
50
|
return child;
|
|
57
51
|
}
|
|
58
52
|
function SchemaUIProperty({ name, $type, overrides, }) {
|
|
59
53
|
const { renderRef } = useProperty();
|
|
60
|
-
const { refs
|
|
54
|
+
const { refs } = useData();
|
|
61
55
|
const schema = refs[$type];
|
|
62
|
-
if ((schema.readOnly && !readOnly) || (schema.writeOnly && !writeOnly))
|
|
63
|
-
return;
|
|
64
56
|
let type = schema.typeName;
|
|
65
57
|
if (schema.type === 'or' && schema.items.length > 0) {
|
|
66
58
|
type = (_jsx("span", { className: cn(typeVariants(), 'flex flex-row gap-2 items-center'), children: schema.items.map((item, i) => (_jsxs(Fragment, { children: [i > 0 && _jsx("span", { children: "|" }), renderRef({
|
|
@@ -69,6 +61,13 @@ function SchemaUIProperty({ name, $type, overrides, }) {
|
|
|
69
61
|
$ref: item.$type,
|
|
70
62
|
})] }, item.$type))) }));
|
|
71
63
|
}
|
|
64
|
+
if (schema.type === 'and' && schema.items.length > 0) {
|
|
65
|
+
type = (_jsx("span", { className: cn(typeVariants(), 'flex flex-row gap-2 items-center'), children: schema.items.map((item, i) => (_jsxs(Fragment, { children: [i > 0 && _jsx("span", { children: "&" }), renderRef({
|
|
66
|
+
pathName: name,
|
|
67
|
+
text: item.name,
|
|
68
|
+
$ref: item.$type,
|
|
69
|
+
})] }, item.$type))) }));
|
|
70
|
+
}
|
|
72
71
|
if (schema.type === 'object' && schema.props.length > 0) {
|
|
73
72
|
type = renderRef({
|
|
74
73
|
text: schema.aliasName,
|
|
@@ -136,13 +135,10 @@ function LinkRef({ $ref, pathName, onInsert, text, }) {
|
|
|
136
135
|
onInsert(pathName, $ref);
|
|
137
136
|
}, children: text }));
|
|
138
137
|
}
|
|
139
|
-
function ObjectCollapsible(props) {
|
|
140
|
-
return (_jsxs(Collapsible, { className: "my-2", ...props, children: [_jsxs(CollapsibleTrigger, { className: cn(buttonVariants({ color: 'secondary', size: 'sm' }), 'group px-3 py-2 data-[state=open]:rounded-b-none'), children: [props.name, _jsx(ChevronDown, { className: "size-4 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { className: "-mt-px *:bg-fd-card", children: props.children })] }));
|
|
141
|
-
}
|
|
142
138
|
function Property({ name, type, required, deprecated, nested = false, ...props }) {
|
|
143
139
|
return (_jsxs("div", { className: cn('text-sm border-t', nested
|
|
144
140
|
? 'p-3 border-x bg-fd-card last:rounded-b-xl first:rounded-tr-xl last:border-b'
|
|
145
|
-
: 'py-4 first:border-t-0', props.className), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-3 not-prose", children: [_jsxs("span", { className: "font-medium font-mono text-fd-primary", children: [name, required
|
|
141
|
+
: 'py-4 first:border-t-0', props.className), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-3 not-prose", children: [_jsxs("span", { className: "font-medium font-mono text-fd-primary", children: [name, required ? (_jsx("span", { className: "text-red-400", children: "*" })) : (_jsx("span", { className: "text-fd-muted-foreground", children: "?" }))] }), typeof type === 'string' ? (_jsx("span", { className: "text-sm font-mono text-fd-muted-foreground", children: type })) : (type), deprecated && (_jsx(Badge, { color: "yellow", className: "ms-auto text-xs", children: "Deprecated" }))] }), _jsx("div", { className: "prose-no-margin pt-2.5 empty:hidden", children: props.children })] }));
|
|
146
142
|
}
|
|
147
143
|
function isExpandable(schema) {
|
|
148
144
|
return schema.type !== 'primitive';
|
|
@@ -8,8 +8,6 @@ export interface FieldBase {
|
|
|
8
8
|
typeName: string;
|
|
9
9
|
aliasName: string;
|
|
10
10
|
deprecated?: boolean;
|
|
11
|
-
writeOnly?: boolean;
|
|
12
|
-
readOnly?: boolean;
|
|
13
11
|
}
|
|
14
12
|
export type SchemaData = FieldBase & ({
|
|
15
13
|
type: 'primitive';
|
|
@@ -31,15 +29,31 @@ export type SchemaData = FieldBase & ({
|
|
|
31
29
|
name: string;
|
|
32
30
|
$type: string;
|
|
33
31
|
}[];
|
|
32
|
+
} | {
|
|
33
|
+
type: 'and';
|
|
34
|
+
items: {
|
|
35
|
+
name: string;
|
|
36
|
+
$type: string;
|
|
37
|
+
}[];
|
|
34
38
|
});
|
|
35
39
|
export interface SchemaUIOptions {
|
|
36
40
|
root: ResolvedSchema;
|
|
37
|
-
|
|
41
|
+
client: Omit<SchemaUIProps, 'generated'>;
|
|
42
|
+
/**
|
|
43
|
+
* include read only props
|
|
44
|
+
*/
|
|
45
|
+
readOnly?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* include write only props
|
|
48
|
+
*/
|
|
49
|
+
writeOnly?: boolean;
|
|
38
50
|
}
|
|
39
51
|
export interface SchemaUIGeneratedData {
|
|
40
52
|
$root: string;
|
|
41
53
|
refs: Record<string, SchemaData>;
|
|
42
54
|
}
|
|
43
|
-
export declare function Schema({ ctx,
|
|
44
|
-
|
|
55
|
+
export declare function Schema({ ctx, ...options }: SchemaUIOptions & {
|
|
56
|
+
ctx: RenderContext;
|
|
57
|
+
}): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<ReactNode> | null | undefined;
|
|
58
|
+
export declare function generateSchemaUI({ root, readOnly, writeOnly }: SchemaUIOptions, ctx: RenderContext): SchemaUIGeneratedData;
|
|
45
59
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/schema/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,WAAW,SAAS;IACxB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IAEvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/schema/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,KAAK,EAAE,aAA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H,GAAG,OAAO,EACX,EAAE,eAAe,GAAG;IACnB,GAAG,EAAE,aAAa,CAAC;CACpB,8IAWA;AAED,wBAAgB,gBAAgB,CAC9B,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,eAAe,EAC9C,GAAG,EAAE,aAAa,GACjB,qBAAqB,CAuSvB"}
|
package/dist/ui/schema/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { FormatFlags, schemaToString } from '../../utils/schema-to-string.js';
|
|
3
|
-
import {
|
|
3
|
+
import { mergeAllOf } from '../../utils/merge-schema.js';
|
|
4
4
|
import { SchemaUILazy } from '../../ui/schema/lazy.js';
|
|
5
|
-
export function Schema({ ctx,
|
|
5
|
+
export function Schema({ ctx, ...options }) {
|
|
6
6
|
if (ctx.schemaUI?.render) {
|
|
7
|
-
return ctx.schemaUI.render(
|
|
7
|
+
return ctx.schemaUI.render(options, ctx);
|
|
8
8
|
}
|
|
9
|
-
return (_jsx(SchemaUILazy, { ...
|
|
9
|
+
return (_jsx(SchemaUILazy, { ...options.client, generated: generateSchemaUI(options, ctx) }));
|
|
10
10
|
}
|
|
11
|
-
export function generateSchemaUI({
|
|
11
|
+
export function generateSchemaUI({ root, readOnly, writeOnly }, ctx) {
|
|
12
12
|
const refs = {};
|
|
13
13
|
const { showExample = false } = ctx.schemaUI ?? {};
|
|
14
14
|
function generateInfoTags(schema) {
|
|
@@ -65,6 +65,15 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
65
65
|
autoIds.set(schema, generated);
|
|
66
66
|
return generated;
|
|
67
67
|
}
|
|
68
|
+
function isVisible(schema) {
|
|
69
|
+
if (typeof schema === 'boolean')
|
|
70
|
+
return true;
|
|
71
|
+
if (schema.writeOnly)
|
|
72
|
+
return writeOnly ?? false;
|
|
73
|
+
if (schema.readOnly)
|
|
74
|
+
return readOnly ?? false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
68
77
|
function base(schema) {
|
|
69
78
|
if (typeof schema === 'boolean') {
|
|
70
79
|
const name = schema ? 'any' : 'never';
|
|
@@ -79,8 +88,6 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
79
88
|
typeName: schemaToString(schema, ctx.schema),
|
|
80
89
|
aliasName: schemaToString(schema, ctx.schema, FormatFlags.UseAlias),
|
|
81
90
|
deprecated: schema.deprecated,
|
|
82
|
-
readOnly: schema.readOnly,
|
|
83
|
-
writeOnly: schema.writeOnly,
|
|
84
91
|
};
|
|
85
92
|
}
|
|
86
93
|
function scanRefs(id, schema) {
|
|
@@ -101,12 +108,11 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
101
108
|
};
|
|
102
109
|
refs[id] = out;
|
|
103
110
|
for (const type of schema.type) {
|
|
104
|
-
const
|
|
111
|
+
const key = `${id}_type:${type}`;
|
|
112
|
+
scanRefs(key, {
|
|
105
113
|
...schema,
|
|
106
114
|
type,
|
|
107
|
-
};
|
|
108
|
-
const key = `${id}_type:${type}`;
|
|
109
|
-
scanRefs(key, item);
|
|
115
|
+
});
|
|
110
116
|
out.items.push({
|
|
111
117
|
name: type,
|
|
112
118
|
$type: key,
|
|
@@ -114,34 +120,64 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
114
120
|
}
|
|
115
121
|
return;
|
|
116
122
|
}
|
|
117
|
-
if (schema.oneOf) {
|
|
123
|
+
if (schema.oneOf && schema.anyOf) {
|
|
124
|
+
const out = {
|
|
125
|
+
type: 'and',
|
|
126
|
+
items: [],
|
|
127
|
+
...base(schema),
|
|
128
|
+
};
|
|
129
|
+
refs[id] = out;
|
|
130
|
+
const $oneOf = `${id}_oneOf`;
|
|
131
|
+
const $anyOf = `${id}_anyOf`;
|
|
132
|
+
scanRefs($oneOf, {
|
|
133
|
+
...schema,
|
|
134
|
+
anyOf: undefined,
|
|
135
|
+
});
|
|
136
|
+
scanRefs($anyOf, {
|
|
137
|
+
...schema,
|
|
138
|
+
oneOf: undefined,
|
|
139
|
+
});
|
|
140
|
+
out.items.push({
|
|
141
|
+
name: refs[$oneOf].aliasName,
|
|
142
|
+
$type: $oneOf,
|
|
143
|
+
}, {
|
|
144
|
+
name: refs[$anyOf].aliasName,
|
|
145
|
+
$type: $anyOf,
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// display both `oneOf` & `anyOf` as OR for simplified overview
|
|
150
|
+
const union = schema.oneOf ?? schema.anyOf;
|
|
151
|
+
if (union) {
|
|
118
152
|
const out = {
|
|
119
153
|
type: 'or',
|
|
120
154
|
items: [],
|
|
121
155
|
...base(schema),
|
|
122
156
|
};
|
|
123
157
|
refs[id] = out;
|
|
124
|
-
for (const item of
|
|
125
|
-
if (typeof item !== 'object')
|
|
158
|
+
for (const item of union) {
|
|
159
|
+
if (typeof item !== 'object' || !isVisible(item))
|
|
126
160
|
continue;
|
|
127
161
|
const key = `${id}_extends:${getSchemaId(item)}`;
|
|
128
|
-
|
|
162
|
+
scanRefs(key, {
|
|
129
163
|
...schema,
|
|
164
|
+
oneOf: undefined,
|
|
165
|
+
anyOf: undefined,
|
|
130
166
|
...item,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
167
|
+
properties: {
|
|
168
|
+
...schema.properties,
|
|
169
|
+
...item.properties,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
134
172
|
out.items.push({
|
|
135
173
|
$type: key,
|
|
136
|
-
name:
|
|
174
|
+
name: refs[key].aliasName,
|
|
137
175
|
});
|
|
138
176
|
}
|
|
139
177
|
return;
|
|
140
178
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const combined = combineSchema(of);
|
|
144
|
-
scanRefs(id, combined);
|
|
179
|
+
if (schema.allOf) {
|
|
180
|
+
scanRefs(id, mergeAllOf(schema));
|
|
145
181
|
return;
|
|
146
182
|
}
|
|
147
183
|
if (schema.type === 'object') {
|
|
@@ -151,10 +187,13 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
151
187
|
...base(schema),
|
|
152
188
|
};
|
|
153
189
|
refs[id] = out;
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
190
|
+
const { properties = {}, patternProperties, additionalProperties, } = schema;
|
|
191
|
+
const props = Object.entries(properties);
|
|
192
|
+
if (patternProperties)
|
|
193
|
+
props.push(...Object.entries(patternProperties));
|
|
157
194
|
for (const [key, prop] of props) {
|
|
195
|
+
if (!isVisible(prop))
|
|
196
|
+
continue;
|
|
158
197
|
const $type = getSchemaId(prop);
|
|
159
198
|
scanRefs($type, prop);
|
|
160
199
|
out.props.push({
|
|
@@ -163,9 +202,10 @@ export function generateSchemaUI({ ctx, root, }) {
|
|
|
163
202
|
required: schema.required?.includes(key) ?? false,
|
|
164
203
|
});
|
|
165
204
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
205
|
+
if (additionalProperties !== undefined &&
|
|
206
|
+
isVisible(additionalProperties)) {
|
|
207
|
+
const $type = getSchemaId(additionalProperties);
|
|
208
|
+
scanRefs($type, additionalProperties);
|
|
169
209
|
out.props.push({
|
|
170
210
|
$type,
|
|
171
211
|
name: '[key: string]',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-equal.d.ts","sourceRoot":"","sources":["../../src/utils/deep-equal.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAuCzD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function deepEqual(a, b) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (a == null || b == null) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (typeof a !== 'object' || typeof b !== 'object') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
12
|
+
if (a.length !== b.length) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const keysA = Object.keys(a);
|
|
21
|
+
const keysB = Object.keys(b);
|
|
22
|
+
if (keysA.length !== keysB.length) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) &&
|
|
26
|
+
deepEqual(a[key], b[key]));
|
|
27
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ParsedSchema } from '../utils/schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge `allOf` object schema
|
|
4
|
+
*/
|
|
5
|
+
export declare function mergeAllOf(schema: ParsedSchema): ParsedSchema;
|
|
6
|
+
export declare function intersection(a: ParsedSchema, b: ParsedSchema): ParsedSchema;
|
|
7
|
+
//# sourceMappingURL=merge-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-schema.d.ts","sourceRoot":"","sources":["../../src/utils/merge-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAS7D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,CAgJ3E"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { deepEqual } from './deep-equal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merge `allOf` object schema
|
|
4
|
+
*/
|
|
5
|
+
export function mergeAllOf(schema) {
|
|
6
|
+
if (typeof schema === 'boolean' || !schema.allOf)
|
|
7
|
+
return schema;
|
|
8
|
+
const { allOf, ...rest } = schema;
|
|
9
|
+
let result = rest;
|
|
10
|
+
for (const item of allOf) {
|
|
11
|
+
result = intersection(result, item);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
export function intersection(a, b) {
|
|
16
|
+
a = mergeAllOf(a);
|
|
17
|
+
b = mergeAllOf(b);
|
|
18
|
+
if (typeof a === 'boolean' && typeof b === 'boolean')
|
|
19
|
+
return a && b;
|
|
20
|
+
if (typeof a === 'boolean')
|
|
21
|
+
return a;
|
|
22
|
+
if (typeof b === 'boolean')
|
|
23
|
+
return b;
|
|
24
|
+
const result = { ...a };
|
|
25
|
+
for (const _k in b) {
|
|
26
|
+
const key = _k;
|
|
27
|
+
switch (key) {
|
|
28
|
+
case '$id':
|
|
29
|
+
case '$comment':
|
|
30
|
+
case 'description':
|
|
31
|
+
case 'additionalItems':
|
|
32
|
+
case 'examples':
|
|
33
|
+
case 'allOf':
|
|
34
|
+
case 'writeOnly':
|
|
35
|
+
case 'readOnly':
|
|
36
|
+
// ignored
|
|
37
|
+
break;
|
|
38
|
+
case 'title': {
|
|
39
|
+
const value = b[key];
|
|
40
|
+
if (value === undefined)
|
|
41
|
+
break;
|
|
42
|
+
if (result[key]) {
|
|
43
|
+
result[key] = `${result[key]} & ${value}`;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
result[key] = value;
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case 'minItems':
|
|
51
|
+
case 'minimum':
|
|
52
|
+
case 'exclusiveMinimum':
|
|
53
|
+
case 'minProperties':
|
|
54
|
+
case 'minContains':
|
|
55
|
+
case 'minLength': {
|
|
56
|
+
const value = b[key];
|
|
57
|
+
if (value === undefined)
|
|
58
|
+
break;
|
|
59
|
+
result[key] =
|
|
60
|
+
result[key] === undefined ? value : Math.max(result[key], value);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'maxContains':
|
|
64
|
+
case 'maxItems':
|
|
65
|
+
case 'maxLength':
|
|
66
|
+
case 'maxProperties':
|
|
67
|
+
case 'maximum':
|
|
68
|
+
case 'exclusiveMaximum': {
|
|
69
|
+
const value = b[key];
|
|
70
|
+
if (value === undefined)
|
|
71
|
+
break;
|
|
72
|
+
result[key] =
|
|
73
|
+
result[key] === undefined ? value : Math.min(result[key], value);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
// intersection
|
|
77
|
+
case 'enum':
|
|
78
|
+
case 'anyOf':
|
|
79
|
+
case 'oneOf': {
|
|
80
|
+
const value = b[key];
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
break;
|
|
83
|
+
result[key] =
|
|
84
|
+
result[key] === undefined
|
|
85
|
+
? value
|
|
86
|
+
: intersectArray(result[key], value);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
// require same
|
|
90
|
+
case 'format':
|
|
91
|
+
case 'const':
|
|
92
|
+
case 'type': {
|
|
93
|
+
const value = b[key];
|
|
94
|
+
if (value === undefined)
|
|
95
|
+
break;
|
|
96
|
+
result[key] ?? (result[key] = value);
|
|
97
|
+
if (!deepEqual(result[key], value))
|
|
98
|
+
return false;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
// add
|
|
102
|
+
case 'required': {
|
|
103
|
+
const value = b[key];
|
|
104
|
+
if (value === undefined)
|
|
105
|
+
break;
|
|
106
|
+
result[key] = [...(result[key] ?? []), ...value];
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'properties':
|
|
110
|
+
case 'patternProperties': {
|
|
111
|
+
const value = b[key];
|
|
112
|
+
if (value === undefined)
|
|
113
|
+
break;
|
|
114
|
+
if (result[key] === undefined) {
|
|
115
|
+
result[key] = value;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
const out = {};
|
|
119
|
+
const allProps = new Set();
|
|
120
|
+
for (const k in result[key])
|
|
121
|
+
allProps.add(k);
|
|
122
|
+
for (const k in value)
|
|
123
|
+
allProps.add(k);
|
|
124
|
+
for (const prop of allProps) {
|
|
125
|
+
const aProp = result[key][prop];
|
|
126
|
+
const bProp = value[prop];
|
|
127
|
+
if (aProp === undefined) {
|
|
128
|
+
out[prop] = bProp;
|
|
129
|
+
}
|
|
130
|
+
else if (bProp === undefined) {
|
|
131
|
+
out[prop] = aProp;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
out[prop] = intersection(aProp, bProp);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
result[key] = out;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case 'additionalProperties':
|
|
141
|
+
case 'contains':
|
|
142
|
+
case 'items': {
|
|
143
|
+
const value = b[key];
|
|
144
|
+
if (value === undefined)
|
|
145
|
+
break;
|
|
146
|
+
result[key] =
|
|
147
|
+
result[key] === undefined ? value : intersection(result[key], value);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'not': {
|
|
151
|
+
const value = b[key];
|
|
152
|
+
if (value === undefined)
|
|
153
|
+
break;
|
|
154
|
+
if (result[key] && value) {
|
|
155
|
+
result.not = { anyOf: [result[key], value] };
|
|
156
|
+
}
|
|
157
|
+
else if (value) {
|
|
158
|
+
result.not = value;
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
default:
|
|
163
|
+
result[key] = b[key];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function intersectArray(a, b) {
|
|
169
|
+
const out = new Set();
|
|
170
|
+
for (const item of a) {
|
|
171
|
+
if (b.includes(item))
|
|
172
|
+
out.add(item);
|
|
173
|
+
}
|
|
174
|
+
for (const item of b) {
|
|
175
|
+
if (a.includes(item))
|
|
176
|
+
out.add(item);
|
|
177
|
+
}
|
|
178
|
+
return Array.from(out);
|
|
179
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAmBvD"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
export function toBody(entry) {
|
|
2
2
|
if (entry.type === 'operation')
|
|
3
3
|
return {
|
|
4
|
-
hasHead: false,
|
|
5
4
|
document: entry.schemaId,
|
|
6
5
|
operations: [entry.item],
|
|
7
6
|
};
|
|
8
7
|
if (entry.type === 'webhook')
|
|
9
8
|
return {
|
|
10
|
-
hasHead: false,
|
|
11
9
|
document: entry.schemaId,
|
|
12
10
|
webhooks: [entry.item],
|
|
13
11
|
};
|
|
14
12
|
return {
|
|
15
|
-
|
|
13
|
+
showTitle: true,
|
|
14
|
+
showDescription: true,
|
|
16
15
|
document: entry.schemaId,
|
|
17
16
|
operations: entry.operations,
|
|
18
17
|
webhooks: entry.webhooks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-text.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-text.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+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