zudoku 0.64.0 → 0.64.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/config/config.d.ts +15 -46
- package/dist/config/validators/InputNavigationSchema.d.ts +53 -53
- package/dist/config/validators/ProtectedRoutesSchema.d.ts +1 -1
- package/dist/config/validators/validate.d.ts +105 -1
- package/dist/config/validators/validate.js +30 -0
- package/dist/config/validators/validate.js.map +1 -1
- package/dist/flat-config.d.ts +16 -0
- package/dist/lib/auth/issuer.js +3 -0
- package/dist/lib/auth/issuer.js.map +1 -1
- package/dist/lib/authentication/authentication.d.ts +1 -1
- package/dist/lib/authentication/providers/firebase.d.ts +4 -0
- package/dist/lib/authentication/providers/firebase.js +215 -0
- package/dist/lib/authentication/providers/firebase.js.map +1 -0
- package/dist/lib/authentication/providers/supabase.js +1 -6
- package/dist/lib/authentication/providers/supabase.js.map +1 -1
- package/dist/lib/authentication/ui/ZudokuAuthUi.d.ts +24 -0
- package/dist/lib/authentication/ui/ZudokuAuthUi.js +124 -0
- package/dist/lib/authentication/ui/ZudokuAuthUi.js.map +1 -0
- package/dist/lib/authentication/ui/icons/Apple.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/Apple.js +4 -0
- package/dist/lib/authentication/ui/icons/Apple.js.map +1 -0
- package/dist/lib/authentication/ui/icons/Facebook.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/Facebook.js +4 -0
- package/dist/lib/authentication/ui/icons/Facebook.js.map +1 -0
- package/dist/lib/authentication/ui/icons/Github.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/Github.js +4 -0
- package/dist/lib/authentication/ui/icons/Github.js.map +1 -0
- package/dist/lib/authentication/ui/icons/Google.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/Google.js +4 -0
- package/dist/lib/authentication/ui/icons/Google.js.map +1 -0
- package/dist/lib/authentication/ui/icons/Microsoft.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/Microsoft.js +4 -0
- package/dist/lib/authentication/ui/icons/Microsoft.js.map +1 -0
- package/dist/lib/authentication/ui/icons/X.d.ts +3 -0
- package/dist/lib/authentication/ui/icons/X.js +4 -0
- package/dist/lib/authentication/ui/icons/X.js.map +1 -0
- package/dist/lib/components/Heading.d.ts +1 -1
- package/dist/lib/core/RouteGuard.js +6 -6
- package/dist/lib/core/RouteGuard.js.map +1 -1
- package/dist/lib/oas/parser/index.js +7 -3
- package/dist/lib/oas/parser/index.js.map +1 -1
- package/dist/lib/plugins/api-keys/ProtectedRoute.js +4 -1
- package/dist/lib/plugins/api-keys/ProtectedRoute.js.map +1 -1
- package/dist/lib/plugins/openapi/CollapsibleCode.d.ts +1 -0
- package/dist/lib/plugins/openapi/CollapsibleCode.js +2 -1
- package/dist/lib/plugins/openapi/CollapsibleCode.js.map +1 -1
- package/dist/lib/plugins/openapi/GeneratedExampleSidecarBox.d.ts +5 -0
- package/dist/lib/plugins/openapi/GeneratedExampleSidecarBox.js +10 -0
- package/dist/lib/plugins/openapi/GeneratedExampleSidecarBox.js.map +1 -0
- package/dist/lib/plugins/openapi/OperationList.js +4 -1
- package/dist/lib/plugins/openapi/OperationList.js.map +1 -1
- package/dist/lib/plugins/openapi/OperationListItem.d.ts +2 -1
- package/dist/lib/plugins/openapi/OperationListItem.js +2 -2
- package/dist/lib/plugins/openapi/OperationListItem.js.map +1 -1
- package/dist/lib/plugins/openapi/RequestBodySidecarBox.d.ts +9 -2
- package/dist/lib/plugins/openapi/RequestBodySidecarBox.js +2 -2
- package/dist/lib/plugins/openapi/RequestBodySidecarBox.js.map +1 -1
- package/dist/lib/plugins/openapi/ResponsesSidecarBox.d.ts +3 -1
- package/dist/lib/plugins/openapi/ResponsesSidecarBox.js +14 -2
- package/dist/lib/plugins/openapi/ResponsesSidecarBox.js.map +1 -1
- package/dist/lib/plugins/openapi/Sidecar.d.ts +2 -1
- package/dist/lib/plugins/openapi/Sidecar.js +33 -30
- package/dist/lib/plugins/openapi/Sidecar.js.map +1 -1
- package/dist/lib/plugins/openapi/SidecarExamples.d.ts +9 -2
- package/dist/lib/plugins/openapi/SidecarExamples.js +15 -33
- package/dist/lib/plugins/openapi/SidecarExamples.js.map +1 -1
- package/dist/lib/plugins/openapi/components/NonHighlightedCode.d.ts +4 -0
- package/dist/lib/plugins/openapi/components/NonHighlightedCode.js +5 -0
- package/dist/lib/plugins/openapi/components/NonHighlightedCode.js.map +1 -0
- package/dist/lib/plugins/openapi/components/ResponseContent.js +1 -1
- package/dist/lib/plugins/openapi/components/ResponseContent.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/InlineInput.d.ts +1 -1
- package/dist/lib/plugins/openapi/playground/ParamsGrid.d.ts +2 -2
- package/dist/lib/plugins/openapi/schema/SchemaPropertyItem.js +1 -2
- package/dist/lib/plugins/openapi/schema/SchemaPropertyItem.js.map +1 -1
- package/dist/lib/plugins/openapi/schema/SchemaView.js +0 -4
- package/dist/lib/plugins/openapi/schema/SchemaView.js.map +1 -1
- package/dist/lib/plugins/openapi/schema/union-helpers.js +0 -1
- package/dist/lib/plugins/openapi/schema/union-helpers.js.map +1 -1
- package/dist/lib/plugins/openapi/util/generateSchemaExample.js +9 -11
- package/dist/lib/plugins/openapi/util/generateSchemaExample.js.map +1 -1
- package/dist/lib/ui/CodeBlock.d.ts +0 -1
- package/dist/lib/ui/CodeBlock.js.map +1 -1
- package/dist/lib/ui/Command.d.ts +3 -3
- package/dist/lib/ui/EmbeddedCodeBlock.d.ts +0 -1
- package/dist/lib/ui/EmbeddedCodeBlock.js +1 -1
- package/dist/lib/ui/EmbeddedCodeBlock.js.map +1 -1
- package/dist/lib/ui/Separator.d.ts +4 -0
- package/dist/lib/ui/Separator.js +8 -0
- package/dist/lib/ui/Separator.js.map +1 -0
- package/dist/lib/ui/Tooltip.d.ts +7 -7
- package/dist/lib/ui/Tooltip.js +16 -10
- package/dist/lib/ui/Tooltip.js.map +1 -1
- package/dist/lib/util/createVariantComponent.d.ts +5 -2
- package/dist/lib/util/createVariantComponent.js +5 -2
- package/dist/lib/util/createVariantComponent.js.map +1 -1
- package/dist/lib/util/flattenAllOf.d.ts +4 -0
- package/dist/lib/util/flattenAllOf.js +65 -0
- package/dist/lib/util/flattenAllOf.js.map +1 -0
- package/dist/lib/util/flattenAllOf.test.d.ts +1 -0
- package/dist/lib/util/flattenAllOf.test.js +532 -0
- package/dist/lib/util/flattenAllOf.test.js.map +1 -0
- package/dist/vite/api/SchemaManager.js +6 -18
- package/dist/vite/api/SchemaManager.js.map +1 -1
- package/dist/vite/plugin-theme.js +10 -1
- package/dist/vite/plugin-theme.js.map +1 -1
- package/lib/{ErrorAlert-DE3Sf66a.js → ErrorAlert--3alJ_-b.js} +1340 -1311
- package/lib/{ErrorAlert-DE3Sf66a.js.map → ErrorAlert--3alJ_-b.js.map} +1 -1
- package/lib/{MdxPage-DZfeC0QY.js → MdxPage-Bpa9tL63.js} +5 -5
- package/lib/{MdxPage-DZfeC0QY.js.map → MdxPage-Bpa9tL63.js.map} +1 -1
- package/lib/{OAuthErrorPage-BycMozgn.js → OAuthErrorPage-B79J86Fo.js} +4 -4
- package/lib/{OAuthErrorPage-BycMozgn.js.map → OAuthErrorPage-B79J86Fo.js.map} +1 -1
- package/lib/{OasProvider-Bf5zBDBY.js → OasProvider-jr0oDSFy.js} +2 -2
- package/lib/{OasProvider-Bf5zBDBY.js.map → OasProvider-jr0oDSFy.js.map} +1 -1
- package/lib/OperationList-DLEAg4qw.js +5465 -0
- package/lib/OperationList-DLEAg4qw.js.map +1 -0
- package/lib/{Pagination-CJszmeSA.js → Pagination-H2HW9-Er.js} +2 -2
- package/lib/{Pagination-CJszmeSA.js.map → Pagination-H2HW9-Er.js.map} +1 -1
- package/lib/RouteGuard-CjzxosTf.js +77 -0
- package/lib/RouteGuard-CjzxosTf.js.map +1 -0
- package/lib/{RouterError-VDLnrFqF.js → RouterError-DZS2d6Sc.js} +2 -2
- package/lib/{RouterError-VDLnrFqF.js.map → RouterError-DZS2d6Sc.js.map} +1 -1
- package/lib/{SchemaList-xZSf3IMh.js → SchemaList-CSDSazqV.js} +6 -6
- package/lib/{SchemaList-xZSf3IMh.js.map → SchemaList-CSDSazqV.js.map} +1 -1
- package/lib/SchemaView-DJiBd0_5.js +397 -0
- package/lib/SchemaView-DJiBd0_5.js.map +1 -0
- package/lib/{SignUp-6SGx9Yyq.js → SignUp-Fycafbyg.js} +2 -2
- package/lib/{SignUp-6SGx9Yyq.js.map → SignUp-Fycafbyg.js.map} +1 -1
- package/lib/{SyntaxHighlight-zvlnSnHB.js → SyntaxHighlight-C19vH0V_.js} +525 -509
- package/lib/SyntaxHighlight-C19vH0V_.js.map +1 -0
- package/lib/{Toc-Da9yp7lo.js → Toc-ChkOg2UU.js} +2 -2
- package/lib/{Toc-Da9yp7lo.js.map → Toc-ChkOg2UU.js.map} +1 -1
- package/lib/{circular-DvuimBGQ.js → circular-DGfd8SGc.js} +2 -2
- package/lib/{circular-DvuimBGQ.js.map → circular-DGfd8SGc.js.map} +1 -1
- package/lib/{createServer-D9UvCoDf.js → createServer-DGD8hEzT.js} +4662 -4238
- package/lib/createServer-DGD8hEzT.js.map +1 -0
- package/lib/{errors-CuGgh3hf.js → errors-BTpjwHS6.js} +2 -2
- package/lib/{errors-CuGgh3hf.js.map → errors-BTpjwHS6.js.map} +1 -1
- package/lib/{index-rYHsvtTo.js → index-Bvas0H4x.js} +2 -2
- package/lib/{index-rYHsvtTo.js.map → index-Bvas0H4x.js.map} +1 -1
- package/lib/{index-Cr9_YzOZ.js → index-DP1xZgfJ.js} +9 -9
- package/lib/index-DP1xZgfJ.js.map +1 -0
- package/lib/{index-B1rmok4X.js → index-FNRZUtwo.js} +2 -2
- package/lib/{index-B1rmok4X.js.map → index-FNRZUtwo.js.map} +1 -1
- package/lib/ui/CodeBlock.js.map +1 -1
- package/lib/ui/EmbeddedCodeBlock.js +9 -9
- package/lib/ui/EmbeddedCodeBlock.js.map +1 -1
- package/lib/ui/Separator.js +27 -0
- package/lib/ui/Separator.js.map +1 -0
- package/lib/ui/SyntaxHighlight.js +1 -1
- package/lib/ui/Tooltip.js +55 -28
- package/lib/ui/Tooltip.js.map +1 -1
- package/lib/zudoku.__internal.js +4 -4
- package/lib/zudoku.auth-azureb2c.js +3 -3
- package/lib/zudoku.auth-clerk.js +1 -1
- package/lib/zudoku.auth-openid.js +3 -3
- package/lib/zudoku.auth-supabase.js +30 -33
- package/lib/zudoku.auth-supabase.js.map +1 -1
- package/lib/zudoku.components.js +2 -2
- package/lib/zudoku.plugin-api-catalog.js +3 -3
- package/lib/zudoku.plugin-api-keys.js +3 -3
- package/lib/zudoku.plugin-api-keys.js.map +1 -1
- package/lib/zudoku.plugin-markdown.js +1 -1
- package/lib/zudoku.plugin-openapi.js +1 -1
- package/lib/zudoku.plugin-search-pagefind.js +1 -1
- package/package.json +16 -11
- package/src/app/main.css +1 -1
- package/src/lib/auth/issuer.ts +3 -0
- package/src/lib/authentication/authentication.ts +1 -1
- package/src/lib/authentication/providers/firebase.tsx +284 -0
- package/src/lib/authentication/providers/supabase.tsx +2 -7
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +335 -0
- package/src/lib/authentication/ui/icons/Apple.tsx +10 -0
- package/src/lib/authentication/ui/icons/Facebook.tsx +15 -0
- package/src/lib/authentication/ui/icons/Github.tsx +16 -0
- package/src/lib/authentication/ui/icons/Google.tsx +16 -0
- package/src/lib/authentication/ui/icons/Microsoft.tsx +12 -0
- package/src/lib/authentication/ui/icons/X.tsx +10 -0
- package/src/lib/core/RouteGuard.tsx +8 -8
- package/src/lib/oas/parser/index.ts +8 -3
- package/src/lib/plugins/api-keys/ProtectedRoute.tsx +11 -7
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +5 -3
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -0
- package/src/lib/plugins/openapi/OperationList.tsx +5 -0
- package/src/lib/plugins/openapi/OperationListItem.tsx +3 -0
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +20 -2
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +26 -1
- package/src/lib/plugins/openapi/Sidecar.tsx +84 -63
- package/src/lib/plugins/openapi/SidecarExamples.tsx +38 -48
- package/src/lib/plugins/openapi/components/NonHighlightedCode.tsx +22 -0
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +1 -1
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +1 -4
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +0 -5
- package/src/lib/plugins/openapi/schema/union-helpers.ts +0 -1
- package/src/lib/plugins/openapi/util/generateSchemaExample.ts +11 -11
- package/src/lib/ui/CodeBlock.tsx +0 -1
- package/src/lib/ui/EmbeddedCodeBlock.tsx +1 -2
- package/src/lib/ui/Separator.tsx +25 -0
- package/src/lib/ui/Tooltip.tsx +54 -32
- package/src/lib/util/createVariantComponent.tsx +31 -5
- package/src/lib/util/flattenAllOf.test.ts +637 -0
- package/src/lib/util/flattenAllOf.ts +101 -0
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupConnector.d.ts +0 -5
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupConnector.js +0 -7
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupConnector.js.map +0 -1
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupItem.d.ts +0 -4
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupItem.js +0 -10
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupItem.js.map +0 -1
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupView.d.ts +0 -5
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupView.js +0 -16
- package/dist/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupView.js.map +0 -1
- package/lib/OperationList-Cmiw1xm2.js +0 -5446
- package/lib/OperationList-Cmiw1xm2.js.map +0 -1
- package/lib/RouteGuard-DhU3LRr1.js +0 -81
- package/lib/RouteGuard-DhU3LRr1.js.map +0 -1
- package/lib/SchemaView-tHXTm5oM.js +0 -458
- package/lib/SchemaView-tHXTm5oM.js.map +0 -1
- package/lib/SyntaxHighlight-zvlnSnHB.js.map +0 -1
- package/lib/createServer-D9UvCoDf.js.map +0 -1
- package/lib/index-Cr9_YzOZ.js.map +0 -1
- package/src/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupConnector.tsx +0 -36
- package/src/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupItem.tsx +0 -25
- package/src/lib/plugins/openapi/schema/AllOfGroup/AllOfGroupView.tsx +0 -42
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
import type { JSONSchema7 } from "json-schema";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import type { OpenAPIDocument } from "../oas/parser/index.js";
|
|
4
|
+
import { flattenAllOf, flattenAllOfProcessor } from "./flattenAllOf.js";
|
|
5
|
+
import invariant from "./invariant.js";
|
|
6
|
+
|
|
7
|
+
describe("flattenAllOf", () => {
|
|
8
|
+
it("should merge two simple schemas", () => {
|
|
9
|
+
const schema = {
|
|
10
|
+
allOf: [
|
|
11
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
12
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
13
|
+
],
|
|
14
|
+
} as JSONSchema7;
|
|
15
|
+
|
|
16
|
+
const result = flattenAllOf(schema);
|
|
17
|
+
|
|
18
|
+
expect(result).toMatchObject({
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
id: { type: "string" },
|
|
22
|
+
name: { type: "string" },
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
expect(result).not.toHaveProperty("allOf");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should merge nested allOf chains", () => {
|
|
29
|
+
const schema = {
|
|
30
|
+
allOf: [
|
|
31
|
+
{
|
|
32
|
+
allOf: [
|
|
33
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
34
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{ type: "object", properties: { email: { type: "string" } } },
|
|
38
|
+
],
|
|
39
|
+
} as JSONSchema7;
|
|
40
|
+
|
|
41
|
+
const result = flattenAllOf(schema);
|
|
42
|
+
|
|
43
|
+
expect(result).toMatchObject({
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: {
|
|
46
|
+
id: { type: "string" },
|
|
47
|
+
name: { type: "string" },
|
|
48
|
+
email: { type: "string" },
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
expect(result).not.toHaveProperty("allOf");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should recursively flatten allOf in nested properties", () => {
|
|
55
|
+
const schema = {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
user: {
|
|
59
|
+
allOf: [
|
|
60
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
61
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
} as JSONSchema7;
|
|
66
|
+
|
|
67
|
+
const result = flattenAllOf(schema);
|
|
68
|
+
|
|
69
|
+
invariant(
|
|
70
|
+
typeof result === "object" && result.properties,
|
|
71
|
+
"Result is not a schema",
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(result.properties?.user).toMatchObject({
|
|
75
|
+
type: "object",
|
|
76
|
+
properties: {
|
|
77
|
+
id: { type: "string" },
|
|
78
|
+
name: { type: "string" },
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(result.properties.user).not.toHaveProperty("allOf");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should flatten allOf in array items", () => {
|
|
85
|
+
const schema = {
|
|
86
|
+
type: "array",
|
|
87
|
+
items: {
|
|
88
|
+
allOf: [
|
|
89
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
90
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
} as JSONSchema7;
|
|
94
|
+
|
|
95
|
+
const result = flattenAllOf(schema);
|
|
96
|
+
|
|
97
|
+
invariant(
|
|
98
|
+
typeof result === "object" && result.items,
|
|
99
|
+
"Result is not a schema",
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
expect(result.items).toMatchObject({
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: {
|
|
105
|
+
id: { type: "string" },
|
|
106
|
+
name: { type: "string" },
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
expect(result.items).not.toHaveProperty("allOf");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should flatten allOf in tuple items", () => {
|
|
113
|
+
const schema = {
|
|
114
|
+
type: "array",
|
|
115
|
+
items: [
|
|
116
|
+
{
|
|
117
|
+
allOf: [
|
|
118
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
119
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{ type: "string" },
|
|
123
|
+
],
|
|
124
|
+
} as JSONSchema7;
|
|
125
|
+
|
|
126
|
+
const result = flattenAllOf(schema);
|
|
127
|
+
|
|
128
|
+
invariant(
|
|
129
|
+
typeof result === "object" && Array.isArray(result.items),
|
|
130
|
+
"Result is not a schema",
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(result.items[0]).toMatchObject({
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
id: { type: "string" },
|
|
137
|
+
name: { type: "string" },
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
expect(result.items[0]).not.toHaveProperty("allOf");
|
|
141
|
+
expect(result.items[1]).toEqual({ type: "string" });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should flatten allOf in additionalProperties", () => {
|
|
145
|
+
const schema = {
|
|
146
|
+
type: "object",
|
|
147
|
+
additionalProperties: {
|
|
148
|
+
allOf: [
|
|
149
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
150
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
} as JSONSchema7;
|
|
154
|
+
|
|
155
|
+
const result = flattenAllOf(schema);
|
|
156
|
+
|
|
157
|
+
invariant(
|
|
158
|
+
typeof result === "object" && result.additionalProperties,
|
|
159
|
+
"Result is not a schema",
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
expect(result.additionalProperties as JSONSchema7).toMatchObject({
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
id: { type: "string" },
|
|
166
|
+
name: { type: "string" },
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
expect(result.additionalProperties).not.toHaveProperty("allOf");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should flatten allOf within anyOf", () => {
|
|
173
|
+
const schema = {
|
|
174
|
+
anyOf: [
|
|
175
|
+
{
|
|
176
|
+
allOf: [
|
|
177
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
178
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
{ type: "string" },
|
|
182
|
+
],
|
|
183
|
+
} as JSONSchema7;
|
|
184
|
+
|
|
185
|
+
const result = flattenAllOf(schema);
|
|
186
|
+
|
|
187
|
+
invariant(
|
|
188
|
+
typeof result === "object" && result.anyOf,
|
|
189
|
+
"Result is not a schema",
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(result.anyOf[0]).toMatchObject({
|
|
193
|
+
type: "object",
|
|
194
|
+
properties: {
|
|
195
|
+
id: { type: "string" },
|
|
196
|
+
name: { type: "string" },
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
expect(result.anyOf[0]).not.toHaveProperty("allOf");
|
|
200
|
+
expect(result.anyOf[1]).toEqual({ type: "string" });
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("should flatten allOf within oneOf", () => {
|
|
204
|
+
const schema = {
|
|
205
|
+
oneOf: [
|
|
206
|
+
{
|
|
207
|
+
allOf: [
|
|
208
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
209
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
{ type: "string" },
|
|
213
|
+
],
|
|
214
|
+
} as JSONSchema7;
|
|
215
|
+
|
|
216
|
+
const result = flattenAllOf(schema);
|
|
217
|
+
|
|
218
|
+
invariant(
|
|
219
|
+
typeof result === "object" && result.oneOf,
|
|
220
|
+
"Result is not a schema",
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
expect(result.oneOf[0]).toMatchObject({
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
id: { type: "string" },
|
|
227
|
+
name: { type: "string" },
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
expect(result.oneOf[0]).not.toHaveProperty("allOf");
|
|
231
|
+
expect(result.oneOf[1]).toEqual({ type: "string" });
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should handle schemas without allOf", () => {
|
|
235
|
+
const schema = { type: "string" } as JSONSchema7;
|
|
236
|
+
expect(flattenAllOf(schema)).toEqual({ type: "string" });
|
|
237
|
+
|
|
238
|
+
const objectSchema = {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: { id: { type: "string" } },
|
|
241
|
+
} as JSONSchema7;
|
|
242
|
+
expect(flattenAllOf(objectSchema)).toEqual(objectSchema);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("should preserve description and other properties", () => {
|
|
246
|
+
const schema = {
|
|
247
|
+
description: "A test schema",
|
|
248
|
+
allOf: [
|
|
249
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
250
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
251
|
+
],
|
|
252
|
+
} as JSONSchema7;
|
|
253
|
+
|
|
254
|
+
const result = flattenAllOf(schema);
|
|
255
|
+
|
|
256
|
+
invariant(typeof result === "object", "Result is not a schema");
|
|
257
|
+
|
|
258
|
+
expect(result.description).toBe("A test schema");
|
|
259
|
+
expect(result.properties).toBeDefined();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should merge required arrays", () => {
|
|
263
|
+
const schema = {
|
|
264
|
+
allOf: [
|
|
265
|
+
{
|
|
266
|
+
type: "object",
|
|
267
|
+
properties: { id: { type: "string" } },
|
|
268
|
+
required: ["id"],
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
type: "object",
|
|
272
|
+
properties: { name: { type: "string" } },
|
|
273
|
+
required: ["name"],
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
} as JSONSchema7;
|
|
277
|
+
|
|
278
|
+
const result = flattenAllOf(schema);
|
|
279
|
+
|
|
280
|
+
invariant(typeof result === "object", "Result is not a schema");
|
|
281
|
+
|
|
282
|
+
expect(result.required).toEqual(expect.arrayContaining(["id", "name"]));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("should handle complex nested structures", () => {
|
|
286
|
+
const schema = {
|
|
287
|
+
type: "object",
|
|
288
|
+
properties: {
|
|
289
|
+
booking: {
|
|
290
|
+
allOf: [
|
|
291
|
+
{
|
|
292
|
+
allOf: [
|
|
293
|
+
{
|
|
294
|
+
type: "object",
|
|
295
|
+
properties: { quoteId: { type: "string" } },
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
type: "object",
|
|
299
|
+
properties: { price: { type: "number" } },
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
type: "object",
|
|
305
|
+
properties: { bookingId: { type: "string" } },
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
} as JSONSchema7;
|
|
311
|
+
|
|
312
|
+
const result = flattenAllOf(schema);
|
|
313
|
+
|
|
314
|
+
invariant(
|
|
315
|
+
typeof result === "object" && result.properties,
|
|
316
|
+
"Result is not a schema",
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
expect(result.properties.booking).toMatchObject({
|
|
320
|
+
type: "object",
|
|
321
|
+
properties: {
|
|
322
|
+
quoteId: { type: "string" },
|
|
323
|
+
price: { type: "number" },
|
|
324
|
+
bookingId: { type: "string" },
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
expect(result.properties.booking).not.toHaveProperty("allOf");
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
describe("flattenAllOf processor", () => {
|
|
332
|
+
it("should process an OpenAPI document and flatten allOf", async () => {
|
|
333
|
+
const schema: OpenAPIDocument = {
|
|
334
|
+
openapi: "3.0.0",
|
|
335
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
336
|
+
paths: {
|
|
337
|
+
"/users": {
|
|
338
|
+
get: {
|
|
339
|
+
responses: {
|
|
340
|
+
"200": {
|
|
341
|
+
description: "Success",
|
|
342
|
+
content: {
|
|
343
|
+
"application/json": {
|
|
344
|
+
schema: {
|
|
345
|
+
allOf: [
|
|
346
|
+
{
|
|
347
|
+
type: "object",
|
|
348
|
+
properties: { id: { type: "string" } },
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
type: "object",
|
|
352
|
+
properties: { name: { type: "string" } },
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const mockDereference = vi.fn().mockResolvedValue(schema);
|
|
366
|
+
|
|
367
|
+
const result = await flattenAllOfProcessor({
|
|
368
|
+
schema,
|
|
369
|
+
file: "/test/schema.json",
|
|
370
|
+
dereference: mockDereference,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
expect(mockDereference).toHaveBeenCalledWith(schema);
|
|
374
|
+
|
|
375
|
+
const responseSchema =
|
|
376
|
+
result.paths?.["/users"]?.get?.responses?.[200]?.content?.[
|
|
377
|
+
"application/json"
|
|
378
|
+
]?.schema;
|
|
379
|
+
|
|
380
|
+
expect(responseSchema).toMatchObject({
|
|
381
|
+
type: "object",
|
|
382
|
+
properties: {
|
|
383
|
+
id: { type: "string" },
|
|
384
|
+
name: { type: "string" },
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
expect(responseSchema).not.toHaveProperty("allOf");
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("should process components.schemas and flatten allOf", async () => {
|
|
391
|
+
const schema: OpenAPIDocument = {
|
|
392
|
+
openapi: "3.0.0",
|
|
393
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
394
|
+
paths: {},
|
|
395
|
+
components: {
|
|
396
|
+
schemas: {
|
|
397
|
+
User: {
|
|
398
|
+
allOf: [
|
|
399
|
+
{ type: "object", properties: { id: { type: "string" } } },
|
|
400
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
401
|
+
],
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const mockDereference = vi.fn().mockResolvedValue(schema);
|
|
408
|
+
|
|
409
|
+
const result = await flattenAllOfProcessor({
|
|
410
|
+
schema,
|
|
411
|
+
file: "/test/schema.json",
|
|
412
|
+
dereference: mockDereference,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const userSchema = result.components?.schemas?.User;
|
|
416
|
+
expect(userSchema).toMatchObject({
|
|
417
|
+
type: "object",
|
|
418
|
+
properties: {
|
|
419
|
+
id: { type: "string" },
|
|
420
|
+
name: { type: "string" },
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
expect(userSchema).not.toHaveProperty("allOf");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("should handle errors gracefully and return original schema", async () => {
|
|
427
|
+
const schema: OpenAPIDocument = {
|
|
428
|
+
openapi: "3.0.0",
|
|
429
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
430
|
+
paths: {},
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
const mockDereference = vi
|
|
434
|
+
.fn()
|
|
435
|
+
.mockRejectedValue(new Error("Dereference failed"));
|
|
436
|
+
|
|
437
|
+
const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
438
|
+
|
|
439
|
+
const result = await flattenAllOfProcessor({
|
|
440
|
+
schema,
|
|
441
|
+
file: "/test/schema.json",
|
|
442
|
+
dereference: mockDereference,
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
expect(result).toBe(schema);
|
|
446
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
447
|
+
expect.stringContaining("Failed to flatten"),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
consoleSpy.mockRestore();
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("should only flatten schema objects, not other OpenAPI structures", async () => {
|
|
454
|
+
const schema: OpenAPIDocument = {
|
|
455
|
+
openapi: "3.0.0",
|
|
456
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
457
|
+
paths: {
|
|
458
|
+
"/users": {
|
|
459
|
+
get: {
|
|
460
|
+
operationId: "getUsers",
|
|
461
|
+
tags: ["users"],
|
|
462
|
+
responses: {
|
|
463
|
+
"200": {
|
|
464
|
+
description: "Success",
|
|
465
|
+
content: {
|
|
466
|
+
"application/json": {
|
|
467
|
+
schema: {
|
|
468
|
+
allOf: [
|
|
469
|
+
{
|
|
470
|
+
type: "object",
|
|
471
|
+
properties: { id: { type: "string" } },
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
type: "object",
|
|
475
|
+
properties: { name: { type: "string" } },
|
|
476
|
+
},
|
|
477
|
+
],
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const mockDereference = vi.fn().mockResolvedValue(schema);
|
|
489
|
+
|
|
490
|
+
const result = await flattenAllOfProcessor({
|
|
491
|
+
schema,
|
|
492
|
+
file: "/test/schema.json",
|
|
493
|
+
dereference: mockDereference,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
// Operation objects should not be flattened
|
|
497
|
+
const operation = result.paths?.["/users"]?.get;
|
|
498
|
+
expect(operation?.operationId).toBe("getUsers");
|
|
499
|
+
expect(operation?.tags).toEqual(["users"]);
|
|
500
|
+
|
|
501
|
+
// But schema objects should be flattened
|
|
502
|
+
const responseSchema =
|
|
503
|
+
operation?.responses?.[200]?.content?.["application/json"]?.schema;
|
|
504
|
+
expect(responseSchema).not.toHaveProperty("allOf");
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("should handle deeply nested allOf in request bodies", async () => {
|
|
508
|
+
const schema: OpenAPIDocument = {
|
|
509
|
+
openapi: "3.0.0",
|
|
510
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
511
|
+
paths: {
|
|
512
|
+
"/bookings": {
|
|
513
|
+
post: {
|
|
514
|
+
requestBody: {
|
|
515
|
+
content: {
|
|
516
|
+
"application/json": {
|
|
517
|
+
schema: {
|
|
518
|
+
allOf: [
|
|
519
|
+
{
|
|
520
|
+
allOf: [
|
|
521
|
+
{
|
|
522
|
+
type: "object",
|
|
523
|
+
properties: { quoteId: { type: "string" } },
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
type: "object",
|
|
527
|
+
properties: { price: { type: "number" } },
|
|
528
|
+
},
|
|
529
|
+
],
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
type: "object",
|
|
533
|
+
properties: { bookingId: { type: "string" } },
|
|
534
|
+
},
|
|
535
|
+
],
|
|
536
|
+
},
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
responses: {},
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
const mockDereference = vi.fn().mockResolvedValue(schema);
|
|
547
|
+
|
|
548
|
+
const result = await flattenAllOfProcessor({
|
|
549
|
+
schema,
|
|
550
|
+
file: "/test/schema.json",
|
|
551
|
+
dereference: mockDereference,
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
const requestSchema =
|
|
555
|
+
result.paths?.["/bookings"]?.post?.requestBody?.content?.[
|
|
556
|
+
"application/json"
|
|
557
|
+
]?.schema;
|
|
558
|
+
|
|
559
|
+
expect(requestSchema).toMatchObject({
|
|
560
|
+
type: "object",
|
|
561
|
+
properties: {
|
|
562
|
+
quoteId: { type: "string" },
|
|
563
|
+
price: { type: "number" },
|
|
564
|
+
bookingId: { type: "string" },
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
expect(requestSchema).not.toHaveProperty("allOf");
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
it("should handle mixed allOf and oneOf combinations", async () => {
|
|
571
|
+
const schema: OpenAPIDocument = {
|
|
572
|
+
openapi: "3.0.0",
|
|
573
|
+
info: { title: "Test API", version: "1.0.0" },
|
|
574
|
+
paths: {},
|
|
575
|
+
components: {
|
|
576
|
+
schemas: {
|
|
577
|
+
Container: {
|
|
578
|
+
oneOf: [
|
|
579
|
+
{
|
|
580
|
+
allOf: [
|
|
581
|
+
{
|
|
582
|
+
type: "object",
|
|
583
|
+
properties: { type: { type: "string", const: "standard" } },
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
type: "object",
|
|
587
|
+
properties: { weight: { type: "number" } },
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
allOf: [
|
|
593
|
+
{
|
|
594
|
+
type: "object",
|
|
595
|
+
properties: {
|
|
596
|
+
type: { type: "string", const: "refrigerated" },
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
type: "object",
|
|
601
|
+
properties: { temperature: { type: "number" } },
|
|
602
|
+
},
|
|
603
|
+
],
|
|
604
|
+
},
|
|
605
|
+
],
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
const mockDereference = vi.fn().mockResolvedValue(schema);
|
|
612
|
+
|
|
613
|
+
const result = await flattenAllOfProcessor({
|
|
614
|
+
schema,
|
|
615
|
+
file: "/test/schema.json",
|
|
616
|
+
dereference: mockDereference,
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
const containerSchema = result.components?.schemas?.Container;
|
|
620
|
+
expect(containerSchema?.oneOf?.[0]).toMatchObject({
|
|
621
|
+
type: "object",
|
|
622
|
+
properties: {
|
|
623
|
+
type: { type: "string", const: "standard" },
|
|
624
|
+
weight: { type: "number" },
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
expect(containerSchema?.oneOf?.[0]).not.toHaveProperty("allOf");
|
|
628
|
+
expect(containerSchema?.oneOf?.[1]).toMatchObject({
|
|
629
|
+
type: "object",
|
|
630
|
+
properties: {
|
|
631
|
+
type: { type: "string", const: "refrigerated" },
|
|
632
|
+
temperature: { type: "number" },
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
expect(containerSchema?.oneOf?.[1]).not.toHaveProperty("allOf");
|
|
636
|
+
});
|
|
637
|
+
});
|