@lukoweb/apitogo 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +37 -147
- package/dist/declarations/lib/ui/Command.d.ts +1 -1
- package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
- package/package.json +1 -1
- package/src/app/main.tsx +150 -150
- package/src/config/loader.ts +245 -245
- package/src/index.ts +33 -33
- package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
- package/src/lib/authentication/components/SignIn.tsx +46 -46
- package/src/lib/authentication/components/SignUp.tsx +48 -48
- package/src/lib/authentication/providers/clerk.tsx +224 -224
- package/src/lib/authentication/ui/AuthCard.tsx +7 -7
- package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
- package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
- package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
- package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
- package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
- package/src/lib/components/Autocomplete.tsx +123 -123
- package/src/lib/components/DeveloperHint.tsx +39 -35
- package/src/lib/components/Header.tsx +260 -260
- package/src/lib/components/Layout.tsx +53 -53
- package/src/lib/components/Main.tsx +51 -51
- package/src/lib/components/Mermaid.tsx +74 -70
- package/src/lib/components/MobileTopNavigation.tsx +276 -276
- package/src/lib/components/MultiSelect.tsx +86 -82
- package/src/lib/components/TopNavigation.tsx +103 -103
- package/src/lib/components/index.ts +26 -26
- package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
- package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
- package/src/lib/components/navigation/NavigationItem.tsx +181 -177
- package/src/lib/core/RouteGuard.tsx +193 -193
- package/src/lib/errors/ErrorMessage.tsx +50 -46
- package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
- package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
- package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
- package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
- package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
- package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
- package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
- package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
- package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
- package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
- package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
- package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
- package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
- package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
- package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
- package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
- package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
- package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
- package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
- package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
- package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
- package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
- package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
- package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
- package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
- package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
- package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
- package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
- package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
- package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
- package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
- package/src/lib/ui/ActionButton.tsx +21 -21
- package/src/lib/ui/Command.tsx +191 -191
- package/src/lib/util/MdxComponents.tsx +150 -150
- package/src/vite/config.ts +234 -231
- package/src/vite/dev-server.ts +291 -291
- package/src/vite/plugin-api-keys.ts +50 -50
- package/src/vite/plugin-api.ts +320 -318
- package/src/vite/plugin-auth.ts +38 -38
- package/src/vite/plugin-component.ts +45 -39
- package/src/vite/plugin-config.ts +75 -75
- package/src/vite/plugin-custom-pages.ts +36 -36
- package/src/vite/plugin-docs.ts +202 -202
- package/src/vite/plugin-markdown-export.ts +214 -214
- package/src/vite/plugin-mdx.ts +149 -149
- package/src/vite/plugin-navigation.ts +106 -106
- package/src/vite/plugin-search.ts +47 -47
- package/src/vite/plugin.ts +42 -42
- package/src/vite/prerender/prerender.ts +233 -233
|
@@ -1,299 +1,299 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "
|
|
10
|
-
import {
|
|
11
|
-
import { Markdown } from "../../../components/Markdown.js";
|
|
12
|
-
import type { SchemaObject } from "../../../oas/parser/index.js";
|
|
13
|
-
import { ConstValue } from "../components/ConstValue.js";
|
|
14
|
-
import { EnumValues } from "../components/EnumValues.js";
|
|
15
|
-
import { ParamInfos } from "../ParamInfos.js";
|
|
16
|
-
import { SchemaExampleAndDefault } from "./SchemaExampleAndDefault.js";
|
|
17
|
-
import { SchemaPropertyItem } from "./SchemaPropertyItem.js";
|
|
18
|
-
import { UnionView } from "./UnionView.js";
|
|
19
|
-
import { isArrayType, isBasicType } from "./utils.js";
|
|
20
|
-
|
|
21
|
-
const renderMarkdown = (content?: string) =>
|
|
22
|
-
content && (
|
|
23
|
-
<Markdown
|
|
24
|
-
className="text-sm leading-normal line-clamp-4"
|
|
25
|
-
content={content}
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const renderBasicSchema = (
|
|
30
|
-
schema: SchemaObject,
|
|
31
|
-
cardHeader?: React.ReactNode,
|
|
32
|
-
embedded?: boolean,
|
|
33
|
-
) => {
|
|
34
|
-
const content = (
|
|
35
|
-
<>
|
|
36
|
-
<span className="text-sm text-muted-foreground">
|
|
37
|
-
<ParamInfos schema={schema} />
|
|
38
|
-
</span>
|
|
39
|
-
{schema.enum && <EnumValues values={schema.enum} />}
|
|
40
|
-
{renderMarkdown(schema.description)}
|
|
41
|
-
<SchemaExampleAndDefault schema={schema} />
|
|
42
|
-
</>
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (embedded) {
|
|
46
|
-
return <div className="space-y-2 p-4">{content}</div>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<Frame>
|
|
51
|
-
{cardHeader}
|
|
52
|
-
<FramePanel className="space-y-2">{content}</FramePanel>
|
|
53
|
-
</Frame>
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const PropertyGroup = ({
|
|
58
|
-
properties,
|
|
59
|
-
group,
|
|
60
|
-
defaultOpen,
|
|
61
|
-
}: {
|
|
62
|
-
properties: [string, SchemaObject][];
|
|
63
|
-
group: "required" | "optional" | "deprecated";
|
|
64
|
-
defaultOpen: boolean;
|
|
65
|
-
}) => (
|
|
66
|
-
<ItemGroup className="overflow-clip">
|
|
67
|
-
{properties.map(([name, schema], index) => (
|
|
68
|
-
<Fragment key={name}>
|
|
69
|
-
{index > 0 && <ItemSeparator />}
|
|
70
|
-
<SchemaPropertyItem
|
|
71
|
-
name={name}
|
|
72
|
-
schema={schema}
|
|
73
|
-
group={group}
|
|
74
|
-
defaultOpen={defaultOpen}
|
|
75
|
-
/>
|
|
76
|
-
</Fragment>
|
|
77
|
-
))}
|
|
78
|
-
</ItemGroup>
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const DeprecatedToggle = ({
|
|
82
|
-
count,
|
|
83
|
-
showDeprecated,
|
|
84
|
-
onToggle,
|
|
85
|
-
controlsId,
|
|
86
|
-
}: {
|
|
87
|
-
count: number;
|
|
88
|
-
showDeprecated: boolean;
|
|
89
|
-
onToggle: () => void;
|
|
90
|
-
controlsId: string;
|
|
91
|
-
}) => (
|
|
92
|
-
<button
|
|
93
|
-
type="button"
|
|
94
|
-
onClick={onToggle}
|
|
95
|
-
aria-expanded={showDeprecated}
|
|
96
|
-
aria-controls={controlsId}
|
|
97
|
-
className="text-xs text-muted-foreground flex items-center gap-1.5 hover:text-foreground transition-colors cursor-pointer"
|
|
98
|
-
>
|
|
99
|
-
{showDeprecated ? <EyeOffIcon size={14} /> : <EyeIcon size={14} />}
|
|
100
|
-
{showDeprecated
|
|
101
|
-
? "Hide deprecated fields"
|
|
102
|
-
: `Show ${count} deprecated field${count !== 1 ? "s" : ""}`}
|
|
103
|
-
</button>
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const ObjectSchemaView = ({
|
|
107
|
-
schema,
|
|
108
|
-
defaultOpen,
|
|
109
|
-
cardHeader,
|
|
110
|
-
embedded,
|
|
111
|
-
}: {
|
|
112
|
-
schema: SchemaObject;
|
|
113
|
-
defaultOpen: boolean;
|
|
114
|
-
cardHeader?: React.ReactNode;
|
|
115
|
-
embedded?: boolean;
|
|
116
|
-
}) => {
|
|
117
|
-
const [showDeprecated, setShowDeprecated] = useState(false);
|
|
118
|
-
const deprecatedRef = useRef<HTMLDivElement>(null);
|
|
119
|
-
const deprecatedId = useId();
|
|
120
|
-
|
|
121
|
-
// Upgrade hidden → hidden="until-found" so browser Cmd+F can find text inside.
|
|
122
|
-
// Uses useLayoutEffect to set the attribute before paint, avoiding flash.
|
|
123
|
-
// Managed imperatively because React types don't support "until-found" value.
|
|
124
|
-
useLayoutEffect(() => {
|
|
125
|
-
const el = deprecatedRef.current;
|
|
126
|
-
if (!el) return;
|
|
127
|
-
|
|
128
|
-
if (!showDeprecated) {
|
|
129
|
-
el.setAttribute("hidden", "until-found");
|
|
130
|
-
} else {
|
|
131
|
-
el.removeAttribute("hidden");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const handler = () => setShowDeprecated(true);
|
|
135
|
-
el.addEventListener("beforematch", handler);
|
|
136
|
-
return () => el.removeEventListener("beforematch", handler);
|
|
137
|
-
}, [showDeprecated]);
|
|
138
|
-
|
|
139
|
-
const groupedProperties = Object.groupBy(
|
|
140
|
-
Object.entries(schema.properties ?? {}),
|
|
141
|
-
([propertyName, property]) => {
|
|
142
|
-
return property.deprecated
|
|
143
|
-
? "deprecated"
|
|
144
|
-
: schema.required?.includes(propertyName)
|
|
145
|
-
? "required"
|
|
146
|
-
: "optional";
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
const nonDeprecatedGroupNames = ["required", "optional"] as const;
|
|
151
|
-
const nonDeprecatedGroups = nonDeprecatedGroupNames.flatMap((group) => {
|
|
152
|
-
const properties = groupedProperties[group];
|
|
153
|
-
return properties ? { group, properties } : [];
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const deprecatedProperties = groupedProperties["deprecated"];
|
|
157
|
-
|
|
158
|
-
const additionalObjectProperties = typeof schema.additionalProperties ===
|
|
159
|
-
"object" && <SchemaView schema={schema.additionalProperties} embedded />;
|
|
160
|
-
|
|
161
|
-
const itemsList = nonDeprecatedGroups.map(({ group, properties }, index) => (
|
|
162
|
-
<Fragment key={group}>
|
|
163
|
-
{index > 0 && <ItemSeparator />}
|
|
164
|
-
<PropertyGroup
|
|
165
|
-
properties={properties}
|
|
166
|
-
group={group}
|
|
167
|
-
defaultOpen={defaultOpen}
|
|
168
|
-
/>
|
|
169
|
-
</Fragment>
|
|
170
|
-
));
|
|
171
|
-
|
|
172
|
-
const deprecatedList = deprecatedProperties && (
|
|
173
|
-
<>
|
|
174
|
-
{nonDeprecatedGroups.length > 0 && <ItemSeparator />}
|
|
175
|
-
<PropertyGroup
|
|
176
|
-
properties={deprecatedProperties}
|
|
177
|
-
group="deprecated"
|
|
178
|
-
defaultOpen={defaultOpen}
|
|
179
|
-
/>
|
|
180
|
-
</>
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
if (embedded) {
|
|
184
|
-
return (
|
|
185
|
-
<>
|
|
186
|
-
{itemsList}
|
|
187
|
-
{deprecatedList}
|
|
188
|
-
</>
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return (
|
|
193
|
-
<Frame>
|
|
194
|
-
{cardHeader}
|
|
195
|
-
{schema.description && (
|
|
196
|
-
<FrameHeader>
|
|
197
|
-
<FrameDescription>{schema.description}</FrameDescription>
|
|
198
|
-
</FrameHeader>
|
|
199
|
-
)}
|
|
200
|
-
{(nonDeprecatedGroups.length > 0 ||
|
|
201
|
-
deprecatedProperties ||
|
|
202
|
-
additionalObjectProperties) && (
|
|
203
|
-
<FramePanel className="p-0!">
|
|
204
|
-
{itemsList}
|
|
205
|
-
{deprecatedProperties && (
|
|
206
|
-
<div ref={deprecatedRef} id={deprecatedId} hidden={!showDeprecated}>
|
|
207
|
-
{deprecatedList}
|
|
208
|
-
</div>
|
|
209
|
-
)}
|
|
210
|
-
{additionalObjectProperties}
|
|
211
|
-
</FramePanel>
|
|
212
|
-
)}
|
|
213
|
-
{(schema.additionalProperties === true || deprecatedProperties) && (
|
|
214
|
-
<FrameFooter className="flex-row items-center justify-between">
|
|
215
|
-
{schema.additionalProperties === true ? (
|
|
216
|
-
<a
|
|
217
|
-
className="text-sm flex items-center gap-1 hover:underline"
|
|
218
|
-
href="https://swagger.io/docs/specification/v3_0/data-models/dictionaries/"
|
|
219
|
-
rel="noopener noreferrer"
|
|
220
|
-
target="_blank"
|
|
221
|
-
>
|
|
222
|
-
Additional properties are allowed
|
|
223
|
-
<InfoIcon size={14} />
|
|
224
|
-
</a>
|
|
225
|
-
) : (
|
|
226
|
-
<span />
|
|
227
|
-
)}
|
|
228
|
-
{deprecatedProperties && (
|
|
229
|
-
<DeprecatedToggle
|
|
230
|
-
count={deprecatedProperties.length}
|
|
231
|
-
showDeprecated={showDeprecated}
|
|
232
|
-
onToggle={() => setShowDeprecated(!showDeprecated)}
|
|
233
|
-
controlsId={deprecatedId}
|
|
234
|
-
/>
|
|
235
|
-
)}
|
|
236
|
-
</FrameFooter>
|
|
237
|
-
)}
|
|
238
|
-
</Frame>
|
|
239
|
-
);
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export const SchemaView = ({
|
|
243
|
-
schema,
|
|
244
|
-
defaultOpen = false,
|
|
245
|
-
cardHeader,
|
|
246
|
-
embedded,
|
|
247
|
-
}: {
|
|
248
|
-
schema?: SchemaObject | null;
|
|
249
|
-
defaultOpen?: boolean;
|
|
250
|
-
cardHeader?: React.ReactNode;
|
|
251
|
-
embedded?: boolean;
|
|
252
|
-
}) => {
|
|
253
|
-
if (!schema || Object.keys(schema).length === 0) {
|
|
254
|
-
return (
|
|
255
|
-
<Frame>
|
|
256
|
-
{cardHeader}
|
|
257
|
-
<FramePanel>
|
|
258
|
-
<div className="text-sm text-muted-foreground italic">
|
|
259
|
-
No data returned
|
|
260
|
-
</div>
|
|
261
|
-
</FramePanel>
|
|
262
|
-
</Frame>
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (schema.const) {
|
|
267
|
-
return <ConstValue schema={schema} />;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (Array.isArray(schema.oneOf) || Array.isArray(schema.anyOf)) {
|
|
271
|
-
return <UnionView schema={schema} cardHeader={cardHeader} />;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (isBasicType(schema.type)) {
|
|
275
|
-
return renderBasicSchema(schema, cardHeader, embedded);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (isArrayType(schema) && typeof schema.items === "object") {
|
|
279
|
-
const wrappedSchema: SchemaObject = {
|
|
280
|
-
type: "object",
|
|
281
|
-
properties: { "": schema },
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
return (
|
|
285
|
-
<SchemaView schema={wrappedSchema} cardHeader={cardHeader} defaultOpen />
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (schema.type === "object") {
|
|
290
|
-
return (
|
|
291
|
-
<ObjectSchemaView
|
|
292
|
-
schema={schema}
|
|
293
|
-
defaultOpen={defaultOpen}
|
|
294
|
-
cardHeader={cardHeader}
|
|
295
|
-
embedded={embedded}
|
|
296
|
-
/>
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Frame,
|
|
3
|
+
FrameDescription,
|
|
4
|
+
FrameFooter,
|
|
5
|
+
FrameHeader,
|
|
6
|
+
FramePanel,
|
|
7
|
+
} from "@lukoweb/apitogo/ui/Frame.js";
|
|
8
|
+
import { ItemGroup, ItemSeparator } from "@lukoweb/apitogo/ui/Item.js";
|
|
9
|
+
import { EyeIcon, EyeOffIcon, InfoIcon } from "lucide-react";
|
|
10
|
+
import { Fragment, useId, useLayoutEffect, useRef, useState } from "react";
|
|
11
|
+
import { Markdown } from "../../../components/Markdown.js";
|
|
12
|
+
import type { SchemaObject } from "../../../oas/parser/index.js";
|
|
13
|
+
import { ConstValue } from "../components/ConstValue.js";
|
|
14
|
+
import { EnumValues } from "../components/EnumValues.js";
|
|
15
|
+
import { ParamInfos } from "../ParamInfos.js";
|
|
16
|
+
import { SchemaExampleAndDefault } from "./SchemaExampleAndDefault.js";
|
|
17
|
+
import { SchemaPropertyItem } from "./SchemaPropertyItem.js";
|
|
18
|
+
import { UnionView } from "./UnionView.js";
|
|
19
|
+
import { isArrayType, isBasicType } from "./utils.js";
|
|
20
|
+
|
|
21
|
+
const renderMarkdown = (content?: string) =>
|
|
22
|
+
content && (
|
|
23
|
+
<Markdown
|
|
24
|
+
className="text-sm leading-normal line-clamp-4"
|
|
25
|
+
content={content}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const renderBasicSchema = (
|
|
30
|
+
schema: SchemaObject,
|
|
31
|
+
cardHeader?: React.ReactNode,
|
|
32
|
+
embedded?: boolean,
|
|
33
|
+
) => {
|
|
34
|
+
const content = (
|
|
35
|
+
<>
|
|
36
|
+
<span className="text-sm text-muted-foreground">
|
|
37
|
+
<ParamInfos schema={schema} />
|
|
38
|
+
</span>
|
|
39
|
+
{schema.enum && <EnumValues values={schema.enum} />}
|
|
40
|
+
{renderMarkdown(schema.description)}
|
|
41
|
+
<SchemaExampleAndDefault schema={schema} />
|
|
42
|
+
</>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (embedded) {
|
|
46
|
+
return <div className="space-y-2 p-4">{content}</div>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Frame>
|
|
51
|
+
{cardHeader}
|
|
52
|
+
<FramePanel className="space-y-2">{content}</FramePanel>
|
|
53
|
+
</Frame>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const PropertyGroup = ({
|
|
58
|
+
properties,
|
|
59
|
+
group,
|
|
60
|
+
defaultOpen,
|
|
61
|
+
}: {
|
|
62
|
+
properties: [string, SchemaObject][];
|
|
63
|
+
group: "required" | "optional" | "deprecated";
|
|
64
|
+
defaultOpen: boolean;
|
|
65
|
+
}) => (
|
|
66
|
+
<ItemGroup className="overflow-clip">
|
|
67
|
+
{properties.map(([name, schema], index) => (
|
|
68
|
+
<Fragment key={name}>
|
|
69
|
+
{index > 0 && <ItemSeparator />}
|
|
70
|
+
<SchemaPropertyItem
|
|
71
|
+
name={name}
|
|
72
|
+
schema={schema}
|
|
73
|
+
group={group}
|
|
74
|
+
defaultOpen={defaultOpen}
|
|
75
|
+
/>
|
|
76
|
+
</Fragment>
|
|
77
|
+
))}
|
|
78
|
+
</ItemGroup>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const DeprecatedToggle = ({
|
|
82
|
+
count,
|
|
83
|
+
showDeprecated,
|
|
84
|
+
onToggle,
|
|
85
|
+
controlsId,
|
|
86
|
+
}: {
|
|
87
|
+
count: number;
|
|
88
|
+
showDeprecated: boolean;
|
|
89
|
+
onToggle: () => void;
|
|
90
|
+
controlsId: string;
|
|
91
|
+
}) => (
|
|
92
|
+
<button
|
|
93
|
+
type="button"
|
|
94
|
+
onClick={onToggle}
|
|
95
|
+
aria-expanded={showDeprecated}
|
|
96
|
+
aria-controls={controlsId}
|
|
97
|
+
className="text-xs text-muted-foreground flex items-center gap-1.5 hover:text-foreground transition-colors cursor-pointer"
|
|
98
|
+
>
|
|
99
|
+
{showDeprecated ? <EyeOffIcon size={14} /> : <EyeIcon size={14} />}
|
|
100
|
+
{showDeprecated
|
|
101
|
+
? "Hide deprecated fields"
|
|
102
|
+
: `Show ${count} deprecated field${count !== 1 ? "s" : ""}`}
|
|
103
|
+
</button>
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const ObjectSchemaView = ({
|
|
107
|
+
schema,
|
|
108
|
+
defaultOpen,
|
|
109
|
+
cardHeader,
|
|
110
|
+
embedded,
|
|
111
|
+
}: {
|
|
112
|
+
schema: SchemaObject;
|
|
113
|
+
defaultOpen: boolean;
|
|
114
|
+
cardHeader?: React.ReactNode;
|
|
115
|
+
embedded?: boolean;
|
|
116
|
+
}) => {
|
|
117
|
+
const [showDeprecated, setShowDeprecated] = useState(false);
|
|
118
|
+
const deprecatedRef = useRef<HTMLDivElement>(null);
|
|
119
|
+
const deprecatedId = useId();
|
|
120
|
+
|
|
121
|
+
// Upgrade hidden → hidden="until-found" so browser Cmd+F can find text inside.
|
|
122
|
+
// Uses useLayoutEffect to set the attribute before paint, avoiding flash.
|
|
123
|
+
// Managed imperatively because React types don't support "until-found" value.
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
const el = deprecatedRef.current;
|
|
126
|
+
if (!el) return;
|
|
127
|
+
|
|
128
|
+
if (!showDeprecated) {
|
|
129
|
+
el.setAttribute("hidden", "until-found");
|
|
130
|
+
} else {
|
|
131
|
+
el.removeAttribute("hidden");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const handler = () => setShowDeprecated(true);
|
|
135
|
+
el.addEventListener("beforematch", handler);
|
|
136
|
+
return () => el.removeEventListener("beforematch", handler);
|
|
137
|
+
}, [showDeprecated]);
|
|
138
|
+
|
|
139
|
+
const groupedProperties = Object.groupBy(
|
|
140
|
+
Object.entries(schema.properties ?? {}),
|
|
141
|
+
([propertyName, property]) => {
|
|
142
|
+
return property.deprecated
|
|
143
|
+
? "deprecated"
|
|
144
|
+
: schema.required?.includes(propertyName)
|
|
145
|
+
? "required"
|
|
146
|
+
: "optional";
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const nonDeprecatedGroupNames = ["required", "optional"] as const;
|
|
151
|
+
const nonDeprecatedGroups = nonDeprecatedGroupNames.flatMap((group) => {
|
|
152
|
+
const properties = groupedProperties[group];
|
|
153
|
+
return properties ? { group, properties } : [];
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const deprecatedProperties = groupedProperties["deprecated"];
|
|
157
|
+
|
|
158
|
+
const additionalObjectProperties = typeof schema.additionalProperties ===
|
|
159
|
+
"object" && <SchemaView schema={schema.additionalProperties} embedded />;
|
|
160
|
+
|
|
161
|
+
const itemsList = nonDeprecatedGroups.map(({ group, properties }, index) => (
|
|
162
|
+
<Fragment key={group}>
|
|
163
|
+
{index > 0 && <ItemSeparator />}
|
|
164
|
+
<PropertyGroup
|
|
165
|
+
properties={properties}
|
|
166
|
+
group={group}
|
|
167
|
+
defaultOpen={defaultOpen}
|
|
168
|
+
/>
|
|
169
|
+
</Fragment>
|
|
170
|
+
));
|
|
171
|
+
|
|
172
|
+
const deprecatedList = deprecatedProperties && (
|
|
173
|
+
<>
|
|
174
|
+
{nonDeprecatedGroups.length > 0 && <ItemSeparator />}
|
|
175
|
+
<PropertyGroup
|
|
176
|
+
properties={deprecatedProperties}
|
|
177
|
+
group="deprecated"
|
|
178
|
+
defaultOpen={defaultOpen}
|
|
179
|
+
/>
|
|
180
|
+
</>
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
if (embedded) {
|
|
184
|
+
return (
|
|
185
|
+
<>
|
|
186
|
+
{itemsList}
|
|
187
|
+
{deprecatedList}
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Frame>
|
|
194
|
+
{cardHeader}
|
|
195
|
+
{schema.description && (
|
|
196
|
+
<FrameHeader>
|
|
197
|
+
<FrameDescription>{schema.description}</FrameDescription>
|
|
198
|
+
</FrameHeader>
|
|
199
|
+
)}
|
|
200
|
+
{(nonDeprecatedGroups.length > 0 ||
|
|
201
|
+
deprecatedProperties ||
|
|
202
|
+
additionalObjectProperties) && (
|
|
203
|
+
<FramePanel className="p-0!">
|
|
204
|
+
{itemsList}
|
|
205
|
+
{deprecatedProperties && (
|
|
206
|
+
<div ref={deprecatedRef} id={deprecatedId} hidden={!showDeprecated}>
|
|
207
|
+
{deprecatedList}
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
{additionalObjectProperties}
|
|
211
|
+
</FramePanel>
|
|
212
|
+
)}
|
|
213
|
+
{(schema.additionalProperties === true || deprecatedProperties) && (
|
|
214
|
+
<FrameFooter className="flex-row items-center justify-between">
|
|
215
|
+
{schema.additionalProperties === true ? (
|
|
216
|
+
<a
|
|
217
|
+
className="text-sm flex items-center gap-1 hover:underline"
|
|
218
|
+
href="https://swagger.io/docs/specification/v3_0/data-models/dictionaries/"
|
|
219
|
+
rel="noopener noreferrer"
|
|
220
|
+
target="_blank"
|
|
221
|
+
>
|
|
222
|
+
Additional properties are allowed
|
|
223
|
+
<InfoIcon size={14} />
|
|
224
|
+
</a>
|
|
225
|
+
) : (
|
|
226
|
+
<span />
|
|
227
|
+
)}
|
|
228
|
+
{deprecatedProperties && (
|
|
229
|
+
<DeprecatedToggle
|
|
230
|
+
count={deprecatedProperties.length}
|
|
231
|
+
showDeprecated={showDeprecated}
|
|
232
|
+
onToggle={() => setShowDeprecated(!showDeprecated)}
|
|
233
|
+
controlsId={deprecatedId}
|
|
234
|
+
/>
|
|
235
|
+
)}
|
|
236
|
+
</FrameFooter>
|
|
237
|
+
)}
|
|
238
|
+
</Frame>
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export const SchemaView = ({
|
|
243
|
+
schema,
|
|
244
|
+
defaultOpen = false,
|
|
245
|
+
cardHeader,
|
|
246
|
+
embedded,
|
|
247
|
+
}: {
|
|
248
|
+
schema?: SchemaObject | null;
|
|
249
|
+
defaultOpen?: boolean;
|
|
250
|
+
cardHeader?: React.ReactNode;
|
|
251
|
+
embedded?: boolean;
|
|
252
|
+
}) => {
|
|
253
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
254
|
+
return (
|
|
255
|
+
<Frame>
|
|
256
|
+
{cardHeader}
|
|
257
|
+
<FramePanel>
|
|
258
|
+
<div className="text-sm text-muted-foreground italic">
|
|
259
|
+
No data returned
|
|
260
|
+
</div>
|
|
261
|
+
</FramePanel>
|
|
262
|
+
</Frame>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (schema.const) {
|
|
267
|
+
return <ConstValue schema={schema} />;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (Array.isArray(schema.oneOf) || Array.isArray(schema.anyOf)) {
|
|
271
|
+
return <UnionView schema={schema} cardHeader={cardHeader} />;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (isBasicType(schema.type)) {
|
|
275
|
+
return renderBasicSchema(schema, cardHeader, embedded);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (isArrayType(schema) && typeof schema.items === "object") {
|
|
279
|
+
const wrappedSchema: SchemaObject = {
|
|
280
|
+
type: "object",
|
|
281
|
+
properties: { "": schema },
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<SchemaView schema={wrappedSchema} cardHeader={cardHeader} defaultOpen />
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (schema.type === "object") {
|
|
290
|
+
return (
|
|
291
|
+
<ObjectSchemaView
|
|
292
|
+
schema={schema}
|
|
293
|
+
defaultOpen={defaultOpen}
|
|
294
|
+
cardHeader={cardHeader}
|
|
295
|
+
embedded={embedded}
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
};
|