@lukoweb/apitogo 0.2.51 → 0.2.53

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.
@@ -1,371 +1,376 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import {
4
- $RefParser,
5
- type JSONSchema,
6
- } from "@apidevtools/json-schema-ref-parser";
7
- import { upgrade, validate } from "@scalar/openapi-parser";
8
- import { deepEqual } from "fast-equals";
9
- import type { LoadedConfig } from "../../config/config.js";
10
- import type { Processor } from "../../config/validators/BuildSchema.js";
11
- import type { VersionConfig } from "../../config/validators/ZudokuConfig.js";
12
- import type { OpenAPIDocument } from "../../lib/oas/parser/index.js";
13
- import { ensureArray } from "../../lib/util/ensureArray.js";
14
- import { flattenAllOfProcessor } from "../../lib/util/flattenAllOfProcessor.js";
15
- import { joinUrl } from "../../lib/util/joinUrl.js";
16
- import { slugify } from "../../lib/util/slugify.js";
17
- import { generateCode } from "./schema-codegen.js";
18
-
19
- type ProcessedSchema = {
20
- schema: OpenAPIDocument;
21
- version: string;
22
- path: string;
23
- label?: string;
24
- inputPath: string;
25
- params: Record<string, string>;
26
- importKey: string;
27
- downloadUrl: string;
28
- processedJsonPath: string;
29
- processedTime: number;
30
- };
31
- const FALLBACK_VERSION = "default";
32
-
33
- type InputConfig = Partial<VersionConfig> & {
34
- input: string;
35
- params: Record<string, string>;
36
- };
37
-
38
- const parseInputString = (input: string) => {
39
- const idx = input.indexOf("?");
40
- if (idx === -1)
41
- return { filePath: input, params: {} as Record<string, string> };
42
- return {
43
- filePath: input.slice(0, idx),
44
- params: Object.fromEntries(new URLSearchParams(input.slice(idx))),
45
- };
46
- };
47
-
48
- const canonicalParams = (params: Record<string, string>) =>
49
- Object.entries(params)
50
- .sort(([a], [b]) => a.localeCompare(b))
51
- .map(([k, v]) => `${k}=${v}`)
52
- .join("&");
53
-
54
- const paramsSuffix = (params: Record<string, string>) => {
55
- const canonical = canonicalParams(params);
56
- return canonical ? `-${slugify(canonical)}` : "";
57
- };
58
-
59
- const paramsPath = (params: Record<string, string>) => {
60
- const canonical = canonicalParams(params);
61
- return canonical ? slugify(canonical) : "";
62
- };
63
-
64
- const normalizeInputs = (
65
- inputs:
66
- | string
67
- | InputConfig
68
- | Array<
69
- | string
70
- | (Omit<InputConfig, "params"> & { params?: Record<string, string> })
71
- >,
72
- ): InputConfig[] =>
73
- ensureArray(inputs).map((i) => {
74
- const raw = typeof i === "string" ? { input: i } : i;
75
- const { filePath, params } = parseInputString(raw.input);
76
- return { ...raw, input: filePath, params: { ...params, ...raw.params } };
77
- });
78
-
79
- export class SchemaManager {
80
- private storeDir: string;
81
- private processors: Processor[];
82
- private processedSchemas: Record<string, ProcessedSchema[]> = {};
83
- private referencedBy = new Map<string, Set<string>>();
84
- public config: LoadedConfig;
85
-
86
- constructor({
87
- storeDir,
88
- config,
89
- processors,
90
- }: {
91
- storeDir: string;
92
- config: LoadedConfig;
93
- processors: Processor[];
94
- }) {
95
- this.storeDir = storeDir;
96
- this.config = config;
97
- this.processors = [
98
- ({ schema }) => upgrade(schema).specification as OpenAPIDocument,
99
- flattenAllOfProcessor,
100
- ...processors,
101
- ];
102
- }
103
-
104
- private getPathForFile = (input: string, params: Record<string, string>) => {
105
- const filePath = path.resolve(this.config.__meta.rootDir, input);
106
-
107
- const apis = ensureArray(this.config.apis ?? []);
108
- for (const apiConfig of apis) {
109
- if (!apiConfig || apiConfig.type !== "file" || !apiConfig.path) continue;
110
-
111
- const match = normalizeInputs(apiConfig.input).some(
112
- (i) =>
113
- path.resolve(this.config.__meta.rootDir, i.input) === filePath &&
114
- deepEqual(i.params, params),
115
- );
116
- if (match) return apiConfig.path;
117
- }
118
- };
119
-
120
- public processSchema = async (input: InputConfig) => {
121
- const filePath = path.resolve(this.config.__meta.rootDir, input.input);
122
- const params = input.params;
123
- const configuredPath = this.getPathForFile(input.input, params);
124
- if (!configuredPath) {
125
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
126
- console.warn(`No path found for file ${input.input}`);
127
- return;
128
- }
129
-
130
- const parser = new $RefParser();
131
- const schema = await parser.bundle(filePath, {
132
- dereference: { preservedProperties: ["description", "summary"] },
133
- });
134
-
135
- this.referencedBy.set(filePath, new Set());
136
-
137
- parser.$refs
138
- .paths()
139
- .filter((file) => file !== filePath)
140
- .forEach((file) => {
141
- if (!this.referencedBy.has(file)) {
142
- this.referencedBy.set(file, new Set());
143
- }
144
- this.referencedBy.get(file)?.add(filePath);
145
- });
146
-
147
- const validatedSchema = await this.validateSchema(schema, filePath);
148
- const processedSchema = await this.processors.reduce(
149
- async (schema, processor) =>
150
- processor({
151
- schema: await schema,
152
- file: filePath,
153
- params,
154
- dereference: (schema) =>
155
- new $RefParser<OpenAPIDocument>().dereference(schema, {
156
- dereference: {
157
- preservedProperties: ["description", "summary"],
158
- circular: "ignore",
159
- },
160
- }),
161
- }),
162
- Promise.resolve(validatedSchema),
163
- );
164
-
165
- const processedTime = Date.now();
166
- const code = generateCode(processedSchema, filePath);
167
-
168
- const prefixPath = slugify(configuredPath);
169
- const processedFilePath = path.posix.join(
170
- this.storeDir,
171
- `${prefixPath}-${path.basename(filePath)}${paramsSuffix(params)}.js`,
172
- );
173
- const importKey = processedFilePath;
174
-
175
- await fs.writeFile(processedFilePath, code);
176
-
177
- const processedJsonPath = paramsSuffix(params)
178
- ? processedFilePath.replace(/\.js$/, ".json")
179
- : "";
180
- if (processedJsonPath) {
181
- await fs.writeFile(
182
- processedJsonPath,
183
- JSON.stringify(processedSchema, null, 2),
184
- );
185
- }
186
-
187
- const schemas = this.processedSchemas[configuredPath];
188
-
189
- if (!schemas) {
190
- throw new Error(`No schemas found for navigation ID ${configuredPath}.`);
191
- }
192
-
193
- const index = schemas.findIndex(
194
- (s) => s.inputPath === filePath && deepEqual(s.params, params),
195
- );
196
- const existingSchema = schemas[index];
197
-
198
- const schemaVersion = processedSchema.info.version ?? FALLBACK_VERSION;
199
- const versionPath =
200
- existingSchema?.path && existingSchema.path.length > 0
201
- ? existingSchema.path
202
- : paramsPath(params) || schemaVersion;
203
-
204
- const processed = {
205
- schema: processedSchema,
206
- version: schemaVersion,
207
- path: versionPath,
208
- label:
209
- existingSchema?.label ??
210
- (Object.keys(params).length > 0
211
- ? Object.values(params).join(", ")
212
- : undefined),
213
- inputPath: filePath,
214
- params,
215
- importKey,
216
- downloadUrl: this.createSchemaPath(
217
- filePath,
218
- versionPath,
219
- configuredPath,
220
- params,
221
- ),
222
- processedJsonPath,
223
- processedTime,
224
- } satisfies ProcessedSchema;
225
-
226
- if (index > -1) {
227
- schemas[index] = processed;
228
- } else {
229
- throw new Error(
230
- `Schema with input path ${filePath} was not pre-initialized for ${configuredPath}.`,
231
- );
232
- }
233
- return processed;
234
- };
235
-
236
- public getAllTrackedFiles = () => Array.from(this.referencedBy.keys());
237
-
238
- public getFilesToReprocess = (changedFile: string): InputConfig[] => {
239
- const resolvedPath = path.resolve(this.config.__meta.rootDir, changedFile);
240
- const referencedBy = this.referencedBy.get(resolvedPath);
241
-
242
- if (!referencedBy) return [];
243
-
244
- const filesToProcess =
245
- referencedBy.size === 0 ? [resolvedPath] : Array.from(referencedBy);
246
-
247
- return filesToProcess.flatMap((fp) => {
248
- const configs: InputConfig[] = [];
249
- for (const schemas of Object.values(this.processedSchemas)) {
250
- for (const s of schemas) {
251
- if (s.inputPath === fp) {
252
- configs.push({ input: fp, params: s.params });
253
- }
254
- }
255
- }
256
- return configs.length > 0 ? configs : [{ input: fp, params: {} }];
257
- });
258
- };
259
-
260
- public processAllSchemas = async () => {
261
- this.referencedBy.clear();
262
- this.processedSchemas = {};
263
-
264
- const apis = ensureArray(this.config.apis ?? []);
265
- for (const apiConfig of apis) {
266
- if (apiConfig.type !== "file" || !apiConfig.path) continue;
267
-
268
- const inputs = normalizeInputs(apiConfig.input);
269
- if (inputs.length === 0) throw new Error("No schema found");
270
-
271
- this.processedSchemas[apiConfig.path] = inputs.map((input) => ({
272
- schema: {} as OpenAPIDocument,
273
- version: "",
274
- path: input.path ?? "",
275
- label: input.label,
276
- inputPath: path.resolve(this.config.__meta.rootDir, input.input),
277
- params: input.params,
278
- importKey: "",
279
- downloadUrl: "",
280
- processedJsonPath: "",
281
- processedTime: 0,
282
- }));
283
-
284
- const results = await Promise.allSettled(
285
- inputs.map((input) => this.processSchema(input)),
286
- );
287
-
288
- const errors = results.flatMap((r) =>
289
- r.status === "rejected" ? r.reason : [],
290
- );
291
-
292
- if (errors.length > 0) {
293
- throw new Error(
294
- `Failed to process schemas for ${apiConfig.path}: ${errors.join(", ")}`,
295
- );
296
- }
297
- }
298
- };
299
-
300
- public getLatestSchema = (path: string) => this.processedSchemas[path]?.at(0);
301
-
302
- public getSchemasForPath = (path: string) => this.processedSchemas[path];
303
-
304
- public getSchemaImports = () =>
305
- Object.values(this.processedSchemas)
306
- .flat()
307
- .filter((s) => s.importKey);
308
-
309
- public getUrlToFilePathMap = () => {
310
- const map = new Map<string, string>();
311
-
312
- const apis = ensureArray(this.config.apis ?? []);
313
- for (const apiConfig of apis) {
314
- if (apiConfig.type !== "file" || !apiConfig.path) continue;
315
-
316
- const downloadEnabled =
317
- apiConfig.options?.schemaDownload?.enabled ??
318
- this.config.defaults?.apis?.schemaDownload?.enabled ??
319
- false;
320
-
321
- if (!downloadEnabled) continue;
322
-
323
- const schemas = this.processedSchemas[apiConfig.path];
324
-
325
- if (!schemas || schemas.length === 0) continue;
326
-
327
- for (const schema of schemas) {
328
- map.set(
329
- schema.downloadUrl,
330
- schema.processedJsonPath || schema.inputPath,
331
- );
332
- }
333
- }
334
-
335
- return map;
336
- };
337
-
338
- private createSchemaPath = (
339
- inputPath: string,
340
- versionPath: string,
341
- apiPath: string,
342
- params: Record<string, string>,
343
- ) => {
344
- const suffix = paramsSuffix(params);
345
- const extension = suffix ? ".json" : path.extname(inputPath);
346
-
347
- return joinUrl(
348
- this.config.basePath,
349
- apiPath,
350
- versionPath,
351
- `schema${suffix}${extension}`,
352
- );
353
- };
354
-
355
- private validateSchema = async (
356
- schema: JSONSchema,
357
- filePath: string,
358
- ): Promise<OpenAPIDocument> => {
359
- const validated = await validate(schema);
360
- if (validated.errors?.length) {
361
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
362
- console.warn(`Schema warnings in ${filePath}:`);
363
- for (const error of validated.errors) {
364
- // biome-ignore lint/suspicious/noConsole: Logging allowed here
365
- console.warn(error);
366
- }
367
- }
368
-
369
- return schema as OpenAPIDocument;
370
- };
371
- }
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import {
4
+ $RefParser,
5
+ type JSONSchema,
6
+ } from "@apidevtools/json-schema-ref-parser";
7
+ import { upgrade, validate } from "@scalar/openapi-parser";
8
+ import { deepEqual } from "fast-equals";
9
+ import type { LoadedConfig } from "../../config/config.js";
10
+ import type { Processor } from "../../config/validators/BuildSchema.js";
11
+ import type { VersionConfig } from "../../config/validators/ZudokuConfig.js";
12
+ import type { OpenAPIDocument } from "../../lib/oas/parser/index.js";
13
+ import { ensureArray } from "../../lib/util/ensureArray.js";
14
+ import { flattenAllOfProcessor } from "../../lib/util/flattenAllOfProcessor.js";
15
+ import { joinUrl } from "../../lib/util/joinUrl.js";
16
+ import { slugify } from "../../lib/util/slugify.js";
17
+ import { generateCode } from "./schema-codegen.js";
18
+
19
+ type ProcessedSchema = {
20
+ schema: OpenAPIDocument;
21
+ version: string;
22
+ path: string;
23
+ label?: string;
24
+ inputPath: string;
25
+ params: Record<string, string>;
26
+ /** The lookup key the browser uses for this schema: a file name, never a path of the build machine (API-127). */
27
+ importKey: string;
28
+ /** Absolute path of the processed module; only the build imports it. */
29
+ processedFilePath: string;
30
+ downloadUrl: string;
31
+ processedJsonPath: string;
32
+ processedTime: number;
33
+ };
34
+ const FALLBACK_VERSION = "default";
35
+
36
+ type InputConfig = Partial<VersionConfig> & {
37
+ input: string;
38
+ params: Record<string, string>;
39
+ };
40
+
41
+ const parseInputString = (input: string) => {
42
+ const idx = input.indexOf("?");
43
+ if (idx === -1)
44
+ return { filePath: input, params: {} as Record<string, string> };
45
+ return {
46
+ filePath: input.slice(0, idx),
47
+ params: Object.fromEntries(new URLSearchParams(input.slice(idx))),
48
+ };
49
+ };
50
+
51
+ const canonicalParams = (params: Record<string, string>) =>
52
+ Object.entries(params)
53
+ .sort(([a], [b]) => a.localeCompare(b))
54
+ .map(([k, v]) => `${k}=${v}`)
55
+ .join("&");
56
+
57
+ const paramsSuffix = (params: Record<string, string>) => {
58
+ const canonical = canonicalParams(params);
59
+ return canonical ? `-${slugify(canonical)}` : "";
60
+ };
61
+
62
+ const paramsPath = (params: Record<string, string>) => {
63
+ const canonical = canonicalParams(params);
64
+ return canonical ? slugify(canonical) : "";
65
+ };
66
+
67
+ const normalizeInputs = (
68
+ inputs:
69
+ | string
70
+ | InputConfig
71
+ | Array<
72
+ | string
73
+ | (Omit<InputConfig, "params"> & { params?: Record<string, string> })
74
+ >,
75
+ ): InputConfig[] =>
76
+ ensureArray(inputs).map((i) => {
77
+ const raw = typeof i === "string" ? { input: i } : i;
78
+ const { filePath, params } = parseInputString(raw.input);
79
+ return { ...raw, input: filePath, params: { ...params, ...raw.params } };
80
+ });
81
+
82
+ export class SchemaManager {
83
+ private storeDir: string;
84
+ private processors: Processor[];
85
+ private processedSchemas: Record<string, ProcessedSchema[]> = {};
86
+ private referencedBy = new Map<string, Set<string>>();
87
+ public config: LoadedConfig;
88
+
89
+ constructor({
90
+ storeDir,
91
+ config,
92
+ processors,
93
+ }: {
94
+ storeDir: string;
95
+ config: LoadedConfig;
96
+ processors: Processor[];
97
+ }) {
98
+ this.storeDir = storeDir;
99
+ this.config = config;
100
+ this.processors = [
101
+ ({ schema }) => upgrade(schema).specification as OpenAPIDocument,
102
+ flattenAllOfProcessor,
103
+ ...processors,
104
+ ];
105
+ }
106
+
107
+ private getPathForFile = (input: string, params: Record<string, string>) => {
108
+ const filePath = path.resolve(this.config.__meta.rootDir, input);
109
+
110
+ const apis = ensureArray(this.config.apis ?? []);
111
+ for (const apiConfig of apis) {
112
+ if (!apiConfig || apiConfig.type !== "file" || !apiConfig.path) continue;
113
+
114
+ const match = normalizeInputs(apiConfig.input).some(
115
+ (i) =>
116
+ path.resolve(this.config.__meta.rootDir, i.input) === filePath &&
117
+ deepEqual(i.params, params),
118
+ );
119
+ if (match) return apiConfig.path;
120
+ }
121
+ };
122
+
123
+ public processSchema = async (input: InputConfig) => {
124
+ const filePath = path.resolve(this.config.__meta.rootDir, input.input);
125
+ const params = input.params;
126
+ const configuredPath = this.getPathForFile(input.input, params);
127
+ if (!configuredPath) {
128
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
129
+ console.warn(`No path found for file ${input.input}`);
130
+ return;
131
+ }
132
+
133
+ const parser = new $RefParser();
134
+ const schema = await parser.bundle(filePath, {
135
+ dereference: { preservedProperties: ["description", "summary"] },
136
+ });
137
+
138
+ this.referencedBy.set(filePath, new Set());
139
+
140
+ parser.$refs
141
+ .paths()
142
+ .filter((file) => file !== filePath)
143
+ .forEach((file) => {
144
+ if (!this.referencedBy.has(file)) {
145
+ this.referencedBy.set(file, new Set());
146
+ }
147
+ this.referencedBy.get(file)?.add(filePath);
148
+ });
149
+
150
+ const validatedSchema = await this.validateSchema(schema, filePath);
151
+ const processedSchema = await this.processors.reduce(
152
+ async (schema, processor) =>
153
+ processor({
154
+ schema: await schema,
155
+ file: filePath,
156
+ params,
157
+ dereference: (schema) =>
158
+ new $RefParser<OpenAPIDocument>().dereference(schema, {
159
+ dereference: {
160
+ preservedProperties: ["description", "summary"],
161
+ circular: "ignore",
162
+ },
163
+ }),
164
+ }),
165
+ Promise.resolve(validatedSchema),
166
+ );
167
+
168
+ const processedTime = Date.now();
169
+ const code = generateCode(processedSchema, filePath);
170
+
171
+ const prefixPath = slugify(configuredPath);
172
+ const processedFilePath = path.posix.join(
173
+ this.storeDir,
174
+ `${prefixPath}-${path.basename(filePath)}${paramsSuffix(params)}.js`,
175
+ );
176
+ const importKey = path.posix.basename(processedFilePath);
177
+
178
+ await fs.writeFile(processedFilePath, code);
179
+
180
+ const processedJsonPath = paramsSuffix(params)
181
+ ? processedFilePath.replace(/\.js$/, ".json")
182
+ : "";
183
+ if (processedJsonPath) {
184
+ await fs.writeFile(
185
+ processedJsonPath,
186
+ JSON.stringify(processedSchema, null, 2),
187
+ );
188
+ }
189
+
190
+ const schemas = this.processedSchemas[configuredPath];
191
+
192
+ if (!schemas) {
193
+ throw new Error(`No schemas found for navigation ID ${configuredPath}.`);
194
+ }
195
+
196
+ const index = schemas.findIndex(
197
+ (s) => s.inputPath === filePath && deepEqual(s.params, params),
198
+ );
199
+ const existingSchema = schemas[index];
200
+
201
+ const schemaVersion = processedSchema.info.version ?? FALLBACK_VERSION;
202
+ const versionPath =
203
+ existingSchema?.path && existingSchema.path.length > 0
204
+ ? existingSchema.path
205
+ : paramsPath(params) || schemaVersion;
206
+
207
+ const processed = {
208
+ schema: processedSchema,
209
+ version: schemaVersion,
210
+ path: versionPath,
211
+ label:
212
+ existingSchema?.label ??
213
+ (Object.keys(params).length > 0
214
+ ? Object.values(params).join(", ")
215
+ : undefined),
216
+ inputPath: filePath,
217
+ params,
218
+ importKey,
219
+ processedFilePath,
220
+ downloadUrl: this.createSchemaPath(
221
+ filePath,
222
+ versionPath,
223
+ configuredPath,
224
+ params,
225
+ ),
226
+ processedJsonPath,
227
+ processedTime,
228
+ } satisfies ProcessedSchema;
229
+
230
+ if (index > -1) {
231
+ schemas[index] = processed;
232
+ } else {
233
+ throw new Error(
234
+ `Schema with input path ${filePath} was not pre-initialized for ${configuredPath}.`,
235
+ );
236
+ }
237
+ return processed;
238
+ };
239
+
240
+ public getAllTrackedFiles = () => Array.from(this.referencedBy.keys());
241
+
242
+ public getFilesToReprocess = (changedFile: string): InputConfig[] => {
243
+ const resolvedPath = path.resolve(this.config.__meta.rootDir, changedFile);
244
+ const referencedBy = this.referencedBy.get(resolvedPath);
245
+
246
+ if (!referencedBy) return [];
247
+
248
+ const filesToProcess =
249
+ referencedBy.size === 0 ? [resolvedPath] : Array.from(referencedBy);
250
+
251
+ return filesToProcess.flatMap((fp) => {
252
+ const configs: InputConfig[] = [];
253
+ for (const schemas of Object.values(this.processedSchemas)) {
254
+ for (const s of schemas) {
255
+ if (s.inputPath === fp) {
256
+ configs.push({ input: fp, params: s.params });
257
+ }
258
+ }
259
+ }
260
+ return configs.length > 0 ? configs : [{ input: fp, params: {} }];
261
+ });
262
+ };
263
+
264
+ public processAllSchemas = async () => {
265
+ this.referencedBy.clear();
266
+ this.processedSchemas = {};
267
+
268
+ const apis = ensureArray(this.config.apis ?? []);
269
+ for (const apiConfig of apis) {
270
+ if (apiConfig.type !== "file" || !apiConfig.path) continue;
271
+
272
+ const inputs = normalizeInputs(apiConfig.input);
273
+ if (inputs.length === 0) throw new Error("No schema found");
274
+
275
+ this.processedSchemas[apiConfig.path] = inputs.map((input) => ({
276
+ schema: {} as OpenAPIDocument,
277
+ version: "",
278
+ path: input.path ?? "",
279
+ label: input.label,
280
+ inputPath: path.resolve(this.config.__meta.rootDir, input.input),
281
+ params: input.params,
282
+ importKey: "",
283
+ processedFilePath: "",
284
+ downloadUrl: "",
285
+ processedJsonPath: "",
286
+ processedTime: 0,
287
+ }));
288
+
289
+ const results = await Promise.allSettled(
290
+ inputs.map((input) => this.processSchema(input)),
291
+ );
292
+
293
+ const errors = results.flatMap((r) =>
294
+ r.status === "rejected" ? r.reason : [],
295
+ );
296
+
297
+ if (errors.length > 0) {
298
+ throw new Error(
299
+ `Failed to process schemas for ${apiConfig.path}: ${errors.join(", ")}`,
300
+ );
301
+ }
302
+ }
303
+ };
304
+
305
+ public getLatestSchema = (path: string) => this.processedSchemas[path]?.at(0);
306
+
307
+ public getSchemasForPath = (path: string) => this.processedSchemas[path];
308
+
309
+ public getSchemaImports = () =>
310
+ Object.values(this.processedSchemas)
311
+ .flat()
312
+ .filter((s) => s.importKey);
313
+
314
+ public getUrlToFilePathMap = () => {
315
+ const map = new Map<string, string>();
316
+
317
+ const apis = ensureArray(this.config.apis ?? []);
318
+ for (const apiConfig of apis) {
319
+ if (apiConfig.type !== "file" || !apiConfig.path) continue;
320
+
321
+ const downloadEnabled =
322
+ apiConfig.options?.schemaDownload?.enabled ??
323
+ this.config.defaults?.apis?.schemaDownload?.enabled ??
324
+ false;
325
+
326
+ if (!downloadEnabled) continue;
327
+
328
+ const schemas = this.processedSchemas[apiConfig.path];
329
+
330
+ if (!schemas || schemas.length === 0) continue;
331
+
332
+ for (const schema of schemas) {
333
+ map.set(
334
+ schema.downloadUrl,
335
+ schema.processedJsonPath || schema.inputPath,
336
+ );
337
+ }
338
+ }
339
+
340
+ return map;
341
+ };
342
+
343
+ private createSchemaPath = (
344
+ inputPath: string,
345
+ versionPath: string,
346
+ apiPath: string,
347
+ params: Record<string, string>,
348
+ ) => {
349
+ const suffix = paramsSuffix(params);
350
+ const extension = suffix ? ".json" : path.extname(inputPath);
351
+
352
+ return joinUrl(
353
+ this.config.basePath,
354
+ apiPath,
355
+ versionPath,
356
+ `schema${suffix}${extension}`,
357
+ );
358
+ };
359
+
360
+ private validateSchema = async (
361
+ schema: JSONSchema,
362
+ filePath: string,
363
+ ): Promise<OpenAPIDocument> => {
364
+ const validated = await validate(schema);
365
+ if (validated.errors?.length) {
366
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
367
+ console.warn(`Schema warnings in ${filePath}:`);
368
+ for (const error of validated.errors) {
369
+ // biome-ignore lint/suspicious/noConsole: Logging allowed here
370
+ console.warn(error);
371
+ }
372
+ }
373
+
374
+ return schema as OpenAPIDocument;
375
+ };
376
+ }