fumadocs-openapi 10.2.2 → 10.2.3
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 +53 -49
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +88 -102
- package/dist/generate-file.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -1
- package/dist/playground/client.d.ts +88 -72
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +446 -296
- package/dist/playground/client.js.map +1 -0
- package/dist/playground/components/inputs.js +395 -172
- package/dist/playground/components/inputs.js.map +1 -0
- package/dist/playground/components/oauth-dialog.js +270 -174
- package/dist/playground/components/oauth-dialog.js.map +1 -0
- package/dist/playground/components/server-select.js +115 -55
- package/dist/playground/components/server-select.js.map +1 -0
- package/dist/playground/fetcher.d.ts +10 -18
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +67 -75
- package/dist/playground/fetcher.js.map +1 -0
- package/dist/playground/get-default-values.js +23 -26
- package/dist/playground/get-default-values.js.map +1 -0
- package/dist/playground/index.d.ts +23 -13
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +87 -91
- package/dist/playground/index.js.map +1 -0
- package/dist/playground/lazy.js +9 -2
- package/dist/playground/lazy.js.map +1 -0
- package/dist/playground/schema.d.ts +18 -55
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +117 -106
- package/dist/playground/schema.js.map +1 -0
- package/dist/playground/status-info.js +49 -37
- package/dist/playground/status-info.js.map +1 -0
- package/dist/requests/generators/csharp.js +40 -50
- package/dist/requests/generators/csharp.js.map +1 -0
- package/dist/requests/generators/curl.js +28 -27
- package/dist/requests/generators/curl.js.map +1 -0
- package/dist/requests/generators/go.js +39 -35
- package/dist/requests/generators/go.js.map +1 -0
- package/dist/requests/generators/index.js +49 -43
- package/dist/requests/generators/index.js.map +1 -0
- package/dist/requests/generators/java.js +56 -67
- package/dist/requests/generators/java.js.map +1 -0
- package/dist/requests/generators/javascript.js +38 -45
- package/dist/requests/generators/javascript.js.map +1 -0
- package/dist/requests/generators/python.js +33 -37
- package/dist/requests/generators/python.js.map +1 -0
- package/dist/requests/media/adapter.d.ts +38 -84
- package/dist/requests/media/adapter.d.ts.map +1 -1
- package/dist/requests/media/adapter.js +122 -169
- package/dist/requests/media/adapter.js.map +1 -0
- package/dist/requests/media/encode.d.ts +12 -7
- package/dist/requests/media/encode.d.ts.map +1 -1
- package/dist/requests/media/encode.js +129 -109
- package/dist/requests/media/encode.js.map +1 -0
- package/dist/requests/media/resolve-adapter.js +28 -28
- package/dist/requests/media/resolve-adapter.js.map +1 -0
- package/dist/requests/string-utils.js +28 -35
- package/dist/requests/string-utils.js.map +1 -0
- package/dist/requests/to-python-object.js +16 -28
- package/dist/requests/to-python-object.js.map +1 -0
- package/dist/requests/types.d.ts +25 -21
- package/dist/requests/types.d.ts.map +1 -1
- package/dist/scalar/client.js +57 -20
- package/dist/scalar/client.js.map +1 -0
- package/dist/scalar/index.d.ts +8 -2
- package/dist/scalar/index.d.ts.map +1 -1
- package/dist/scalar/index.js +29 -19
- package/dist/scalar/index.js.map +1 -0
- package/dist/server/create.d.ts +29 -25
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +42 -39
- package/dist/server/create.js.map +1 -0
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +4 -2
- package/dist/server/proxy.d.ts +28 -28
- package/dist/server/proxy.d.ts.map +1 -1
- package/dist/server/proxy.js +58 -75
- package/dist/server/proxy.js.map +1 -0
- package/dist/server/source-api.d.ts +32 -29
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/server/source-api.js +82 -75
- package/dist/server/source-api.js.map +1 -0
- package/dist/types.d.ts +41 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts +140 -136
- package/dist/ui/api-page.d.ts.map +1 -1
- package/dist/ui/api-page.js +134 -118
- package/dist/ui/api-page.js.map +1 -0
- package/dist/ui/client/index.d.ts +30 -26
- package/dist/ui/client/index.d.ts.map +1 -1
- package/dist/ui/client/index.js +8 -2
- package/dist/ui/client/index.js.map +1 -0
- package/dist/ui/client/storage-key.js +16 -10
- package/dist/ui/client/storage-key.js.map +1 -0
- package/dist/ui/components/accordion.js +40 -14
- package/dist/ui/components/accordion.js.map +1 -0
- package/dist/ui/components/dialog.js +51 -15
- package/dist/ui/components/dialog.js.map +1 -0
- package/dist/ui/components/input.js +18 -8
- package/dist/ui/components/input.js.map +1 -0
- package/dist/ui/components/method-label.js +38 -33
- package/dist/ui/components/method-label.js.map +1 -0
- package/dist/ui/components/select.js +66 -15
- package/dist/ui/components/select.js.map +1 -0
- package/dist/ui/contexts/api.js +96 -85
- package/dist/ui/contexts/api.js.map +1 -0
- package/dist/ui/contexts/api.lazy.js +9 -2
- package/dist/ui/contexts/api.lazy.js.map +1 -0
- package/dist/ui/index.d.ts +2 -2
- package/dist/ui/index.js +3 -1
- package/dist/ui/operation/client.js +65 -27
- package/dist/ui/operation/client.js.map +1 -0
- package/dist/ui/operation/index.js +403 -186
- package/dist/ui/operation/index.js.map +1 -0
- package/dist/ui/operation/request-tabs.d.ts +15 -16
- package/dist/ui/operation/request-tabs.d.ts.map +1 -1
- package/dist/ui/operation/request-tabs.js +151 -131
- package/dist/ui/operation/request-tabs.js.map +1 -0
- package/dist/ui/operation/response-tabs.d.ts +27 -28
- package/dist/ui/operation/response-tabs.d.ts.map +1 -1
- package/dist/ui/operation/response-tabs.js +73 -56
- package/dist/ui/operation/response-tabs.js.map +1 -0
- package/dist/ui/operation/usage-tabs/client.js +117 -88
- package/dist/ui/operation/usage-tabs/client.js.map +1 -0
- package/dist/ui/operation/usage-tabs/index.d.ts +22 -21
- package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -1
- package/dist/ui/operation/usage-tabs/index.js +63 -48
- package/dist/ui/operation/usage-tabs/index.js.map +1 -0
- package/dist/ui/operation/usage-tabs/lazy.js +11 -4
- package/dist/ui/operation/usage-tabs/lazy.js.map +1 -0
- package/dist/ui/schema/client.d.ts +11 -7
- package/dist/ui/schema/client.d.ts.map +1 -1
- package/dist/ui/schema/client.js +213 -127
- package/dist/ui/schema/client.js.map +1 -0
- package/dist/ui/schema/index.d.ts +51 -50
- package/dist/ui/schema/index.d.ts.map +1 -1
- package/dist/ui/schema/index.js +225 -248
- package/dist/ui/schema/index.js.map +1 -0
- package/dist/ui/schema/lazy.js +9 -2
- package/dist/ui/schema/lazy.js.map +1 -0
- package/dist/utils/cn.js +3 -1
- package/dist/utils/deep-equal.js +18 -26
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/get-typescript-schema.js +21 -19
- package/dist/utils/get-typescript-schema.js.map +1 -0
- package/dist/utils/id-to-title.js +13 -16
- package/dist/utils/id-to-title.js.map +1 -0
- package/dist/utils/lazy.js +13 -11
- package/dist/utils/lazy.js.map +1 -0
- package/dist/utils/merge-schema.js +130 -174
- package/dist/utils/merge-schema.js.map +1 -0
- package/dist/utils/pages/builder.d.ts +80 -76
- package/dist/utils/pages/builder.d.ts.map +1 -1
- package/dist/utils/pages/builder.js +101 -118
- package/dist/utils/pages/builder.js.map +1 -0
- package/dist/utils/pages/preset-auto.d.ts +58 -55
- package/dist/utils/pages/preset-auto.d.ts.map +1 -1
- package/dist/utils/pages/preset-auto.js +124 -137
- package/dist/utils/pages/preset-auto.js.map +1 -0
- package/dist/utils/pages/to-body.js +21 -18
- package/dist/utils/pages/to-body.js.map +1 -0
- package/dist/utils/pages/to-static-data.js +48 -40
- package/dist/utils/pages/to-static-data.js.map +1 -0
- package/dist/utils/pages/to-text.d.ts +43 -41
- package/dist/utils/pages/to-text.d.ts.map +1 -1
- package/dist/utils/pages/to-text.js +93 -126
- package/dist/utils/pages/to-text.js.map +1 -0
- package/dist/utils/process-document.d.ts +18 -19
- package/dist/utils/process-document.d.ts.map +1 -1
- package/dist/utils/process-document.js +43 -54
- package/dist/utils/process-document.js.map +1 -0
- package/dist/utils/remove-undefined.js +18 -18
- package/dist/utils/remove-undefined.js.map +1 -0
- package/dist/utils/schema-to-string.js +46 -64
- package/dist/utils/schema-to-string.js.map +1 -0
- package/dist/utils/schema.d.ts +11 -27
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +43 -44
- package/dist/utils/schema.js.map +1 -0
- package/dist/utils/url.js +35 -56
- package/dist/utils/url.js.map +1 -0
- package/dist/utils/use-query.js +39 -33
- package/dist/utils/use-query.js.map +1 -0
- package/package.json +33 -32
- package/dist/index.d.ts.map +0 -1
- package/dist/playground/components/inputs.d.ts +0 -25
- package/dist/playground/components/inputs.d.ts.map +0 -1
- package/dist/playground/components/oauth-dialog.d.ts +0 -13
- package/dist/playground/components/oauth-dialog.d.ts.map +0 -1
- package/dist/playground/components/server-select.d.ts +0 -3
- package/dist/playground/components/server-select.d.ts.map +0 -1
- package/dist/playground/get-default-values.d.ts +0 -3
- package/dist/playground/get-default-values.d.ts.map +0 -1
- package/dist/playground/lazy.d.ts +0 -2
- package/dist/playground/lazy.d.ts.map +0 -1
- package/dist/playground/status-info.d.ts +0 -8
- package/dist/playground/status-info.d.ts.map +0 -1
- package/dist/requests/generators/csharp.d.ts +0 -3
- package/dist/requests/generators/csharp.d.ts.map +0 -1
- package/dist/requests/generators/curl.d.ts +0 -3
- package/dist/requests/generators/curl.d.ts.map +0 -1
- package/dist/requests/generators/go.d.ts +0 -3
- package/dist/requests/generators/go.d.ts.map +0 -1
- package/dist/requests/generators/index.d.ts +0 -3
- package/dist/requests/generators/index.d.ts.map +0 -1
- package/dist/requests/generators/java.d.ts +0 -3
- package/dist/requests/generators/java.d.ts.map +0 -1
- package/dist/requests/generators/javascript.d.ts +0 -3
- package/dist/requests/generators/javascript.d.ts.map +0 -1
- package/dist/requests/generators/python.d.ts +0 -3
- package/dist/requests/generators/python.d.ts.map +0 -1
- package/dist/requests/media/resolve-adapter.d.ts +0 -19
- package/dist/requests/media/resolve-adapter.d.ts.map +0 -1
- package/dist/requests/string-utils.d.ts +0 -7
- package/dist/requests/string-utils.d.ts.map +0 -1
- package/dist/requests/to-python-object.d.ts +0 -2
- package/dist/requests/to-python-object.d.ts.map +0 -1
- package/dist/requests/types.js +0 -1
- package/dist/scalar/client.d.ts +0 -7
- package/dist/scalar/client.d.ts.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/dist/ui/client/storage-key.d.ts +0 -9
- package/dist/ui/client/storage-key.d.ts.map +0 -1
- package/dist/ui/components/accordion.d.ts +0 -8
- package/dist/ui/components/accordion.d.ts.map +0 -1
- package/dist/ui/components/dialog.d.ts +0 -20
- package/dist/ui/components/dialog.d.ts.map +0 -1
- package/dist/ui/components/input.d.ts +0 -6
- package/dist/ui/components/input.d.ts.map +0 -1
- package/dist/ui/components/method-label.d.ts +0 -10
- package/dist/ui/components/method-label.d.ts.map +0 -1
- package/dist/ui/components/select.d.ts +0 -14
- package/dist/ui/components/select.d.ts.map +0 -1
- package/dist/ui/contexts/api.d.ts +0 -33
- package/dist/ui/contexts/api.d.ts.map +0 -1
- package/dist/ui/contexts/api.lazy.d.ts +0 -2
- package/dist/ui/contexts/api.lazy.d.ts.map +0 -1
- package/dist/ui/icons.d.ts +0 -49
- package/dist/ui/icons.d.ts.map +0 -1
- package/dist/ui/icons.js +0 -281
- package/dist/ui/index.d.ts.map +0 -1
- package/dist/ui/operation/client.d.ts +0 -19
- package/dist/ui/operation/client.d.ts.map +0 -1
- package/dist/ui/operation/index.d.ts +0 -12
- package/dist/ui/operation/index.d.ts.map +0 -1
- package/dist/ui/operation/usage-tabs/client.d.ts +0 -23
- package/dist/ui/operation/usage-tabs/client.d.ts.map +0 -1
- package/dist/ui/operation/usage-tabs/lazy.d.ts +0 -4
- package/dist/ui/operation/usage-tabs/lazy.d.ts.map +0 -1
- package/dist/ui/schema/lazy.d.ts +0 -2
- package/dist/ui/schema/lazy.d.ts.map +0 -1
- package/dist/utils/cn.d.ts +0 -2
- package/dist/utils/cn.d.ts.map +0 -1
- package/dist/utils/deep-equal.d.ts +0 -2
- package/dist/utils/deep-equal.d.ts.map +0 -1
- package/dist/utils/get-typescript-schema.d.ts +0 -4
- package/dist/utils/get-typescript-schema.d.ts.map +0 -1
- package/dist/utils/id-to-title.d.ts +0 -2
- package/dist/utils/id-to-title.d.ts.map +0 -1
- package/dist/utils/lazy.d.ts +0 -5
- package/dist/utils/lazy.d.ts.map +0 -1
- package/dist/utils/merge-schema.d.ts +0 -7
- package/dist/utils/merge-schema.d.ts.map +0 -1
- package/dist/utils/pages/to-body.d.ts +0 -4
- package/dist/utils/pages/to-body.d.ts.map +0 -1
- package/dist/utils/pages/to-static-data.d.ts +0 -10
- package/dist/utils/pages/to-static-data.d.ts.map +0 -1
- package/dist/utils/remove-undefined.d.ts +0 -2
- package/dist/utils/remove-undefined.d.ts.map +0 -1
- package/dist/utils/schema-to-string.d.ts +0 -8
- package/dist/utils/schema-to-string.d.ts.map +0 -1
- package/dist/utils/url.d.ts +0 -11
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/use-query.d.ts +0 -8
- package/dist/utils/use-query.d.ts.map +0 -1
package/dist/playground/index.js
CHANGED
|
@@ -1,95 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import { getPreferredType } from "../utils/schema.js";
|
|
2
|
+
import { ClientLazy } from "./lazy.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/playground/index.tsx
|
|
6
|
+
async function APIPlayground({ path, method, ctx }) {
|
|
7
|
+
if (ctx.playground?.render) return ctx.playground.render({
|
|
8
|
+
path,
|
|
9
|
+
method,
|
|
10
|
+
ctx
|
|
11
|
+
});
|
|
12
|
+
let currentId = 0;
|
|
13
|
+
const bodyContent = method.requestBody?.content;
|
|
14
|
+
const mediaType = bodyContent ? getPreferredType(bodyContent) : void 0;
|
|
15
|
+
const context = {
|
|
16
|
+
references: {},
|
|
17
|
+
nextId() {
|
|
18
|
+
return String(currentId++);
|
|
19
|
+
},
|
|
20
|
+
registered: /* @__PURE__ */ new WeakMap()
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsx(ClientLazy, {
|
|
23
|
+
securities: parseSecurities(method, ctx),
|
|
24
|
+
method: method.method,
|
|
25
|
+
route: path,
|
|
26
|
+
parameters: method.parameters,
|
|
27
|
+
body: bodyContent && mediaType ? {
|
|
28
|
+
schema: writeReferences(bodyContent[mediaType].schema, context),
|
|
29
|
+
mediaType
|
|
30
|
+
} : void 0,
|
|
31
|
+
references: context.references,
|
|
32
|
+
proxyUrl: ctx.proxyUrl,
|
|
33
|
+
writeOnly: true,
|
|
34
|
+
readOnly: false
|
|
35
|
+
});
|
|
35
36
|
}
|
|
36
|
-
function writeReferences(schema, ctx, stack = new WeakMap()) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (const key in output[name]) {
|
|
68
|
-
output[name][key] = writeReferences(output[name][key], ctx, stack);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return output;
|
|
37
|
+
function writeReferences(schema, ctx, stack = /* @__PURE__ */ new WeakMap()) {
|
|
38
|
+
if (typeof schema !== "object" || !schema) return schema;
|
|
39
|
+
if (stack.has(schema)) {
|
|
40
|
+
const out = stack.get(schema);
|
|
41
|
+
const id = ctx.nextId();
|
|
42
|
+
ctx.references[id] = out;
|
|
43
|
+
return { $ref: id };
|
|
44
|
+
}
|
|
45
|
+
const output = { ...schema };
|
|
46
|
+
stack.set(schema, output);
|
|
47
|
+
for (const _n in output) {
|
|
48
|
+
const name = _n;
|
|
49
|
+
if (!output[name]) continue;
|
|
50
|
+
switch (name) {
|
|
51
|
+
case "oneOf":
|
|
52
|
+
case "allOf":
|
|
53
|
+
case "anyOf":
|
|
54
|
+
output[name] = output[name].map((item) => writeReferences(item, ctx, stack));
|
|
55
|
+
continue;
|
|
56
|
+
case "items":
|
|
57
|
+
case "additionalProperties":
|
|
58
|
+
case "not":
|
|
59
|
+
output[name] = writeReferences(output[name], ctx, stack);
|
|
60
|
+
continue;
|
|
61
|
+
case "properties":
|
|
62
|
+
case "patternProperties":
|
|
63
|
+
output[name] = { ...output[name] };
|
|
64
|
+
for (const key in output[name]) output[name][key] = writeReferences(output[name][key], ctx, stack);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return output;
|
|
73
68
|
}
|
|
74
69
|
function parseSecurities(method, { schema: { dereferenced } }) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
result.push(list);
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
70
|
+
const result = [];
|
|
71
|
+
const security = method.security ?? dereferenced.security ?? [];
|
|
72
|
+
if (security.length === 0) return result;
|
|
73
|
+
for (const map of security) {
|
|
74
|
+
const list = [];
|
|
75
|
+
for (const [key, scopes] of Object.entries(map)) {
|
|
76
|
+
const scheme = dereferenced.components?.securitySchemes?.[key];
|
|
77
|
+
if (!scheme) continue;
|
|
78
|
+
list.push({
|
|
79
|
+
...scheme,
|
|
80
|
+
scopes,
|
|
81
|
+
id: key
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (list.length > 0) result.push(list);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
95
87
|
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { APIPlayground };
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["context: Context","result: PlaygroundClientProps['securities']","list: PlaygroundClientProps['securities'][number]"],"sources":["../../src/playground/index.tsx"],"sourcesContent":["import type {\n MethodInformation,\n ParameterObject,\n RenderContext,\n SecuritySchemeObject,\n} from '@/types';\nimport { getPreferredType, type NoReference, type ParsedSchema } from '@/utils/schema';\nimport { type PlaygroundClientProps } from './client';\nimport { ClientLazy } from './lazy';\n\nexport type ParameterField = NoReference<ParameterObject> & {\n schema: ParsedSchema;\n in: 'cookie' | 'header' | 'query' | 'path';\n};\n\ninterface Context {\n references: Record<string, ParsedSchema>;\n registered: WeakMap<Exclude<ParsedSchema, boolean>, string>;\n nextId: () => string;\n}\n\nexport interface APIPlaygroundProps {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n}\n\nexport type SecurityEntry = SecuritySchemeObject & {\n scopes: string[];\n id: string;\n};\n\nexport async function APIPlayground({ path, method, ctx }: APIPlaygroundProps) {\n if (ctx.playground?.render) {\n return ctx.playground.render({ path, method, ctx });\n }\n\n let currentId = 0;\n const bodyContent = method.requestBody?.content;\n const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;\n\n const context: Context = {\n references: {},\n nextId() {\n return String(currentId++);\n },\n registered: new WeakMap(),\n };\n\n const props: PlaygroundClientProps = {\n securities: parseSecurities(method, ctx),\n method: method.method,\n route: path,\n parameters: method.parameters as ParameterField[],\n body:\n bodyContent && mediaType\n ? ({\n schema: writeReferences(bodyContent[mediaType].schema as ParsedSchema, context),\n mediaType,\n } as PlaygroundClientProps['body'])\n : undefined,\n references: context.references,\n proxyUrl: ctx.proxyUrl,\n writeOnly: true,\n readOnly: false,\n };\n\n return <ClientLazy {...props} />;\n}\n\nfunction writeReferences(\n schema: ParsedSchema,\n ctx: Context,\n stack: WeakMap<object, object> = new WeakMap(),\n): ParsedSchema {\n if (typeof schema !== 'object' || !schema) return schema;\n if (stack.has(schema)) {\n const out = stack.get(schema)!;\n const id = ctx.nextId();\n ctx.references[id] = out;\n\n return {\n $ref: id,\n };\n }\n\n const output = { ...schema };\n stack.set(schema, output);\n for (const _n in output) {\n const name = _n as keyof typeof output;\n if (!output[name]) continue;\n\n switch (name) {\n case 'oneOf':\n case 'allOf':\n case 'anyOf':\n output[name] = output[name].map((item) => writeReferences(item, ctx, stack));\n continue;\n case 'items':\n case 'additionalProperties':\n case 'not':\n output[name] = writeReferences(output[name], ctx, stack);\n continue;\n case 'properties':\n case 'patternProperties':\n output[name] = { ...output[name] };\n\n for (const key in output[name]) {\n output[name][key] = writeReferences(output[name][key], ctx, stack);\n }\n }\n }\n\n return output;\n}\n\nfunction parseSecurities(\n method: MethodInformation,\n { schema: { dereferenced } }: RenderContext,\n): PlaygroundClientProps['securities'] {\n const result: PlaygroundClientProps['securities'] = [];\n const security = method.security ?? dereferenced.security ?? [];\n if (security.length === 0) return result;\n\n for (const map of security) {\n const list: PlaygroundClientProps['securities'][number] = [];\n\n for (const [key, scopes] of Object.entries(map)) {\n const scheme = dereferenced.components?.securitySchemes?.[key];\n if (!scheme) continue;\n\n list.push({\n ...scheme,\n scopes,\n id: key,\n });\n }\n\n if (list.length > 0) result.push(list);\n }\n\n return result;\n}\n"],"mappings":";;;;;AAgCA,eAAsB,cAAc,EAAE,MAAM,QAAQ,OAA2B;AAC7E,KAAI,IAAI,YAAY,OAClB,QAAO,IAAI,WAAW,OAAO;EAAE;EAAM;EAAQ;EAAK,CAAC;CAGrD,IAAI,YAAY;CAChB,MAAM,cAAc,OAAO,aAAa;CACxC,MAAM,YAAY,cAAc,iBAAiB,YAAY,GAAG;CAEhE,MAAMA,UAAmB;EACvB,YAAY,EAAE;EACd,SAAS;AACP,UAAO,OAAO,YAAY;;EAE5B,4BAAY,IAAI,SAAS;EAC1B;AAoBD,QAAO,oBAAC;EAjBN,YAAY,gBAAgB,QAAQ,IAAI;EACxC,QAAQ,OAAO;EACf,OAAO;EACP,YAAY,OAAO;EACnB,MACE,eAAe,YACV;GACC,QAAQ,gBAAgB,YAAY,WAAW,QAAwB,QAAQ;GAC/E;GACD,GACD;EACN,YAAY,QAAQ;EACpB,UAAU,IAAI;EACd,WAAW;EACX,UAAU;GAGoB;;AAGlC,SAAS,gBACP,QACA,KACA,wBAAiC,IAAI,SAAS,EAChC;AACd,KAAI,OAAO,WAAW,YAAY,CAAC,OAAQ,QAAO;AAClD,KAAI,MAAM,IAAI,OAAO,EAAE;EACrB,MAAM,MAAM,MAAM,IAAI,OAAO;EAC7B,MAAM,KAAK,IAAI,QAAQ;AACvB,MAAI,WAAW,MAAM;AAErB,SAAO,EACL,MAAM,IACP;;CAGH,MAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,OAAM,IAAI,QAAQ,OAAO;AACzB,MAAK,MAAM,MAAM,QAAQ;EACvB,MAAM,OAAO;AACb,MAAI,CAAC,OAAO,MAAO;AAEnB,UAAQ,MAAR;GACE,KAAK;GACL,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,OAAO,MAAM,KAAK,SAAS,gBAAgB,MAAM,KAAK,MAAM,CAAC;AAC5E;GACF,KAAK;GACL,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,gBAAgB,OAAO,OAAO,KAAK,MAAM;AACxD;GACF,KAAK;GACL,KAAK;AACH,WAAO,QAAQ,EAAE,GAAG,OAAO,OAAO;AAElC,SAAK,MAAM,OAAO,OAAO,MACvB,QAAO,MAAM,OAAO,gBAAgB,OAAO,MAAM,MAAM,KAAK,MAAM;;;AAK1E,QAAO;;AAGT,SAAS,gBACP,QACA,EAAE,QAAQ,EAAE,kBACyB;CACrC,MAAMC,SAA8C,EAAE;CACtD,MAAM,WAAW,OAAO,YAAY,aAAa,YAAY,EAAE;AAC/D,KAAI,SAAS,WAAW,EAAG,QAAO;AAElC,MAAK,MAAM,OAAO,UAAU;EAC1B,MAAMC,OAAoD,EAAE;AAE5D,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,EAAE;GAC/C,MAAM,SAAS,aAAa,YAAY,kBAAkB;AAC1D,OAAI,CAAC,OAAQ;AAEb,QAAK,KAAK;IACR,GAAG;IACH;IACA,IAAI;IACL,CAAC;;AAGJ,MAAI,KAAK,SAAS,EAAG,QAAO,KAAK,KAAK;;AAGxC,QAAO"}
|
package/dist/playground/lazy.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
import { wrapLazy } from "../utils/lazy.js";
|
|
4
|
+
|
|
5
|
+
//#region src/playground/lazy.ts
|
|
6
|
+
const ClientLazy = wrapLazy(() => import("./client.js"));
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ClientLazy };
|
|
10
|
+
//# sourceMappingURL=lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.js","names":[],"sources":["../../src/playground/lazy.ts"],"sourcesContent":["'use client';\nimport { wrapLazy } from '../utils/lazy';\n\nexport const ClientLazy = wrapLazy(() => import('./client'));\n"],"mappings":";;;;;AAGA,MAAa,aAAa,eAAe,OAAO,eAAY"}
|
|
@@ -1,57 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReactNode } from
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import "../utils/schema.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
import { Ajv2020 } from "ajv/dist/2020";
|
|
5
|
+
|
|
6
|
+
//#region src/playground/schema.d.ts
|
|
7
|
+
|
|
8
|
+
interface SchemaScope {
|
|
9
|
+
/**
|
|
10
|
+
* show write only fields
|
|
11
|
+
*/
|
|
12
|
+
writeOnly: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* show read only fields
|
|
15
|
+
*/
|
|
16
|
+
readOnly: boolean;
|
|
8
17
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* show write only fields
|
|
12
|
-
*/
|
|
13
|
-
writeOnly: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* show read only fields
|
|
16
|
-
*/
|
|
17
|
-
readOnly: boolean;
|
|
18
|
-
}
|
|
19
|
-
type UnionField = 'anyOf' | 'oneOf';
|
|
20
|
-
export interface FieldInfo {
|
|
21
|
-
selectedType?: string;
|
|
22
|
-
oneOf: number;
|
|
23
|
-
/**
|
|
24
|
-
* The actual field that represents union members.
|
|
25
|
-
*/
|
|
26
|
-
unionField?: UnionField;
|
|
27
|
-
intersection?: {
|
|
28
|
-
merged: Exclude<ParsedSchema, boolean>;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export declare const anyFields: {
|
|
32
|
-
type: string[];
|
|
33
|
-
items: true;
|
|
34
|
-
additionalProperties: true;
|
|
35
|
-
};
|
|
36
|
-
export declare function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children, }: Omit<SchemaContextType, 'ajv'> & {
|
|
37
|
-
children: ReactNode;
|
|
38
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
39
|
-
export declare function useSchemaScope(): SchemaScope;
|
|
40
|
-
/**
|
|
41
|
-
* A hook to store dynamic info of a field, such as selected schema of `oneOf`.
|
|
42
|
-
*
|
|
43
|
-
* @param fieldName - field name of form.
|
|
44
|
-
* @param schema - The JSON Schema to generate initial values.
|
|
45
|
-
* @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
|
|
46
|
-
*/
|
|
47
|
-
export declare function useFieldInfo(fieldName: string, schema: Exclude<ParsedSchema, boolean>, depth: number): {
|
|
48
|
-
info: FieldInfo;
|
|
49
|
-
updateInfo: (value: Partial<FieldInfo>) => void;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Resolve `$ref` in the schema, **not recursive**.
|
|
53
|
-
*/
|
|
54
|
-
export declare function useResolvedSchema(schema: ParsedSchema): Exclude<ParsedSchema, boolean>;
|
|
55
|
-
export declare function fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean>;
|
|
56
|
-
export {};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { SchemaScope };
|
|
57
20
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/playground/schema.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAaiB,WAAA"}
|
|
@@ -1,116 +1,127 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createContext, use, useMemo, useState } from
|
|
4
|
-
import { useFormContext } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { getDefaultValue } from "./get-default-values.js";
|
|
2
|
+
import { mergeAllOf } from "../utils/merge-schema.js";
|
|
3
|
+
import { createContext, use, useMemo, useState } from "react";
|
|
4
|
+
import { useFormContext } from "react-hook-form";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { Ajv2020 } from "ajv/dist/2020";
|
|
7
|
+
|
|
8
|
+
//#region src/playground/schema.tsx
|
|
9
|
+
const SchemaContext = createContext(void 0);
|
|
10
|
+
const anyFields = {
|
|
11
|
+
type: [
|
|
12
|
+
"string",
|
|
13
|
+
"number",
|
|
14
|
+
"boolean",
|
|
15
|
+
"array",
|
|
16
|
+
"object"
|
|
17
|
+
],
|
|
18
|
+
items: true,
|
|
19
|
+
additionalProperties: true
|
|
12
20
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
function SchemaProvider({ references, fieldInfoMap, readOnly, writeOnly, children }) {
|
|
22
|
+
const ajv = useMemo(() => new Ajv2020({
|
|
23
|
+
strict: false,
|
|
24
|
+
validateSchema: false,
|
|
25
|
+
validateFormats: false,
|
|
26
|
+
schemas: references
|
|
27
|
+
}), [references]);
|
|
28
|
+
return /* @__PURE__ */ jsx(SchemaContext.Provider, {
|
|
29
|
+
value: useMemo(() => ({
|
|
30
|
+
references,
|
|
31
|
+
fieldInfoMap,
|
|
32
|
+
ajv,
|
|
33
|
+
readOnly,
|
|
34
|
+
writeOnly
|
|
35
|
+
}), [
|
|
36
|
+
references,
|
|
37
|
+
fieldInfoMap,
|
|
38
|
+
ajv,
|
|
39
|
+
readOnly,
|
|
40
|
+
writeOnly
|
|
41
|
+
]),
|
|
42
|
+
children
|
|
43
|
+
});
|
|
21
44
|
}
|
|
22
|
-
|
|
23
|
-
|
|
45
|
+
function useSchemaScope() {
|
|
46
|
+
return use(SchemaContext);
|
|
24
47
|
}
|
|
25
48
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
setInfo(updated);
|
|
83
|
-
let valueSchema = schema;
|
|
84
|
-
if (updated.unionField) {
|
|
85
|
-
valueSchema = schema[updated.unionField][updated.oneOf];
|
|
86
|
-
}
|
|
87
|
-
else if (updated.selectedType) {
|
|
88
|
-
valueSchema = { ...schema, type: updated.selectedType };
|
|
89
|
-
}
|
|
90
|
-
form.setValue(fieldName, getDefaultValue(valueSchema));
|
|
91
|
-
},
|
|
92
|
-
};
|
|
49
|
+
* A hook to store dynamic info of a field, such as selected schema of `oneOf`.
|
|
50
|
+
*
|
|
51
|
+
* @param fieldName - field name of form.
|
|
52
|
+
* @param schema - The JSON Schema to generate initial values.
|
|
53
|
+
* @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
|
|
54
|
+
*/
|
|
55
|
+
function useFieldInfo(fieldName, schema, depth) {
|
|
56
|
+
const { fieldInfoMap, ajv } = use(SchemaContext);
|
|
57
|
+
const form = useFormContext();
|
|
58
|
+
const keyName = `${fieldName}:${depth}`;
|
|
59
|
+
const [info, setInfo] = useState(() => {
|
|
60
|
+
const value = form.getValues(fieldName);
|
|
61
|
+
const initialInfo = fieldInfoMap.get(keyName);
|
|
62
|
+
if (initialInfo) return initialInfo;
|
|
63
|
+
const out = { oneOf: -1 };
|
|
64
|
+
const union = getUnion(schema);
|
|
65
|
+
if (union) {
|
|
66
|
+
const [members, field] = union;
|
|
67
|
+
out.oneOf = members.findIndex((item) => ajv.validate(item, value));
|
|
68
|
+
if (out.oneOf === -1) out.oneOf = 0;
|
|
69
|
+
out.unionField = field;
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(schema.type)) {
|
|
72
|
+
const types = schema.type;
|
|
73
|
+
out.selectedType = types.find((type) => {
|
|
74
|
+
schema.type = type;
|
|
75
|
+
const match = ajv.validate(schema, value);
|
|
76
|
+
schema.type = types;
|
|
77
|
+
return match;
|
|
78
|
+
}) ?? types.at(0);
|
|
79
|
+
}
|
|
80
|
+
if (schema.allOf) {
|
|
81
|
+
const merged = mergeAllOf(schema);
|
|
82
|
+
if (typeof merged !== "boolean") out.intersection = { merged };
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
});
|
|
86
|
+
fieldInfoMap.set(keyName, info);
|
|
87
|
+
return {
|
|
88
|
+
info,
|
|
89
|
+
updateInfo: (value) => {
|
|
90
|
+
const updated = {
|
|
91
|
+
...info,
|
|
92
|
+
...value
|
|
93
|
+
};
|
|
94
|
+
if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;
|
|
95
|
+
setInfo(updated);
|
|
96
|
+
let valueSchema = schema;
|
|
97
|
+
if (updated.unionField) valueSchema = schema[updated.unionField][updated.oneOf];
|
|
98
|
+
else if (updated.selectedType) valueSchema = {
|
|
99
|
+
...schema,
|
|
100
|
+
type: updated.selectedType
|
|
101
|
+
};
|
|
102
|
+
form.setValue(fieldName, getDefaultValue(valueSchema));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
93
105
|
}
|
|
94
106
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return schema;
|
|
105
|
-
}, [references, schema]);
|
|
107
|
+
* Resolve `$ref` in the schema, **not recursive**.
|
|
108
|
+
*/
|
|
109
|
+
function useResolvedSchema(schema) {
|
|
110
|
+
const { references } = use(SchemaContext);
|
|
111
|
+
return useMemo(() => {
|
|
112
|
+
if (typeof schema === "boolean") return anyFields;
|
|
113
|
+
if (schema.$ref) return fallbackAny(references[schema.$ref]);
|
|
114
|
+
return schema;
|
|
115
|
+
}, [references, schema]);
|
|
106
116
|
}
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
function fallbackAny(schema) {
|
|
118
|
+
return typeof schema === "boolean" ? anyFields : schema;
|
|
109
119
|
}
|
|
110
120
|
function getUnion(schema) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
if (schema.oneOf)
|
|
115
|
-
return [schema.oneOf, 'oneOf'];
|
|
121
|
+
if (schema.anyOf) return [schema.anyOf, "anyOf"];
|
|
122
|
+
if (schema.oneOf) return [schema.oneOf, "oneOf"];
|
|
116
123
|
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaScope };
|
|
127
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":["out: FieldInfo","valueSchema: ParsedSchema"],"sources":["../../src/playground/schema.tsx"],"sourcesContent":["import { Ajv2020 } from 'ajv/dist/2020';\nimport { createContext, ReactNode, use, useMemo, useState } from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { getDefaultValue } from '@/playground/get-default-values';\nimport type { ParsedSchema } from '@/utils/schema';\nimport { mergeAllOf } from '@/utils/merge-schema';\n\ninterface SchemaContextType extends SchemaScope {\n references: Record<string, ParsedSchema>;\n fieldInfoMap: Map<string, FieldInfo>;\n ajv: Ajv2020;\n}\n\nexport interface SchemaScope {\n /**\n * show write only fields\n */\n writeOnly: boolean;\n\n /**\n * show read only fields\n */\n readOnly: boolean;\n}\n\ntype UnionField = 'anyOf' | 'oneOf';\n\nexport interface FieldInfo {\n selectedType?: string;\n oneOf: number;\n\n /**\n * The actual field that represents union members.\n */\n unionField?: UnionField;\n\n intersection?: {\n merged: Exclude<ParsedSchema, boolean>;\n };\n}\n\nconst SchemaContext = createContext<SchemaContextType | undefined>(undefined);\nexport const anyFields = {\n type: ['string', 'number', 'boolean', 'array', 'object'],\n items: true,\n additionalProperties: true,\n} satisfies ParsedSchema;\n\nexport function SchemaProvider({\n references,\n fieldInfoMap,\n readOnly,\n writeOnly,\n children,\n}: Omit<SchemaContextType, 'ajv'> & { children: ReactNode }) {\n const ajv = useMemo(\n () =>\n new Ajv2020({\n strict: false,\n validateSchema: false,\n validateFormats: false,\n schemas: references,\n }),\n [references],\n );\n\n return (\n <SchemaContext.Provider\n value={useMemo(\n () => ({ references, fieldInfoMap, ajv, readOnly, writeOnly }),\n [references, fieldInfoMap, ajv, readOnly, writeOnly],\n )}\n >\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport function useSchemaScope(): SchemaScope {\n return use(SchemaContext)!;\n}\n\n/**\n * A hook to store dynamic info of a field, such as selected schema of `oneOf`.\n *\n * @param fieldName - field name of form.\n * @param schema - The JSON Schema to generate initial values.\n * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).\n */\nexport function useFieldInfo(\n fieldName: string,\n schema: Exclude<ParsedSchema, boolean>,\n depth: number,\n): {\n info: FieldInfo;\n updateInfo: (value: Partial<FieldInfo>) => void;\n} {\n const { fieldInfoMap, ajv } = use(SchemaContext)!;\n const form = useFormContext();\n const keyName = `${fieldName}:${depth}`;\n const [info, setInfo] = useState<FieldInfo>(() => {\n const value = form.getValues(fieldName as 'body');\n const initialInfo = fieldInfoMap.get(keyName);\n if (initialInfo) return initialInfo;\n\n const out: FieldInfo = {\n oneOf: -1,\n };\n const union = getUnion(schema);\n if (union) {\n const [members, field] = union;\n\n out.oneOf = members.findIndex((item) => ajv.validate(item, value));\n if (out.oneOf === -1) out.oneOf = 0;\n out.unionField = field;\n }\n\n if (Array.isArray(schema.type)) {\n const types = schema.type;\n\n out.selectedType =\n types.find((type) => {\n schema.type = type;\n const match = ajv.validate(schema, value);\n schema.type = types;\n\n return match;\n }) ?? types.at(0);\n }\n\n if (schema.allOf) {\n const merged = mergeAllOf(schema);\n\n if (typeof merged !== 'boolean')\n out.intersection = {\n merged,\n };\n }\n\n return out;\n });\n\n fieldInfoMap.set(keyName, info);\n\n return {\n info,\n updateInfo: (value) => {\n const updated = {\n ...info,\n ...value,\n };\n\n if (updated.oneOf === info.oneOf && updated.selectedType === info.selectedType) return;\n\n setInfo(updated);\n\n let valueSchema: ParsedSchema = schema;\n if (updated.unionField) {\n valueSchema = schema[updated.unionField]![updated.oneOf];\n } else if (updated.selectedType) {\n valueSchema = { ...schema, type: updated.selectedType };\n }\n\n form.setValue(fieldName, getDefaultValue(valueSchema));\n },\n };\n}\n\n/**\n * Resolve `$ref` in the schema, **not recursive**.\n */\nexport function useResolvedSchema(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n const { references } = use(SchemaContext)!;\n\n return useMemo(() => {\n if (typeof schema === 'boolean') return anyFields;\n if (schema.$ref) return fallbackAny(references[schema.$ref]);\n return schema;\n }, [references, schema]);\n}\n\nexport function fallbackAny(schema: ParsedSchema): Exclude<ParsedSchema, boolean> {\n return typeof schema === 'boolean' ? anyFields : schema;\n}\n\nfunction getUnion(\n schema: Exclude<ParsedSchema, boolean>,\n): [readonly ParsedSchema[], UnionField] | undefined {\n if (schema.anyOf) {\n return [schema.anyOf, 'anyOf'];\n }\n\n if (schema.oneOf) return [schema.oneOf, 'oneOf'];\n}\n"],"mappings":";;;;;;;;AAyCA,MAAM,gBAAgB,cAA6C,OAAU;AAC7E,MAAa,YAAY;CACvB,MAAM;EAAC;EAAU;EAAU;EAAW;EAAS;EAAS;CACxD,OAAO;CACP,sBAAsB;CACvB;AAED,SAAgB,eAAe,EAC7B,YACA,cACA,UACA,WACA,YAC2D;CAC3D,MAAM,MAAM,cAER,IAAI,QAAQ;EACV,QAAQ;EACR,gBAAgB;EAChB,iBAAiB;EACjB,SAAS;EACV,CAAC,EACJ,CAAC,WAAW,CACb;AAED,QACE,oBAAC,cAAc;EACb,OAAO,eACE;GAAE;GAAY;GAAc;GAAK;GAAU;GAAW,GAC7D;GAAC;GAAY;GAAc;GAAK;GAAU;GAAU,CACrD;EAEA;GACsB;;AAI7B,SAAgB,iBAA8B;AAC5C,QAAO,IAAI,cAAc;;;;;;;;;AAU3B,SAAgB,aACd,WACA,QACA,OAIA;CACA,MAAM,EAAE,cAAc,QAAQ,IAAI,cAAc;CAChD,MAAM,OAAO,gBAAgB;CAC7B,MAAM,UAAU,GAAG,UAAU,GAAG;CAChC,MAAM,CAAC,MAAM,WAAW,eAA0B;EAChD,MAAM,QAAQ,KAAK,UAAU,UAAoB;EACjD,MAAM,cAAc,aAAa,IAAI,QAAQ;AAC7C,MAAI,YAAa,QAAO;EAExB,MAAMA,MAAiB,EACrB,OAAO,IACR;EACD,MAAM,QAAQ,SAAS,OAAO;AAC9B,MAAI,OAAO;GACT,MAAM,CAAC,SAAS,SAAS;AAEzB,OAAI,QAAQ,QAAQ,WAAW,SAAS,IAAI,SAAS,MAAM,MAAM,CAAC;AAClE,OAAI,IAAI,UAAU,GAAI,KAAI,QAAQ;AAClC,OAAI,aAAa;;AAGnB,MAAI,MAAM,QAAQ,OAAO,KAAK,EAAE;GAC9B,MAAM,QAAQ,OAAO;AAErB,OAAI,eACF,MAAM,MAAM,SAAS;AACnB,WAAO,OAAO;IACd,MAAM,QAAQ,IAAI,SAAS,QAAQ,MAAM;AACzC,WAAO,OAAO;AAEd,WAAO;KACP,IAAI,MAAM,GAAG,EAAE;;AAGrB,MAAI,OAAO,OAAO;GAChB,MAAM,SAAS,WAAW,OAAO;AAEjC,OAAI,OAAO,WAAW,UACpB,KAAI,eAAe,EACjB,QACD;;AAGL,SAAO;GACP;AAEF,cAAa,IAAI,SAAS,KAAK;AAE/B,QAAO;EACL;EACA,aAAa,UAAU;GACrB,MAAM,UAAU;IACd,GAAG;IACH,GAAG;IACJ;AAED,OAAI,QAAQ,UAAU,KAAK,SAAS,QAAQ,iBAAiB,KAAK,aAAc;AAEhF,WAAQ,QAAQ;GAEhB,IAAIC,cAA4B;AAChC,OAAI,QAAQ,WACV,eAAc,OAAO,QAAQ,YAAa,QAAQ;YACzC,QAAQ,aACjB,eAAc;IAAE,GAAG;IAAQ,MAAM,QAAQ;IAAc;AAGzD,QAAK,SAAS,WAAW,gBAAgB,YAAY,CAAC;;EAEzD;;;;;AAMH,SAAgB,kBAAkB,QAAsD;CACtF,MAAM,EAAE,eAAe,IAAI,cAAc;AAEzC,QAAO,cAAc;AACnB,MAAI,OAAO,WAAW,UAAW,QAAO;AACxC,MAAI,OAAO,KAAM,QAAO,YAAY,WAAW,OAAO,MAAM;AAC5D,SAAO;IACN,CAAC,YAAY,OAAO,CAAC;;AAG1B,SAAgB,YAAY,QAAsD;AAChF,QAAO,OAAO,WAAW,YAAY,YAAY;;AAGnD,SAAS,SACP,QACmD;AACnD,KAAI,OAAO,MACT,QAAO,CAAC,OAAO,OAAO,QAAQ;AAGhC,KAAI,OAAO,MAAO,QAAO,CAAC,OAAO,OAAO,QAAQ"}
|
|
@@ -1,40 +1,52 @@
|
|
|
1
|
-
import { CircleCheck, CircleX } from
|
|
1
|
+
import { CircleCheck, CircleX } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
//#region src/playground/status-info.tsx
|
|
2
4
|
const statusMap = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
400: {
|
|
6
|
+
description: "Bad Request",
|
|
7
|
+
color: "text-red-500",
|
|
8
|
+
icon: CircleX
|
|
9
|
+
},
|
|
10
|
+
401: {
|
|
11
|
+
description: "Unauthorized",
|
|
12
|
+
color: "text-red-500",
|
|
13
|
+
icon: CircleX
|
|
14
|
+
},
|
|
15
|
+
403: {
|
|
16
|
+
description: "Forbidden",
|
|
17
|
+
color: "text-red-500",
|
|
18
|
+
icon: CircleX
|
|
19
|
+
},
|
|
20
|
+
404: {
|
|
21
|
+
description: "Not Found",
|
|
22
|
+
color: "text-fd-muted-foreground",
|
|
23
|
+
icon: CircleX
|
|
24
|
+
},
|
|
25
|
+
500: {
|
|
26
|
+
description: "Internal Server Error",
|
|
27
|
+
color: "text-red-500",
|
|
28
|
+
icon: CircleX
|
|
29
|
+
}
|
|
20
30
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
icon: CircleX,
|
|
39
|
-
};
|
|
31
|
+
function getStatusInfo(status) {
|
|
32
|
+
if (status in statusMap) return statusMap[status];
|
|
33
|
+
if (status >= 200 && status < 300) return {
|
|
34
|
+
description: "Successful",
|
|
35
|
+
color: "text-green-500",
|
|
36
|
+
icon: CircleCheck
|
|
37
|
+
};
|
|
38
|
+
if (status >= 400) return {
|
|
39
|
+
description: "Error",
|
|
40
|
+
color: "text-red-500",
|
|
41
|
+
icon: CircleX
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
description: "No Description",
|
|
45
|
+
color: "text-fd-muted-foreground",
|
|
46
|
+
icon: CircleX
|
|
47
|
+
};
|
|
40
48
|
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { getStatusInfo };
|
|
52
|
+
//# sourceMappingURL=status-info.js.map
|