@scalar/types 0.2.1 → 0.2.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/CHANGELOG.md +7 -0
- package/package.json +3 -3
- package/dist/api-reference/api-reference-configuration.test.js +0 -224
- package/dist/api-reference/api-reference-configuration.test.js.map +0 -7
- package/dist/entities/security-scheme.test.js +0 -318
- package/dist/entities/security-scheme.test.js.map +0 -7
- package/dist/utils/nanoid.test.js +0 -29
- package/dist/utils/nanoid.test.js.map +0 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"scalar",
|
|
17
17
|
"references"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.2",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -66,13 +66,13 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"nanoid": "^5.1.5",
|
|
68
68
|
"zod": "3.24.1",
|
|
69
|
-
"@scalar/openapi-types": "0.3.
|
|
69
|
+
"@scalar/openapi-types": "0.3.2"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@types/har-format": "^1.2.15",
|
|
73
73
|
"type-fest": "^4.20.0",
|
|
74
74
|
"vite": "5.4.19",
|
|
75
|
-
"@scalar/build-tooling": "0.2.
|
|
75
|
+
"@scalar/build-tooling": "0.2.2"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "scalar-build-esbuild",
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { apiReferenceConfigurationSchema } from "./api-reference-configuration.js";
|
|
3
|
-
describe("api-reference-configuration", () => {
|
|
4
|
-
describe("schema", () => {
|
|
5
|
-
it("validates a minimal configuration", () => {
|
|
6
|
-
const minimalConfig = {};
|
|
7
|
-
expect(() => apiReferenceConfigurationSchema.parse(minimalConfig)).not.toThrow();
|
|
8
|
-
});
|
|
9
|
-
it("validates a complete configuration", () => {
|
|
10
|
-
const completeConfig = {
|
|
11
|
-
theme: "default",
|
|
12
|
-
layout: "modern",
|
|
13
|
-
url: "https://example.com/openapi.json",
|
|
14
|
-
content: '{"openapi": "3.1.0"}',
|
|
15
|
-
proxyUrl: "https://proxy.example.com",
|
|
16
|
-
isEditable: true,
|
|
17
|
-
showSidebar: true,
|
|
18
|
-
hideModels: false,
|
|
19
|
-
hideDownloadButton: false,
|
|
20
|
-
hideTestRequestButton: false,
|
|
21
|
-
hideSearch: false,
|
|
22
|
-
darkMode: true,
|
|
23
|
-
forceDarkModeState: "dark",
|
|
24
|
-
hideDarkModeToggle: false,
|
|
25
|
-
searchHotKey: "k",
|
|
26
|
-
favicon: "/favicon.ico",
|
|
27
|
-
hiddenClients: ["fetch", "xhr"],
|
|
28
|
-
defaultHttpClient: {
|
|
29
|
-
targetKey: "target1",
|
|
30
|
-
clientKey: "client1"
|
|
31
|
-
},
|
|
32
|
-
customCss: ".custom { color: red; }",
|
|
33
|
-
pathRouting: {
|
|
34
|
-
basePath: "/api"
|
|
35
|
-
},
|
|
36
|
-
baseServerURL: "https://api.example.com",
|
|
37
|
-
withDefaultFonts: true,
|
|
38
|
-
defaultOpenAllTags: false,
|
|
39
|
-
tagsSorter: "alpha",
|
|
40
|
-
operationsSorter: "method",
|
|
41
|
-
_integration: "nextjs",
|
|
42
|
-
hideClientButton: false
|
|
43
|
-
};
|
|
44
|
-
expect(() => apiReferenceConfigurationSchema.parse(completeConfig)).not.toThrow();
|
|
45
|
-
});
|
|
46
|
-
it("validates hiddenClients true", () => {
|
|
47
|
-
const config = { hiddenClients: true };
|
|
48
|
-
expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ hiddenClients: true });
|
|
49
|
-
});
|
|
50
|
-
it("validates theme enum values", () => {
|
|
51
|
-
const config = { theme: "invalid-theme" };
|
|
52
|
-
expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ theme: "default" });
|
|
53
|
-
const validThemes = [
|
|
54
|
-
"alternate",
|
|
55
|
-
"default",
|
|
56
|
-
"moon",
|
|
57
|
-
"purple",
|
|
58
|
-
"solarized",
|
|
59
|
-
"bluePlanet",
|
|
60
|
-
"deepSpace",
|
|
61
|
-
"saturn",
|
|
62
|
-
"kepler",
|
|
63
|
-
"elysiajs",
|
|
64
|
-
"fastify",
|
|
65
|
-
"mars",
|
|
66
|
-
"none"
|
|
67
|
-
];
|
|
68
|
-
validThemes.forEach((theme) => {
|
|
69
|
-
expect(apiReferenceConfigurationSchema.parse({ theme })).toMatchObject({ theme });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
it("validates layout enum values", () => {
|
|
73
|
-
const config = { layout: "invalid-layout" };
|
|
74
|
-
expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ layout: "modern" });
|
|
75
|
-
const validLayouts = ["modern", "classic"];
|
|
76
|
-
validLayouts.forEach((layout) => {
|
|
77
|
-
expect(apiReferenceConfigurationSchema.parse({ layout })).toMatchObject({ layout });
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
it("validates content and url configuration", () => {
|
|
81
|
-
const validConfigs = [
|
|
82
|
-
{ url: "https://example.com/openapi.json" },
|
|
83
|
-
{ content: '{"openapi": "3.1.0"}' },
|
|
84
|
-
{ content: { openapi: "3.1.0" } },
|
|
85
|
-
{ content: () => ({ openapi: "3.1.0" }) },
|
|
86
|
-
{ content: null }
|
|
87
|
-
];
|
|
88
|
-
validConfigs.forEach((config) => {
|
|
89
|
-
expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow();
|
|
90
|
-
});
|
|
91
|
-
const invalidConfigs = [{ url: 999 }, { content: 123 }];
|
|
92
|
-
invalidConfigs.forEach((config) => {
|
|
93
|
-
expect(() => apiReferenceConfigurationSchema.parse(config)).toThrow();
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
it("validates function parameters", () => {
|
|
97
|
-
const config = {
|
|
98
|
-
generateHeadingSlug: (heading) => `#${heading.slug}`,
|
|
99
|
-
generateModelSlug: (model) => `model-${model.name}`,
|
|
100
|
-
generateTagSlug: (tag) => `tag-${tag.name}`,
|
|
101
|
-
generateOperationSlug: (operation) => `${operation.method}-${operation.path}`,
|
|
102
|
-
generateWebhookSlug: (webhook) => `webhook-${webhook.name}`,
|
|
103
|
-
onLoaded: () => console.log("loaded"),
|
|
104
|
-
onSpecUpdate: (spec) => console.log("spec updated", spec)
|
|
105
|
-
};
|
|
106
|
-
expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow();
|
|
107
|
-
});
|
|
108
|
-
it("validates integration enum values", () => {
|
|
109
|
-
const validIntegrations = [
|
|
110
|
-
"adonisjs",
|
|
111
|
-
"docusaurus",
|
|
112
|
-
"dotnet",
|
|
113
|
-
"elysiajs",
|
|
114
|
-
"express",
|
|
115
|
-
"fastapi",
|
|
116
|
-
"fastify",
|
|
117
|
-
"go",
|
|
118
|
-
"hono",
|
|
119
|
-
"html",
|
|
120
|
-
"laravel",
|
|
121
|
-
"litestar",
|
|
122
|
-
"nestjs",
|
|
123
|
-
"nextjs",
|
|
124
|
-
"nitro",
|
|
125
|
-
"nuxt",
|
|
126
|
-
"platformatic",
|
|
127
|
-
"react",
|
|
128
|
-
"rust",
|
|
129
|
-
"svelte",
|
|
130
|
-
"vue",
|
|
131
|
-
null
|
|
132
|
-
];
|
|
133
|
-
validIntegrations.forEach((integration) => {
|
|
134
|
-
expect(() => apiReferenceConfigurationSchema.parse({ _integration: integration })).not.toThrow();
|
|
135
|
-
});
|
|
136
|
-
expect(() => apiReferenceConfigurationSchema.parse({ _integration: "invalid-integration" })).toThrow();
|
|
137
|
-
});
|
|
138
|
-
it("validates sorter configurations", () => {
|
|
139
|
-
const validConfigs = [
|
|
140
|
-
{ tagsSorter: "alpha" },
|
|
141
|
-
{ tagsSorter: (a, b) => a.name.localeCompare(b.name) },
|
|
142
|
-
{ operationsSorter: "alpha" },
|
|
143
|
-
{ operationsSorter: "method" },
|
|
144
|
-
{ operationsSorter: (a, b) => a.path.localeCompare(b.path) }
|
|
145
|
-
];
|
|
146
|
-
validConfigs.forEach((config) => {
|
|
147
|
-
expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow();
|
|
148
|
-
});
|
|
149
|
-
const invalidConfigs = [{ tagsSorter: "invalid" }, { operationsSorter: "invalid" }];
|
|
150
|
-
invalidConfigs.forEach((config) => {
|
|
151
|
-
expect(() => apiReferenceConfigurationSchema.parse(config)).toThrow();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe("migrations", () => {
|
|
156
|
-
it("migrates proxy to proxyUrl", () => {
|
|
157
|
-
const config = {
|
|
158
|
-
proxy: "https://proxy.example.com"
|
|
159
|
-
};
|
|
160
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
161
|
-
expect(migratedConfig.proxyUrl).toBe("https://proxy.example.com");
|
|
162
|
-
expect(migratedConfig.proxy).toBeUndefined();
|
|
163
|
-
});
|
|
164
|
-
it("keeps proxyUrl if both proxy and proxyUrl are set", () => {
|
|
165
|
-
const config = {
|
|
166
|
-
proxy: "https://proxy.example.com",
|
|
167
|
-
proxyUrl: "https://existing.example.com"
|
|
168
|
-
};
|
|
169
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
170
|
-
expect(migratedConfig.proxyUrl).toBe("https://existing.example.com");
|
|
171
|
-
expect(migratedConfig.proxy).toBeUndefined();
|
|
172
|
-
});
|
|
173
|
-
it("migrates the old proxy URL to the new one", () => {
|
|
174
|
-
const config = {
|
|
175
|
-
proxyUrl: "https://api.scalar.com/request-proxy"
|
|
176
|
-
};
|
|
177
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
178
|
-
expect(migratedConfig.proxyUrl).toBe("https://proxy.scalar.com");
|
|
179
|
-
expect(migratedConfig.proxy).toBeUndefined();
|
|
180
|
-
});
|
|
181
|
-
it("migrates spec.url to url", () => {
|
|
182
|
-
const config = {
|
|
183
|
-
spec: {
|
|
184
|
-
url: "https://example.com/openapi.json"
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
188
|
-
expect(migratedConfig.spec).toBeUndefined();
|
|
189
|
-
expect(migratedConfig.url).toBe("https://example.com/openapi.json");
|
|
190
|
-
});
|
|
191
|
-
it("migrates spec.content to content", () => {
|
|
192
|
-
const config = {
|
|
193
|
-
spec: {
|
|
194
|
-
content: '{"openapi": "3.1.0"}'
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
198
|
-
expect(migratedConfig.spec).toBeUndefined();
|
|
199
|
-
expect(migratedConfig.content).toBe('{"openapi": "3.1.0"}');
|
|
200
|
-
});
|
|
201
|
-
it("allows a function as onDocumentSelect", () => {
|
|
202
|
-
const config = {
|
|
203
|
-
onDocumentSelect: () => console.log("selected")
|
|
204
|
-
};
|
|
205
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
206
|
-
expect(migratedConfig.onDocumentSelect).toBeInstanceOf(Function);
|
|
207
|
-
});
|
|
208
|
-
it("allows a function as onDocumentSelect", () => {
|
|
209
|
-
const config = {
|
|
210
|
-
onDocumentSelect: () => console.log("selected")
|
|
211
|
-
};
|
|
212
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
213
|
-
expect(migratedConfig.onDocumentSelect).toBeInstanceOf(Function);
|
|
214
|
-
});
|
|
215
|
-
it("allows an async function as onDocumentSelect", async () => {
|
|
216
|
-
const config = {
|
|
217
|
-
onDocumentSelect: async () => console.log("selected")
|
|
218
|
-
};
|
|
219
|
-
const migratedConfig = apiReferenceConfigurationSchema.parse(config);
|
|
220
|
-
expect(migratedConfig.onDocumentSelect?.()).toBeInstanceOf(Promise);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
//# sourceMappingURL=api-reference-configuration.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/api-reference/api-reference-configuration.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\nimport { type ApiReferenceConfiguration, apiReferenceConfigurationSchema } from './api-reference-configuration'\n\ndescribe('api-reference-configuration', () => {\n describe('schema', () => {\n it('validates a minimal configuration', () => {\n const minimalConfig = {}\n expect(() => apiReferenceConfigurationSchema.parse(minimalConfig)).not.toThrow()\n })\n\n it('validates a complete configuration', () => {\n const completeConfig = {\n theme: 'default',\n layout: 'modern',\n url: 'https://example.com/openapi.json',\n content: '{\"openapi\": \"3.1.0\"}',\n proxyUrl: 'https://proxy.example.com',\n isEditable: true,\n showSidebar: true,\n hideModels: false,\n hideDownloadButton: false,\n hideTestRequestButton: false,\n hideSearch: false,\n darkMode: true,\n forceDarkModeState: 'dark',\n hideDarkModeToggle: false,\n searchHotKey: 'k',\n favicon: '/favicon.ico',\n hiddenClients: ['fetch', 'xhr'],\n defaultHttpClient: {\n targetKey: 'target1',\n clientKey: 'client1',\n },\n customCss: '.custom { color: red; }',\n pathRouting: {\n basePath: '/api',\n },\n baseServerURL: 'https://api.example.com',\n withDefaultFonts: true,\n defaultOpenAllTags: false,\n tagsSorter: 'alpha',\n operationsSorter: 'method',\n _integration: 'nextjs',\n hideClientButton: false,\n }\n\n expect(() => apiReferenceConfigurationSchema.parse(completeConfig)).not.toThrow()\n })\n\n it('validates hiddenClients true', () => {\n const config = { hiddenClients: true }\n\n expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ hiddenClients: true })\n })\n\n it('validates theme enum values', () => {\n const config = { theme: 'invalid-theme' }\n\n expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ theme: 'default' })\n\n const validThemes = [\n 'alternate',\n 'default',\n 'moon',\n 'purple',\n 'solarized',\n 'bluePlanet',\n 'deepSpace',\n 'saturn',\n 'kepler',\n 'elysiajs',\n 'fastify',\n 'mars',\n 'none',\n ]\n\n validThemes.forEach((theme) => {\n expect(apiReferenceConfigurationSchema.parse({ theme })).toMatchObject({ theme })\n })\n })\n\n it('validates layout enum values', () => {\n const config = { layout: 'invalid-layout' }\n expect(apiReferenceConfigurationSchema.parse(config)).toMatchObject({ layout: 'modern' })\n\n const validLayouts = ['modern', 'classic']\n validLayouts.forEach((layout) => {\n expect(apiReferenceConfigurationSchema.parse({ layout })).toMatchObject({ layout })\n })\n })\n\n it('validates content and url configuration', () => {\n const validConfigs = [\n { url: 'https://example.com/openapi.json' },\n { content: '{\"openapi\": \"3.1.0\"}' },\n { content: { openapi: '3.1.0' } },\n { content: () => ({ openapi: '3.1.0' }) },\n { content: null },\n ]\n\n validConfigs.forEach((config) => {\n expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow()\n })\n\n const invalidConfigs = [{ url: 999 }, { content: 123 }]\n\n invalidConfigs.forEach((config) => {\n expect(() => apiReferenceConfigurationSchema.parse(config)).toThrow()\n })\n })\n\n it('validates function parameters', () => {\n const config = {\n generateHeadingSlug: (heading: any) => `#${heading.slug}`,\n generateModelSlug: (model: { name: string }) => `model-${model.name}`,\n generateTagSlug: (tag: any) => `tag-${tag.name}`,\n generateOperationSlug: (operation: { path: string; method: string }) => `${operation.method}-${operation.path}`,\n generateWebhookSlug: (webhook: { name: string }) => `webhook-${webhook.name}`,\n onLoaded: () => console.log('loaded'),\n onSpecUpdate: (spec: string) => console.log('spec updated', spec),\n }\n\n expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow()\n })\n\n it('validates integration enum values', () => {\n const validIntegrations = [\n 'adonisjs',\n 'docusaurus',\n 'dotnet',\n 'elysiajs',\n 'express',\n 'fastapi',\n 'fastify',\n 'go',\n 'hono',\n 'html',\n 'laravel',\n 'litestar',\n 'nestjs',\n 'nextjs',\n 'nitro',\n 'nuxt',\n 'platformatic',\n 'react',\n 'rust',\n 'svelte',\n 'vue',\n null,\n ]\n\n validIntegrations.forEach((integration) => {\n expect(() => apiReferenceConfigurationSchema.parse({ _integration: integration })).not.toThrow()\n })\n\n expect(() => apiReferenceConfigurationSchema.parse({ _integration: 'invalid-integration' })).toThrow()\n })\n\n it('validates sorter configurations', () => {\n const validConfigs = [\n { tagsSorter: 'alpha' },\n { tagsSorter: (a: any, b: any) => a.name.localeCompare(b.name) },\n { operationsSorter: 'alpha' },\n { operationsSorter: 'method' },\n { operationsSorter: (a: any, b: any) => a.path.localeCompare(b.path) },\n ]\n\n validConfigs.forEach((config) => {\n expect(() => apiReferenceConfigurationSchema.parse(config)).not.toThrow()\n })\n\n const invalidConfigs = [{ tagsSorter: 'invalid' }, { operationsSorter: 'invalid' }]\n\n invalidConfigs.forEach((config) => {\n expect(() => apiReferenceConfigurationSchema.parse(config)).toThrow()\n })\n })\n })\n\n describe('migrations', () => {\n it('migrates proxy to proxyUrl', () => {\n const config = {\n proxy: 'https://proxy.example.com',\n }\n\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n\n expect(migratedConfig.proxyUrl).toBe('https://proxy.example.com')\n expect(migratedConfig.proxy).toBeUndefined()\n })\n\n it('keeps proxyUrl if both proxy and proxyUrl are set', () => {\n const config = {\n proxy: 'https://proxy.example.com',\n proxyUrl: 'https://existing.example.com',\n }\n\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n expect(migratedConfig.proxyUrl).toBe('https://existing.example.com')\n expect(migratedConfig.proxy).toBeUndefined()\n })\n\n it('migrates the old proxy URL to the new one', () => {\n const config = {\n proxyUrl: 'https://api.scalar.com/request-proxy',\n }\n\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n expect(migratedConfig.proxyUrl).toBe('https://proxy.scalar.com')\n expect(migratedConfig.proxy).toBeUndefined()\n })\n\n it('migrates spec.url to url', () => {\n const config = {\n spec: {\n url: 'https://example.com/openapi.json',\n },\n }\n\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n\n expect(migratedConfig.spec).toBeUndefined()\n expect(migratedConfig.url).toBe('https://example.com/openapi.json')\n })\n\n it('migrates spec.content to content', () => {\n const config = {\n spec: {\n content: '{\"openapi\": \"3.1.0\"}',\n },\n }\n\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n\n expect(migratedConfig.spec).toBeUndefined()\n expect(migratedConfig.content).toBe('{\"openapi\": \"3.1.0\"}')\n })\n\n it('allows a function as onDocumentSelect', () => {\n const config = {\n onDocumentSelect: () => console.log('selected'),\n }\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n expect(migratedConfig.onDocumentSelect).toBeInstanceOf(Function)\n })\n\n it('allows a function as onDocumentSelect', () => {\n const config = {\n onDocumentSelect: () => console.log('selected'),\n } satisfies Partial<ApiReferenceConfiguration>\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n expect(migratedConfig.onDocumentSelect).toBeInstanceOf(Function)\n })\n\n it('allows an async function as onDocumentSelect', async () => {\n const config = {\n onDocumentSelect: async () => console.log('selected'),\n } satisfies Partial<ApiReferenceConfiguration>\n const migratedConfig = apiReferenceConfigurationSchema.parse(config)\n\n expect(migratedConfig.onDocumentSelect?.()).toBeInstanceOf(Promise)\n })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAyC,uCAAuC;AAEhF,SAAS,+BAA+B,MAAM;AAC5C,WAAS,UAAU,MAAM;AACvB,OAAG,qCAAqC,MAAM;AAC5C,YAAM,gBAAgB,CAAC;AACvB,aAAO,MAAM,gCAAgC,MAAM,aAAa,CAAC,EAAE,IAAI,QAAQ;AAAA,IACjF,CAAC;AAED,OAAG,sCAAsC,MAAM;AAC7C,YAAM,iBAAiB;AAAA,QACrB,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,KAAK;AAAA,QACL,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,aAAa;AAAA,QACb,YAAY;AAAA,QACZ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OAAG,yCAAyC,MAAM;AAChD,YAAM,SAAS;AAAA,QACb,kBAAkB,MAAM,QAAQ,IAAI,UAAU;AAAA,MAChD;AACA,YAAM,iBAAiB,gCAAgC,MAAM,MAAM;AACnE,aAAO,eAAe,gBAAgB,EAAE,eAAe,QAAQ;AAAA,IACjE,CAAC;AAED,OAAG,yCAAyC,MAAM;AAChD,YAAM,SAAS;AAAA,QACb,kBAAkB,MAAM,QAAQ,IAAI,UAAU;AAAA,MAChD;AACA,YAAM,iBAAiB,gCAAgC,MAAM,MAAM;AACnE,aAAO,eAAe,gBAAgB,EAAE,eAAe,QAAQ;AAAA,IACjE,CAAC;AAED,OAAG,gDAAgD,YAAY;AAC7D,YAAM,SAAS;AAAA,QACb,kBAAkB,YAAY,QAAQ,IAAI,UAAU;AAAA,MACtD;AACA,YAAM,iBAAiB,gCAAgC,MAAM,MAAM;AAEnE,aAAO,eAAe,mBAAmB,CAAC,EAAE,eAAe,OAAO;AAAA,IACpE,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
oasSecurityRequirementSchema,
|
|
4
|
-
pkceOptions,
|
|
5
|
-
securityApiKeySchema,
|
|
6
|
-
securityHttpSchema,
|
|
7
|
-
securityOauthSchema,
|
|
8
|
-
securityOpenIdSchema,
|
|
9
|
-
securitySchemeSchema
|
|
10
|
-
} from "./security-scheme.js";
|
|
11
|
-
describe("Security Schemas", () => {
|
|
12
|
-
describe("API Key Schema", () => {
|
|
13
|
-
it("should validate a valid API key schema", () => {
|
|
14
|
-
const apiKey = {
|
|
15
|
-
type: "apiKey",
|
|
16
|
-
name: "api_key",
|
|
17
|
-
in: "header",
|
|
18
|
-
description: "API Key Authentication",
|
|
19
|
-
uid: "apikey123",
|
|
20
|
-
nameKey: "x-api-key",
|
|
21
|
-
value: "test-api-key"
|
|
22
|
-
};
|
|
23
|
-
const result = securityApiKeySchema.safeParse(apiKey);
|
|
24
|
-
expect(result.success).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
it("should apply default values", () => {
|
|
27
|
-
const minimalApiKey = {
|
|
28
|
-
type: "apiKey",
|
|
29
|
-
uid: "apikey123"
|
|
30
|
-
};
|
|
31
|
-
const result = securityApiKeySchema.parse(minimalApiKey);
|
|
32
|
-
expect(result).toEqual({
|
|
33
|
-
type: "apiKey",
|
|
34
|
-
uid: "apikey123",
|
|
35
|
-
name: "",
|
|
36
|
-
in: "header",
|
|
37
|
-
nameKey: "",
|
|
38
|
-
value: ""
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("HTTP Schema", () => {
|
|
43
|
-
it("should validate a valid HTTP basic schema", () => {
|
|
44
|
-
const httpBasic = {
|
|
45
|
-
type: "http",
|
|
46
|
-
scheme: "basic",
|
|
47
|
-
description: "Basic HTTP Authentication",
|
|
48
|
-
uid: "http123",
|
|
49
|
-
username: "user",
|
|
50
|
-
password: "pass"
|
|
51
|
-
};
|
|
52
|
-
const result = securityHttpSchema.safeParse(httpBasic);
|
|
53
|
-
expect(result.success).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
it("should validate a valid HTTP bearer schema", () => {
|
|
56
|
-
const httpBearer = {
|
|
57
|
-
type: "http",
|
|
58
|
-
scheme: "bearer",
|
|
59
|
-
bearerFormat: "JWT",
|
|
60
|
-
description: "Bearer Authentication",
|
|
61
|
-
uid: "http456",
|
|
62
|
-
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
|
|
63
|
-
};
|
|
64
|
-
const result = securityHttpSchema.safeParse(httpBearer);
|
|
65
|
-
expect(result.success).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
it("should apply default values", () => {
|
|
68
|
-
const minimalHttp = {
|
|
69
|
-
type: "http",
|
|
70
|
-
uid: "http123"
|
|
71
|
-
};
|
|
72
|
-
const result = securityHttpSchema.parse(minimalHttp);
|
|
73
|
-
expect(result).toEqual({
|
|
74
|
-
type: "http",
|
|
75
|
-
uid: "http123",
|
|
76
|
-
scheme: "basic",
|
|
77
|
-
bearerFormat: "JWT",
|
|
78
|
-
nameKey: "",
|
|
79
|
-
username: "",
|
|
80
|
-
password: "",
|
|
81
|
-
token: ""
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
it("should reject invalid scheme values", () => {
|
|
85
|
-
const invalidHttp = {
|
|
86
|
-
type: "http",
|
|
87
|
-
scheme: "digest",
|
|
88
|
-
uid: "http123"
|
|
89
|
-
};
|
|
90
|
-
const result = securityHttpSchema.safeParse(invalidHttp);
|
|
91
|
-
expect(result.success).toBe(false);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe("OpenID Connect Schema", () => {
|
|
95
|
-
it("should validate a valid OpenID schema", () => {
|
|
96
|
-
const openId = {
|
|
97
|
-
type: "openIdConnect",
|
|
98
|
-
openIdConnectUrl: "https://example.com/.well-known/openid-configuration",
|
|
99
|
-
description: "OpenID Connect",
|
|
100
|
-
uid: "openid123",
|
|
101
|
-
nameKey: "openid"
|
|
102
|
-
};
|
|
103
|
-
const result = securityOpenIdSchema.safeParse(openId);
|
|
104
|
-
expect(result.success).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
it("should apply default values", () => {
|
|
107
|
-
const minimalOpenId = {
|
|
108
|
-
type: "openIdConnect",
|
|
109
|
-
uid: "openid123"
|
|
110
|
-
};
|
|
111
|
-
const result = securityOpenIdSchema.parse(minimalOpenId);
|
|
112
|
-
expect(result).toEqual({
|
|
113
|
-
type: "openIdConnect",
|
|
114
|
-
uid: "openid123",
|
|
115
|
-
openIdConnectUrl: "",
|
|
116
|
-
nameKey: ""
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe("OAuth2 Schema", () => {
|
|
121
|
-
it("should validate a valid OAuth2 implicit flow schema", () => {
|
|
122
|
-
const oauth2Implicit = {
|
|
123
|
-
type: "oauth2",
|
|
124
|
-
description: "OAuth2 Implicit Flow",
|
|
125
|
-
uid: "oauth123",
|
|
126
|
-
flows: {
|
|
127
|
-
implicit: {
|
|
128
|
-
type: "implicit",
|
|
129
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
130
|
-
scopes: {
|
|
131
|
-
"read:api": "Read access",
|
|
132
|
-
"write:api": "Write access"
|
|
133
|
-
},
|
|
134
|
-
selectedScopes: ["read:api"],
|
|
135
|
-
token: "access-token-123"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const result = securityOauthSchema.safeParse(oauth2Implicit);
|
|
140
|
-
expect(result.success).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
it("should validate a valid OAuth2 with missing scopes", () => {
|
|
143
|
-
const oauth2Implicit = {
|
|
144
|
-
type: "oauth2",
|
|
145
|
-
description: "OAuth2 Implicit Flow",
|
|
146
|
-
uid: "oauth123",
|
|
147
|
-
flows: {
|
|
148
|
-
implicit: {
|
|
149
|
-
type: "implicit",
|
|
150
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
151
|
-
scopes: null,
|
|
152
|
-
selectedScopes: ["read:api"],
|
|
153
|
-
token: "access-token-123"
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const result = securityOauthSchema.safeParse(oauth2Implicit);
|
|
158
|
-
expect(result.success).toBe(true);
|
|
159
|
-
});
|
|
160
|
-
it("should validate a valid OAuth2 authorization code flow schema", () => {
|
|
161
|
-
const oauth2AuthCode = {
|
|
162
|
-
type: "oauth2",
|
|
163
|
-
description: "OAuth2 Authorization Code Flow",
|
|
164
|
-
uid: "oauth456",
|
|
165
|
-
flows: {
|
|
166
|
-
authorizationCode: {
|
|
167
|
-
type: "authorizationCode",
|
|
168
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
169
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
170
|
-
"x-usePkce": "SHA-256",
|
|
171
|
-
scopes: {
|
|
172
|
-
"read:api": "Read access",
|
|
173
|
-
"write:api": "Write access"
|
|
174
|
-
},
|
|
175
|
-
clientSecret: "client-secret",
|
|
176
|
-
token: "access-token-456",
|
|
177
|
-
"x-scalar-security-query": {
|
|
178
|
-
prompt: "consent"
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const result = securityOauthSchema.safeParse(oauth2AuthCode);
|
|
184
|
-
expect(result.success).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
it("should validate a valid OAuth2 client credentials flow schema", () => {
|
|
187
|
-
const oauth2ClientCreds = {
|
|
188
|
-
type: "oauth2",
|
|
189
|
-
description: "OAuth2 Client Credentials Flow",
|
|
190
|
-
uid: "oauth789",
|
|
191
|
-
flows: {
|
|
192
|
-
clientCredentials: {
|
|
193
|
-
type: "clientCredentials",
|
|
194
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
195
|
-
scopes: {},
|
|
196
|
-
clientSecret: "client-secret",
|
|
197
|
-
token: "access-token-789"
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
const result = securityOauthSchema.safeParse(oauth2ClientCreds);
|
|
202
|
-
expect(result.success).toBe(true);
|
|
203
|
-
});
|
|
204
|
-
it("should validate a valid OAuth2 password flow schema", () => {
|
|
205
|
-
const oauth2Password = {
|
|
206
|
-
type: "oauth2",
|
|
207
|
-
description: "OAuth2 Password Flow",
|
|
208
|
-
uid: "oauth101",
|
|
209
|
-
flows: {
|
|
210
|
-
password: {
|
|
211
|
-
type: "password",
|
|
212
|
-
tokenUrl: "https://example.com/oauth/token",
|
|
213
|
-
scopes: {},
|
|
214
|
-
username: "testuser",
|
|
215
|
-
password: "testpass",
|
|
216
|
-
clientSecret: "client-secret",
|
|
217
|
-
token: "access-token-101",
|
|
218
|
-
"x-scalar-security-query": {
|
|
219
|
-
prompt: "consent",
|
|
220
|
-
audience: "scalar"
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const result = securityOauthSchema.safeParse(oauth2Password);
|
|
226
|
-
expect(result.success).toBe(true);
|
|
227
|
-
});
|
|
228
|
-
it("should apply default values", () => {
|
|
229
|
-
const minimalOauth2 = {
|
|
230
|
-
type: "oauth2",
|
|
231
|
-
uid: "oauth123"
|
|
232
|
-
};
|
|
233
|
-
const result = securityOauthSchema.parse(minimalOauth2);
|
|
234
|
-
expect(result.flows.implicit).toBeDefined();
|
|
235
|
-
expect(result.flows.implicit?.authorizationUrl).toBe("http://localhost:8080");
|
|
236
|
-
expect(result.flows.implicit?.scopes).toEqual({});
|
|
237
|
-
expect(result.flows.implicit?.selectedScopes).toEqual([]);
|
|
238
|
-
expect(result.flows.implicit?.token).toBe("");
|
|
239
|
-
expect(result.nameKey).toBe("");
|
|
240
|
-
});
|
|
241
|
-
it("should validate PKCE options", () => {
|
|
242
|
-
expect(pkceOptions).toContain("SHA-256");
|
|
243
|
-
expect(pkceOptions).toContain("plain");
|
|
244
|
-
expect(pkceOptions).toContain("no");
|
|
245
|
-
});
|
|
246
|
-
it("should apply x-default-scopes", () => {
|
|
247
|
-
const oauth2 = {
|
|
248
|
-
type: "oauth2",
|
|
249
|
-
uid: "oauth123",
|
|
250
|
-
"x-default-scopes": ["read:api", "write:api"]
|
|
251
|
-
};
|
|
252
|
-
const result = securitySchemeSchema.parse(oauth2);
|
|
253
|
-
if (result.type !== "oauth2") {
|
|
254
|
-
throw new Error("Expected oauth2 schema");
|
|
255
|
-
}
|
|
256
|
-
expect(result["x-default-scopes"]).toEqual(["read:api", "write:api"]);
|
|
257
|
-
expect(result.flows.implicit?.selectedScopes).toEqual(["read:api", "write:api"]);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
describe("Security Requirement Schema", () => {
|
|
261
|
-
it("should validate a valid security requirement", () => {
|
|
262
|
-
const securityRequirement = {
|
|
263
|
-
"api_key": [],
|
|
264
|
-
"oauth2": ["read:api", "write:api"]
|
|
265
|
-
};
|
|
266
|
-
const result = oasSecurityRequirementSchema.safeParse(securityRequirement);
|
|
267
|
-
expect(result.success).toBe(true);
|
|
268
|
-
});
|
|
269
|
-
it("should apply default values for empty scopes", () => {
|
|
270
|
-
const securityRequirement = {
|
|
271
|
-
"api_key": void 0
|
|
272
|
-
};
|
|
273
|
-
const result = oasSecurityRequirementSchema.parse(securityRequirement);
|
|
274
|
-
expect(result).toEqual({
|
|
275
|
-
"api_key": []
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
describe("Combined Security Scheme", () => {
|
|
280
|
-
it("should validate all security scheme types", () => {
|
|
281
|
-
const apiKey = {
|
|
282
|
-
type: "apiKey",
|
|
283
|
-
name: "api_key",
|
|
284
|
-
in: "header",
|
|
285
|
-
uid: "apikey123",
|
|
286
|
-
value: "test-api-key"
|
|
287
|
-
};
|
|
288
|
-
const http = {
|
|
289
|
-
type: "http",
|
|
290
|
-
scheme: "bearer",
|
|
291
|
-
uid: "http123",
|
|
292
|
-
token: "bearer-token"
|
|
293
|
-
};
|
|
294
|
-
const openId = {
|
|
295
|
-
type: "openIdConnect",
|
|
296
|
-
openIdConnectUrl: "https://example.com/.well-known/openid-configuration",
|
|
297
|
-
uid: "openid123"
|
|
298
|
-
};
|
|
299
|
-
const oauth2 = {
|
|
300
|
-
type: "oauth2",
|
|
301
|
-
uid: "oauth123",
|
|
302
|
-
flows: {
|
|
303
|
-
implicit: {
|
|
304
|
-
type: "implicit",
|
|
305
|
-
authorizationUrl: "https://example.com/oauth/authorize",
|
|
306
|
-
scopes: {},
|
|
307
|
-
token: ""
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
expect(securitySchemeSchema.safeParse(apiKey).success).toBe(true);
|
|
312
|
-
expect(securitySchemeSchema.safeParse(http).success).toBe(true);
|
|
313
|
-
expect(securitySchemeSchema.safeParse(openId).success).toBe(true);
|
|
314
|
-
expect(securitySchemeSchema.safeParse(oauth2).success).toBe(true);
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
//# sourceMappingURL=security-scheme.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/entities/security-scheme.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\nimport {\n oasSecurityRequirementSchema,\n pkceOptions,\n securityApiKeySchema,\n securityHttpSchema,\n securityOauthSchema,\n securityOpenIdSchema,\n securitySchemeSchema,\n} from './security-scheme'\n\ndescribe('Security Schemas', () => {\n describe('API Key Schema', () => {\n it('should validate a valid API key schema', () => {\n const apiKey = {\n type: 'apiKey',\n name: 'api_key',\n in: 'header',\n description: 'API Key Authentication',\n uid: 'apikey123',\n nameKey: 'x-api-key',\n value: 'test-api-key',\n }\n\n const result = securityApiKeySchema.safeParse(apiKey)\n expect(result.success).toBe(true)\n })\n\n it('should apply default values', () => {\n const minimalApiKey = {\n type: 'apiKey',\n uid: 'apikey123',\n }\n\n const result = securityApiKeySchema.parse(minimalApiKey)\n expect(result).toEqual({\n type: 'apiKey',\n uid: 'apikey123',\n name: '',\n in: 'header',\n nameKey: '',\n value: '',\n })\n })\n })\n\n describe('HTTP Schema', () => {\n it('should validate a valid HTTP basic schema', () => {\n const httpBasic = {\n type: 'http',\n scheme: 'basic',\n description: 'Basic HTTP Authentication',\n uid: 'http123',\n username: 'user',\n password: 'pass',\n }\n\n const result = securityHttpSchema.safeParse(httpBasic)\n expect(result.success).toBe(true)\n })\n\n it('should validate a valid HTTP bearer schema', () => {\n const httpBearer = {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n description: 'Bearer Authentication',\n uid: 'http456',\n token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',\n }\n\n const result = securityHttpSchema.safeParse(httpBearer)\n expect(result.success).toBe(true)\n })\n\n it('should apply default values', () => {\n const minimalHttp = {\n type: 'http',\n uid: 'http123',\n }\n\n const result = securityHttpSchema.parse(minimalHttp)\n expect(result).toEqual({\n type: 'http',\n uid: 'http123',\n scheme: 'basic',\n bearerFormat: 'JWT',\n nameKey: '',\n username: '',\n password: '',\n token: '',\n })\n })\n\n it('should reject invalid scheme values', () => {\n const invalidHttp = {\n type: 'http',\n scheme: 'digest',\n uid: 'http123',\n }\n\n const result = securityHttpSchema.safeParse(invalidHttp)\n expect(result.success).toBe(false)\n })\n })\n\n describe('OpenID Connect Schema', () => {\n it('should validate a valid OpenID schema', () => {\n const openId = {\n type: 'openIdConnect',\n openIdConnectUrl: 'https://example.com/.well-known/openid-configuration',\n description: 'OpenID Connect',\n uid: 'openid123',\n nameKey: 'openid',\n }\n\n const result = securityOpenIdSchema.safeParse(openId)\n expect(result.success).toBe(true)\n })\n\n it('should apply default values', () => {\n const minimalOpenId = {\n type: 'openIdConnect',\n uid: 'openid123',\n }\n\n const result = securityOpenIdSchema.parse(minimalOpenId)\n expect(result).toEqual({\n type: 'openIdConnect',\n uid: 'openid123',\n openIdConnectUrl: '',\n nameKey: '',\n })\n })\n })\n\n describe('OAuth2 Schema', () => {\n it('should validate a valid OAuth2 implicit flow schema', () => {\n const oauth2Implicit = {\n type: 'oauth2',\n description: 'OAuth2 Implicit Flow',\n uid: 'oauth123',\n flows: {\n implicit: {\n type: 'implicit',\n authorizationUrl: 'https://example.com/oauth/authorize',\n scopes: {\n 'read:api': 'Read access',\n 'write:api': 'Write access',\n },\n selectedScopes: ['read:api'],\n token: 'access-token-123',\n },\n },\n }\n\n const result = securityOauthSchema.safeParse(oauth2Implicit)\n expect(result.success).toBe(true)\n })\n\n it('should validate a valid OAuth2 with missing scopes', () => {\n const oauth2Implicit = {\n type: 'oauth2',\n description: 'OAuth2 Implicit Flow',\n uid: 'oauth123',\n flows: {\n implicit: {\n type: 'implicit',\n authorizationUrl: 'https://example.com/oauth/authorize',\n scopes: null,\n selectedScopes: ['read:api'],\n token: 'access-token-123',\n },\n },\n }\n\n const result = securityOauthSchema.safeParse(oauth2Implicit)\n expect(result.success).toBe(true)\n })\n\n it('should validate a valid OAuth2 authorization code flow schema', () => {\n const oauth2AuthCode = {\n type: 'oauth2',\n description: 'OAuth2 Authorization Code Flow',\n uid: 'oauth456',\n flows: {\n authorizationCode: {\n type: 'authorizationCode',\n authorizationUrl: 'https://example.com/oauth/authorize',\n tokenUrl: 'https://example.com/oauth/token',\n 'x-usePkce': 'SHA-256',\n scopes: {\n 'read:api': 'Read access',\n 'write:api': 'Write access',\n },\n clientSecret: 'client-secret',\n token: 'access-token-456',\n 'x-scalar-security-query': {\n prompt: 'consent',\n },\n },\n },\n }\n\n const result = securityOauthSchema.safeParse(oauth2AuthCode)\n expect(result.success).toBe(true)\n })\n\n it('should validate a valid OAuth2 client credentials flow schema', () => {\n const oauth2ClientCreds = {\n type: 'oauth2',\n description: 'OAuth2 Client Credentials Flow',\n uid: 'oauth789',\n flows: {\n clientCredentials: {\n type: 'clientCredentials',\n tokenUrl: 'https://example.com/oauth/token',\n scopes: {},\n clientSecret: 'client-secret',\n token: 'access-token-789',\n },\n },\n }\n\n const result = securityOauthSchema.safeParse(oauth2ClientCreds)\n expect(result.success).toBe(true)\n })\n\n it('should validate a valid OAuth2 password flow schema', () => {\n const oauth2Password = {\n type: 'oauth2',\n description: 'OAuth2 Password Flow',\n uid: 'oauth101',\n flows: {\n password: {\n type: 'password',\n tokenUrl: 'https://example.com/oauth/token',\n scopes: {},\n username: 'testuser',\n password: 'testpass',\n clientSecret: 'client-secret',\n token: 'access-token-101',\n 'x-scalar-security-query': {\n prompt: 'consent',\n audience: 'scalar',\n },\n },\n },\n }\n\n const result = securityOauthSchema.safeParse(oauth2Password)\n expect(result.success).toBe(true)\n })\n\n it('should apply default values', () => {\n const minimalOauth2 = {\n type: 'oauth2',\n uid: 'oauth123',\n }\n\n const result = securityOauthSchema.parse(minimalOauth2)\n expect(result.flows.implicit).toBeDefined()\n expect(result.flows.implicit?.authorizationUrl).toBe('http://localhost:8080')\n expect(result.flows.implicit?.scopes).toEqual({})\n expect(result.flows.implicit?.selectedScopes).toEqual([])\n expect(result.flows.implicit?.token).toBe('')\n expect(result.nameKey).toBe('')\n })\n\n it('should validate PKCE options', () => {\n expect(pkceOptions).toContain('SHA-256')\n expect(pkceOptions).toContain('plain')\n expect(pkceOptions).toContain('no')\n })\n\n it('should apply x-default-scopes', () => {\n const oauth2 = {\n type: 'oauth2',\n uid: 'oauth123',\n 'x-default-scopes': ['read:api', 'write:api'],\n }\n\n const result = securitySchemeSchema.parse(oauth2)\n if (result.type !== 'oauth2') {\n throw new Error('Expected oauth2 schema')\n }\n expect(result['x-default-scopes']).toEqual(['read:api', 'write:api'])\n expect(result.flows.implicit?.selectedScopes).toEqual(['read:api', 'write:api'])\n })\n })\n\n describe('Security Requirement Schema', () => {\n it('should validate a valid security requirement', () => {\n const securityRequirement = {\n 'api_key': [],\n 'oauth2': ['read:api', 'write:api'],\n }\n\n const result = oasSecurityRequirementSchema.safeParse(securityRequirement)\n expect(result.success).toBe(true)\n })\n\n it('should apply default values for empty scopes', () => {\n const securityRequirement = {\n 'api_key': undefined,\n }\n\n const result = oasSecurityRequirementSchema.parse(securityRequirement)\n expect(result).toEqual({\n 'api_key': [],\n })\n })\n })\n\n describe('Combined Security Scheme', () => {\n it('should validate all security scheme types', () => {\n const apiKey = {\n type: 'apiKey',\n name: 'api_key',\n in: 'header',\n uid: 'apikey123',\n value: 'test-api-key',\n }\n\n const http = {\n type: 'http',\n scheme: 'bearer',\n uid: 'http123',\n token: 'bearer-token',\n }\n\n const openId = {\n type: 'openIdConnect',\n openIdConnectUrl: 'https://example.com/.well-known/openid-configuration',\n uid: 'openid123',\n }\n\n const oauth2 = {\n type: 'oauth2',\n uid: 'oauth123',\n flows: {\n implicit: {\n type: 'implicit',\n authorizationUrl: 'https://example.com/oauth/authorize',\n scopes: {},\n token: '',\n },\n },\n }\n\n expect(securitySchemeSchema.safeParse(apiKey).success).toBe(true)\n expect(securitySchemeSchema.safeParse(http).success).toBe(true)\n expect(securitySchemeSchema.safeParse(openId).success).toBe(true)\n expect(securitySchemeSchema.safeParse(oauth2).success).toBe(true)\n })\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,oBAAoB,MAAM;AACjC,WAAS,kBAAkB,MAAM;AAC/B,OAAG,0CAA0C,MAAM;AACjD,YAAM,SAAS;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,IAAI;AAAA,QACJ,aAAa;AAAA,QACb,KAAK;AAAA,QACL,SAAS;AAAA,QACT,OAAO;AAAA,MACT;AAEA,YAAM,SAAS,qBAAqB,UAAU,MAAM;AACpD,aAAO,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,IAClC,CAAC;AAED,OAAG,+BAA+B,MAAM;AACtC,YAAM,gBAAgB;AAAA,QACpB,MAAM;AAAA,QACN,KAAK;AAAA,MACP;AAEA,YAAM,SAAS,qBAAqB,MAAM,aAAa;AACvD,aAAO,MAAM,EAAE,QAAQ;AAAA,QACrB,MAAM;AAAA,QACN,KAAK;AAAA,QACL,MAAM;AAAA,QACN,IAAI;AAAA,QACJ,SAAS;AAAA,QACT,OAAO;AAAA,MACT,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AAED,WAAS,eAAe,MAAM;AAC5B,OAAG,6CAA6C,MAAM;AACpD,YAAM,YAAY;AAAA,QAChB,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,aAAa;AAAA,QACb,KAAK;AAAA,QACL,UAAU;AAAA,QACV,UAAU;AAAA,MACZ;AAEA,YAAM,SAAS,mBAAmB,UAAU,SAAS;AACrD,aAAO,OAAO,OAAO,EAAE,KAAK,IAAI;AAAA,IAClC,CAAC;AAED,OAAG,8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C;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AAED,WAAS,4BAA4B,MAAM;AACzC,OAAG,6CAA6C,MAAM;AACpD,YAAM,SAAS;AAAA,QACb,MAAM;AAAA,QACN,MAAM;AAAA,QACN,IAAI;AAAA,QACJ,KAAK;AAAA,QACL,OAAO;AAAA,MACT;AAEA,YAAM,OAAO;AAAA,QACX,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,KAAK;AAAA,QACL,OAAO;AAAA,MACT;AAEA,YAAM,SAAS;AAAA,QACb,MAAM;AAAA,QACN,kBAAkB;AAAA,QAClB,KAAK;AAAA,MACP;AAEA,YAAM,SAAS;AAAA,QACb,MAAM;AAAA,QACN,KAAK;AAAA,QACL,OAAO;AAAA,UACL,UAAU;AAAA,YACR,MAAM;AAAA,YACN,kBAAkB;AAAA,YAClB,QAAQ,CAAC;AAAA,YACT,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAEA,aAAO,qBAAqB,UAAU,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AAChE,aAAO,qBAAqB,UAAU,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI;AAC9D,aAAO,qBAAqB,UAAU,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AAChE,aAAO,qBAAqB,UAAU,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI;AAAA,IAClE,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { nanoidSchema } from "./nanoid.js";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
describe("nanoidSchema", () => {
|
|
5
|
-
it("should generate a string with minimum length of 7 characters when no value is provided", () => {
|
|
6
|
-
const result = nanoidSchema.parse(void 0);
|
|
7
|
-
expect(typeof result).toBe("string");
|
|
8
|
-
expect(result.length).toBeGreaterThanOrEqual(7);
|
|
9
|
-
});
|
|
10
|
-
it("should accept valid strings with length >= 7", () => {
|
|
11
|
-
const validString = "1234567";
|
|
12
|
-
const result = nanoidSchema.parse(validString);
|
|
13
|
-
expect(result).toBe(validString);
|
|
14
|
-
});
|
|
15
|
-
it("should reject strings shorter than 7 characters", () => {
|
|
16
|
-
const invalidString = "123456";
|
|
17
|
-
expect(() => nanoidSchema.parse(invalidString)).toThrow(z.ZodError);
|
|
18
|
-
});
|
|
19
|
-
it("should generate different IDs for multiple calls", () => {
|
|
20
|
-
const id1 = nanoidSchema.parse(void 0);
|
|
21
|
-
const id2 = nanoidSchema.parse(void 0);
|
|
22
|
-
expect(id1).not.toBe(id2);
|
|
23
|
-
});
|
|
24
|
-
it("should properly type the generated ID as Nanoid", () => {
|
|
25
|
-
const id = nanoidSchema.parse(void 0);
|
|
26
|
-
expect(typeof id).toBe("string");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
//# sourceMappingURL=nanoid.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/nanoid.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, it, expect } from 'vitest'\nimport { nanoidSchema, type Nanoid } from './nanoid'\nimport { z } from 'zod'\n\ndescribe('nanoidSchema', () => {\n it('should generate a string with minimum length of 7 characters when no value is provided', () => {\n const result = nanoidSchema.parse(undefined)\n expect(typeof result).toBe('string')\n expect(result.length).toBeGreaterThanOrEqual(7)\n })\n\n it('should accept valid strings with length >= 7', () => {\n const validString = '1234567'\n const result = nanoidSchema.parse(validString)\n expect(result).toBe(validString)\n })\n\n it('should reject strings shorter than 7 characters', () => {\n const invalidString = '123456'\n expect(() => nanoidSchema.parse(invalidString)).toThrow(z.ZodError)\n })\n\n it('should generate different IDs for multiple calls', () => {\n const id1 = nanoidSchema.parse(undefined)\n const id2 = nanoidSchema.parse(undefined)\n expect(id1).not.toBe(id2)\n })\n\n it('should properly type the generated ID as Nanoid', () => {\n const id: Nanoid = nanoidSchema.parse(undefined)\n expect(typeof id).toBe('string')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,IAAI,cAAc;AACrC,SAAS,oBAAiC;AAC1C,SAAS,SAAS;AAElB,SAAS,gBAAgB,MAAM;AAC7B,KAAG,0FAA0F,MAAM;AACjG,UAAM,SAAS,aAAa,MAAM,MAAS;AAC3C,WAAO,OAAO,MAAM,EAAE,KAAK,QAAQ;AACnC,WAAO,OAAO,MAAM,EAAE,uBAAuB,CAAC;AAAA,EAChD,CAAC;AAED,KAAG,gDAAgD,MAAM;AACvD,UAAM,cAAc;AACpB,UAAM,SAAS,aAAa,MAAM,WAAW;AAC7C,WAAO,MAAM,EAAE,KAAK,WAAW;AAAA,EACjC,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D,UAAM,gBAAgB;AACtB,WAAO,MAAM,aAAa,MAAM,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ;AAAA,EACpE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,UAAM,MAAM,aAAa,MAAM,MAAS;AACxC,UAAM,MAAM,aAAa,MAAM,MAAS;AACxC,WAAO,GAAG,EAAE,IAAI,KAAK,GAAG;AAAA,EAC1B,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D,UAAM,KAAa,aAAa,MAAM,MAAS;AAC/C,WAAO,OAAO,EAAE,EAAE,KAAK,QAAQ;AAAA,EACjC,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|