orval 7.14.0 → 8.0.0-rc.0
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/bin/orval.js +20 -21
- package/dist/bin/orval.js.map +1 -1
- package/dist/{generate-B5LnJ5C4.js → generate-Cg1NHQEp.js} +248 -449
- package/dist/generate-Cg1NHQEp.js.map +1 -0
- package/dist/index.js +12 -21
- package/dist/index.js.map +1 -1
- package/package.json +27 -26
- package/dist/generate-B5LnJ5C4.js.map +0 -1
|
@@ -1,109 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
node_fs = __toESM(node_fs);
|
|
28
|
-
let node_path = require("node:path");
|
|
29
|
-
node_path = __toESM(node_path);
|
|
30
|
-
let node_process = require("node:process");
|
|
31
|
-
node_process = __toESM(node_process);
|
|
32
|
-
let node_url = require("node:url");
|
|
33
|
-
node_url = __toESM(node_url);
|
|
34
|
-
let __apidevtools_swagger_parser = require("@apidevtools/swagger-parser");
|
|
35
|
-
__apidevtools_swagger_parser = __toESM(__apidevtools_swagger_parser);
|
|
36
|
-
let chalk = require("chalk");
|
|
37
|
-
chalk = __toESM(chalk);
|
|
38
|
-
let fs_extra = require("fs-extra");
|
|
39
|
-
fs_extra = __toESM(fs_extra);
|
|
40
|
-
let js_yaml = require("js-yaml");
|
|
41
|
-
js_yaml = __toESM(js_yaml);
|
|
42
|
-
let __orval_mock = require("@orval/mock");
|
|
43
|
-
__orval_mock = __toESM(__orval_mock);
|
|
44
|
-
let __orval_angular = require("@orval/angular");
|
|
45
|
-
__orval_angular = __toESM(__orval_angular);
|
|
46
|
-
let __orval_axios = require("@orval/axios");
|
|
47
|
-
__orval_axios = __toESM(__orval_axios);
|
|
48
|
-
let __orval_fetch = require("@orval/fetch");
|
|
49
|
-
__orval_fetch = __toESM(__orval_fetch);
|
|
50
|
-
let __orval_hono = require("@orval/hono");
|
|
51
|
-
__orval_hono = __toESM(__orval_hono);
|
|
52
|
-
let __orval_mcp = require("@orval/mcp");
|
|
53
|
-
__orval_mcp = __toESM(__orval_mcp);
|
|
54
|
-
let __orval_query = require("@orval/query");
|
|
55
|
-
__orval_query = __toESM(__orval_query);
|
|
56
|
-
let __orval_swr = require("@orval/swr");
|
|
57
|
-
__orval_swr = __toESM(__orval_swr);
|
|
58
|
-
let __orval_zod = require("@orval/zod");
|
|
59
|
-
__orval_zod = __toESM(__orval_zod);
|
|
60
|
-
let node_https = require("node:https");
|
|
61
|
-
node_https = __toESM(node_https);
|
|
62
|
-
let enquirer = require("enquirer");
|
|
63
|
-
enquirer = __toESM(enquirer);
|
|
64
|
-
let find_up = require("find-up");
|
|
65
|
-
find_up = __toESM(find_up);
|
|
66
|
-
let tsconfck = require("tsconfck");
|
|
67
|
-
tsconfck = __toESM(tsconfck);
|
|
68
|
-
let execa = require("execa");
|
|
69
|
-
execa = __toESM(execa);
|
|
70
|
-
let lodash_uniq = require("lodash.uniq");
|
|
71
|
-
lodash_uniq = __toESM(lodash_uniq);
|
|
72
|
-
let string_argv = require("string-argv");
|
|
73
|
-
string_argv = __toESM(string_argv);
|
|
1
|
+
import { ErrorWithTag, FormDataArrayHandling, GetterPropType, NamingConvention, OutputClient, OutputHttpClient, OutputMode, PropertySortOrder, RefComponentSuffix, asyncReduce, createLogger, createSuccessMessage, dynamicImport, generateComponentDefinition, generateDependencyImports, generateParameterDefinition, generateSchemasDefinition, generateVerbsOptions, getFileInfo, getFullRoute, getMockFileExtensionByTypeName, getRoute, ibmOpenapiValidator, isBoolean, isFunction, isObject, isReference, isRootKey, isSchema, isString, isUndefined, isUrl, jsDoc, log, logError, mergeDeep, openApiConverter, pascal, removeFilesAndEmptyFolders, resolveRef, upath, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode } from "@orval/core";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process$1 from "node:process";
|
|
5
|
+
import url from "node:url";
|
|
6
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import fs$1 from "fs-extra";
|
|
9
|
+
import yaml from "js-yaml";
|
|
10
|
+
import * as mock from "@orval/mock";
|
|
11
|
+
import { DEFAULT_MOCK_OPTIONS, generateMockImports } from "@orval/mock";
|
|
12
|
+
import angular from "@orval/angular";
|
|
13
|
+
import axios from "@orval/axios";
|
|
14
|
+
import fetchClient from "@orval/fetch";
|
|
15
|
+
import hono from "@orval/hono";
|
|
16
|
+
import mcp from "@orval/mcp";
|
|
17
|
+
import query from "@orval/query";
|
|
18
|
+
import swr from "@orval/swr";
|
|
19
|
+
import zod from "@orval/zod";
|
|
20
|
+
import https from "node:https";
|
|
21
|
+
import enquirer from "enquirer";
|
|
22
|
+
import { findUp } from "find-up";
|
|
23
|
+
import { parse } from "tsconfck";
|
|
24
|
+
import { ExecaError, execa } from "execa";
|
|
25
|
+
import uniq from "lodash.uniq";
|
|
26
|
+
import { parseArgsStringToArgv } from "string-argv";
|
|
74
27
|
|
|
75
28
|
//#region src/client.ts
|
|
76
|
-
const DEFAULT_CLIENT =
|
|
29
|
+
const DEFAULT_CLIENT = OutputClient.AXIOS;
|
|
77
30
|
const getGeneratorClient = (outputClient, output) => {
|
|
78
31
|
const GENERATOR_CLIENT = {
|
|
79
|
-
axios: (
|
|
80
|
-
"axios-functions": (
|
|
81
|
-
angular: (
|
|
82
|
-
"react-query": (
|
|
32
|
+
axios: axios({ type: "axios" })(),
|
|
33
|
+
"axios-functions": axios({ type: "axios-functions" })(),
|
|
34
|
+
angular: angular()(),
|
|
35
|
+
"react-query": query({
|
|
83
36
|
output,
|
|
84
37
|
type: "react-query"
|
|
85
38
|
})(),
|
|
86
|
-
"svelte-query": (
|
|
39
|
+
"svelte-query": query({
|
|
87
40
|
output,
|
|
88
41
|
type: "svelte-query"
|
|
89
42
|
})(),
|
|
90
|
-
"vue-query": (
|
|
43
|
+
"vue-query": query({
|
|
91
44
|
output,
|
|
92
45
|
type: "vue-query"
|
|
93
46
|
})(),
|
|
94
|
-
swr: (
|
|
95
|
-
zod: (
|
|
96
|
-
hono: (
|
|
97
|
-
fetch: (
|
|
98
|
-
mcp: (
|
|
47
|
+
swr: swr()(),
|
|
48
|
+
zod: zod()(),
|
|
49
|
+
hono: hono()(),
|
|
50
|
+
fetch: fetchClient()(),
|
|
51
|
+
mcp: mcp()()
|
|
99
52
|
};
|
|
100
|
-
const generator =
|
|
53
|
+
const generator = isFunction(outputClient) ? outputClient(GENERATOR_CLIENT) : GENERATOR_CLIENT[outputClient];
|
|
101
54
|
if (!generator) throw new Error(`Oups... 🍻. Client not found: ${outputClient}`);
|
|
102
55
|
return generator;
|
|
103
56
|
};
|
|
104
57
|
const generateClientImports = ({ client = DEFAULT_CLIENT, implementation, imports, specsName, hasSchemaDir, isAllowSyntheticDefaultImports, hasGlobalMutator, hasTagsMutator, hasParamsSerializerOptions, packageJson, output }) => {
|
|
105
|
-
const { dependencies
|
|
106
|
-
return
|
|
58
|
+
const { dependencies } = getGeneratorClient(client, output);
|
|
59
|
+
return generateDependencyImports(implementation, dependencies ? [...dependencies(hasGlobalMutator, hasParamsSerializerOptions, packageJson, output.httpClient, hasTagsMutator, output.override), ...imports] : imports, specsName, hasSchemaDir, isAllowSyntheticDefaultImports);
|
|
107
60
|
};
|
|
108
61
|
const generateClientHeader = ({ outputClient = DEFAULT_CLIENT, isRequestOptions, isGlobalMutator, isMutator, provideIn, hasAwaitedType, titles, output, verbOptions, tag, clientImplementation }) => {
|
|
109
62
|
const { header } = getGeneratorClient(outputClient, output);
|
|
@@ -131,7 +84,7 @@ const generateClientFooter = ({ outputClient = DEFAULT_CLIENT, operationNames, h
|
|
|
131
84
|
};
|
|
132
85
|
let implementation;
|
|
133
86
|
try {
|
|
134
|
-
if (
|
|
87
|
+
if (isFunction(outputClient)) {
|
|
135
88
|
implementation = footer(operationNames);
|
|
136
89
|
console.warn("[WARN] Passing an array of strings for operations names to the footer function is deprecated and will be removed in a future major release. Please pass them in an object instead: { operationNames: string[] }.");
|
|
137
90
|
} else implementation = footer({
|
|
@@ -157,18 +110,18 @@ const generateClientTitle = ({ outputClient = DEFAULT_CLIENT, title, customTitle
|
|
|
157
110
|
const { title: generatorTitle } = getGeneratorClient(outputClient, output);
|
|
158
111
|
if (!generatorTitle) return {
|
|
159
112
|
implementation: "",
|
|
160
|
-
implementationMock: `get${
|
|
113
|
+
implementationMock: `get${pascal(title)}Mock`
|
|
161
114
|
};
|
|
162
115
|
if (customTitleFunc) {
|
|
163
116
|
const customTitle = customTitleFunc(title);
|
|
164
117
|
return {
|
|
165
118
|
implementation: generatorTitle(customTitle),
|
|
166
|
-
implementationMock: `get${
|
|
119
|
+
implementationMock: `get${pascal(customTitle)}Mock`
|
|
167
120
|
};
|
|
168
121
|
}
|
|
169
122
|
return {
|
|
170
123
|
implementation: generatorTitle(title),
|
|
171
|
-
implementationMock: `get${
|
|
124
|
+
implementationMock: `get${pascal(title)}Mock`
|
|
172
125
|
};
|
|
173
126
|
};
|
|
174
127
|
const generateMock = (verbOption, options) => {
|
|
@@ -180,11 +133,11 @@ const generateMock = (verbOption, options) => {
|
|
|
180
133
|
},
|
|
181
134
|
imports: []
|
|
182
135
|
};
|
|
183
|
-
if (
|
|
184
|
-
return
|
|
136
|
+
if (isFunction(options.mock)) return options.mock(verbOption, options);
|
|
137
|
+
return mock.generateMock(verbOption, options);
|
|
185
138
|
};
|
|
186
139
|
const generateOperations = (outputClient = DEFAULT_CLIENT, verbsOptions, options, output) => {
|
|
187
|
-
return
|
|
140
|
+
return asyncReduce(verbsOptions, async (acc, verbOption) => {
|
|
188
141
|
const { client: generatorClient } = getGeneratorClient(outputClient, output);
|
|
189
142
|
const client = await generatorClient(verbOption, options, outputClient);
|
|
190
143
|
if (!client.implementation) return acc;
|
|
@@ -215,19 +168,19 @@ const generateExtraFiles = (outputClient = DEFAULT_CLIENT, verbsOptions, output,
|
|
|
215
168
|
//#endregion
|
|
216
169
|
//#region src/api.ts
|
|
217
170
|
const getApiBuilder = async ({ input, output, context }) => {
|
|
218
|
-
const api = await
|
|
219
|
-
const route =
|
|
171
|
+
const api = await asyncReduce(Object.entries(context.specs[context.specKey].paths ?? {}), async (acc, [pathRoute, verbs]) => {
|
|
172
|
+
const route = getRoute(pathRoute);
|
|
220
173
|
let resolvedVerbs = verbs;
|
|
221
174
|
let resolvedContext = context;
|
|
222
|
-
if (
|
|
223
|
-
const { schema, imports } =
|
|
175
|
+
if (isReference(verbs)) {
|
|
176
|
+
const { schema, imports } = resolveRef(verbs, context);
|
|
224
177
|
resolvedVerbs = schema;
|
|
225
178
|
resolvedContext = {
|
|
226
179
|
...context,
|
|
227
180
|
...imports.length > 0 ? { specKey: imports[0].specKey } : {}
|
|
228
181
|
};
|
|
229
182
|
}
|
|
230
|
-
let verbsOptions = await
|
|
183
|
+
let verbsOptions = await generateVerbsOptions({
|
|
231
184
|
verbs: resolvedVerbs,
|
|
232
185
|
input,
|
|
233
186
|
output,
|
|
@@ -239,13 +192,13 @@ const getApiBuilder = async ({ input, output, context }) => {
|
|
|
239
192
|
return !verb.deprecated;
|
|
240
193
|
});
|
|
241
194
|
const schemas = verbsOptions.reduce((acc$1, { queryParams, headers, body, response, props }) => {
|
|
242
|
-
if (props) acc$1.push(...props.flatMap((param) => param.type ===
|
|
195
|
+
if (props) acc$1.push(...props.flatMap((param) => param.type === GetterPropType.NAMED_PATH_PARAMS ? param.schema : []));
|
|
243
196
|
if (queryParams) acc$1.push(queryParams.schema, ...queryParams.deps);
|
|
244
197
|
if (headers) acc$1.push(headers.schema, ...headers.deps);
|
|
245
198
|
acc$1.push(...body.schemas, ...response.schemas);
|
|
246
199
|
return acc$1;
|
|
247
200
|
}, []);
|
|
248
|
-
const fullRoute =
|
|
201
|
+
const fullRoute = getFullRoute(route, verbs.servers ?? context.specs[context.specKey].servers, output.baseUrl);
|
|
249
202
|
if (!output.target) throw new Error("Output does not have a target");
|
|
250
203
|
const pathOperations = await generateOperations(output.client, verbsOptions, {
|
|
251
204
|
route: fullRoute,
|
|
@@ -276,7 +229,7 @@ const getApiBuilder = async ({ input, output, context }) => {
|
|
|
276
229
|
header: generateClientHeader,
|
|
277
230
|
footer: generateClientFooter,
|
|
278
231
|
imports: generateClientImports,
|
|
279
|
-
importsMock:
|
|
232
|
+
importsMock: generateMockImports,
|
|
280
233
|
extraFiles
|
|
281
234
|
};
|
|
282
235
|
};
|
|
@@ -318,11 +271,11 @@ const importOpenApi = async ({ data, input, output, target, workspace }) => {
|
|
|
318
271
|
};
|
|
319
272
|
};
|
|
320
273
|
const generateInputSpecs = async ({ specs, input, workspace }) => {
|
|
321
|
-
const transformerFn = input.override?.transformer ? await
|
|
322
|
-
return
|
|
323
|
-
const schema = await
|
|
274
|
+
const transformerFn = input.override?.transformer ? await dynamicImport(input.override.transformer, workspace) : void 0;
|
|
275
|
+
return asyncReduce(Object.entries(specs), async (acc, [specKey, value]) => {
|
|
276
|
+
const schema = await openApiConverter(value, input.converterOptions, specKey);
|
|
324
277
|
const transfomedSchema = transformerFn ? transformerFn(schema) : schema;
|
|
325
|
-
if (input.validation) await
|
|
278
|
+
if (input.validation) await ibmOpenapiValidator(transfomedSchema, input.validation);
|
|
326
279
|
acc[specKey] = transfomedSchema;
|
|
327
280
|
return acc;
|
|
328
281
|
}, {});
|
|
@@ -336,11 +289,10 @@ const getApiSchemas = ({ input, output, target, workspace, specs }) => {
|
|
|
336
289
|
specs,
|
|
337
290
|
output
|
|
338
291
|
};
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
const parameters = (0, __orval_core.generateParameterDefinition)(spec.components?.parameters, context, output.override.components.parameters.suffix);
|
|
292
|
+
const schemaDefinition = generateSchemasDefinition(spec.openapi ? spec.components?.schemas : getAllSchemas(spec, specKey), context, output.override.components.schemas.suffix, input.filters);
|
|
293
|
+
const responseDefinition = generateComponentDefinition(spec.components?.responses, context, output.override.components.responses.suffix);
|
|
294
|
+
const bodyDefinition = generateComponentDefinition(spec.components?.requestBodies, context, output.override.components.requestBodies.suffix);
|
|
295
|
+
const parameters = generateParameterDefinition(spec.components?.parameters, context, output.override.components.parameters.suffix);
|
|
344
296
|
const schemas = [
|
|
345
297
|
...schemaDefinition,
|
|
346
298
|
...responseDefinition,
|
|
@@ -364,8 +316,8 @@ const getAllSchemas = (spec, specKey) => {
|
|
|
364
316
|
"externalDocs"
|
|
365
317
|
]);
|
|
366
318
|
const cleanedSpec = Object.fromEntries(Object.entries(spec).filter(([key]) => !keysToOmit.has(key)));
|
|
367
|
-
if (specKey &&
|
|
368
|
-
const name$1 =
|
|
319
|
+
if (specKey && isSchema(cleanedSpec)) {
|
|
320
|
+
const name$1 = upath.getSchemaFileName(specKey);
|
|
369
321
|
const additionalKeysToOmit = new Set([
|
|
370
322
|
"type",
|
|
371
323
|
"properties",
|
|
@@ -381,8 +333,8 @@ const getAllSchemas = (spec, specKey) => {
|
|
|
381
333
|
}
|
|
382
334
|
return {
|
|
383
335
|
...Object.entries(cleanedSpec).reduce((acc, [key, value]) => {
|
|
384
|
-
if (!
|
|
385
|
-
if (!
|
|
336
|
+
if (!isObject(value)) return acc;
|
|
337
|
+
if (!isSchema(value) && !isReference(value)) return {
|
|
386
338
|
...acc,
|
|
387
339
|
...getAllSchemas(value)
|
|
388
340
|
};
|
|
@@ -398,32 +350,31 @@ const getAllSchemas = (spec, specKey) => {
|
|
|
398
350
|
const resolveSpecs = async (path$1, { validate,...options }, _isUrl, isOnlySchema) => {
|
|
399
351
|
try {
|
|
400
352
|
if (validate) try {
|
|
401
|
-
await
|
|
353
|
+
await SwaggerParser.validate(path$1, options);
|
|
402
354
|
} catch (error) {
|
|
403
355
|
if (error instanceof Error && error.name === "ParserError") throw error;
|
|
404
|
-
if (!isOnlySchema)
|
|
356
|
+
if (!isOnlySchema) log(`⚠️ ${chalk.yellow(error)}`);
|
|
405
357
|
}
|
|
406
|
-
const data = (await
|
|
358
|
+
const data = (await SwaggerParser.resolve(path$1, options)).values();
|
|
407
359
|
if (_isUrl) return data;
|
|
408
|
-
return Object.fromEntries(Object.entries(data).sort().map(([key, value]) => [
|
|
360
|
+
return Object.fromEntries(Object.entries(data).sort().map(([key, value]) => [isUrl(key) ? key : upath.resolve(key), value]));
|
|
409
361
|
} catch {
|
|
410
|
-
const file = await
|
|
411
|
-
return { [path$1]:
|
|
362
|
+
const file = await fs$1.readFile(path$1, "utf8");
|
|
363
|
+
return { [path$1]: yaml.load(file) };
|
|
412
364
|
}
|
|
413
365
|
};
|
|
414
366
|
const importSpecs = async (workspace, options) => {
|
|
415
367
|
const { input, output } = options;
|
|
416
|
-
if (!
|
|
368
|
+
if (!isString(input.target)) return importOpenApi({
|
|
417
369
|
data: { [workspace]: input.target },
|
|
418
370
|
input,
|
|
419
371
|
output,
|
|
420
372
|
target: workspace,
|
|
421
373
|
workspace
|
|
422
374
|
});
|
|
423
|
-
const isPathUrl =
|
|
424
|
-
const data = await resolveSpecs(input.target, input.parserOptions, isPathUrl, !output.target);
|
|
375
|
+
const isPathUrl = isUrl(input.target);
|
|
425
376
|
return importOpenApi({
|
|
426
|
-
data,
|
|
377
|
+
data: await resolveSpecs(input.target, input.parserOptions, isPathUrl, !output.target),
|
|
427
378
|
input,
|
|
428
379
|
output,
|
|
429
380
|
target: input.target,
|
|
@@ -435,120 +386,13 @@ const importSpecs = async (workspace, options) => {
|
|
|
435
386
|
//#region package.json
|
|
436
387
|
var name = "orval";
|
|
437
388
|
var description = "A swagger client generator for typescript";
|
|
438
|
-
var version = "
|
|
439
|
-
var license = "MIT";
|
|
440
|
-
var files = ["dist", "!dist/**/*.d.ts.map"];
|
|
441
|
-
var bin = "./dist/bin/orval.js";
|
|
442
|
-
var type = "commonjs";
|
|
443
|
-
var exports$1 = { ".": {
|
|
444
|
-
"types": "./dist/index.d.ts",
|
|
445
|
-
"default": "./dist/index.js"
|
|
446
|
-
} };
|
|
447
|
-
var engines = { "node": ">=22.18.0" };
|
|
448
|
-
var keywords = [
|
|
449
|
-
"rest",
|
|
450
|
-
"client",
|
|
451
|
-
"swagger",
|
|
452
|
-
"open-api",
|
|
453
|
-
"fetch",
|
|
454
|
-
"data fetching",
|
|
455
|
-
"code-generation",
|
|
456
|
-
"angular",
|
|
457
|
-
"react",
|
|
458
|
-
"react-query",
|
|
459
|
-
"svelte",
|
|
460
|
-
"svelte-query",
|
|
461
|
-
"vue",
|
|
462
|
-
"vue-query",
|
|
463
|
-
"msw",
|
|
464
|
-
"mock",
|
|
465
|
-
"axios",
|
|
466
|
-
"vue-query",
|
|
467
|
-
"vue",
|
|
468
|
-
"swr",
|
|
469
|
-
"zod",
|
|
470
|
-
"hono"
|
|
471
|
-
];
|
|
472
|
-
var author = {
|
|
473
|
-
"name": "Victor Bury",
|
|
474
|
-
"email": "victor@anymaniax.com"
|
|
475
|
-
};
|
|
476
|
-
var repository = {
|
|
477
|
-
"type": "git",
|
|
478
|
-
"url": "git+https://github.com/orval-labs/orval.git"
|
|
479
|
-
};
|
|
480
|
-
var scripts = {
|
|
481
|
-
"build": "tsdown --config-loader unconfig",
|
|
482
|
-
"dev": "tsdown --config-loader unconfig --watch src --onSuccess 'yarn generate-api'",
|
|
483
|
-
"lint": "eslint .",
|
|
484
|
-
"generate-api": "orval --config ../../samples/react-query/basic/orval.config.ts",
|
|
485
|
-
"test": "tsc --noEmit && vitest",
|
|
486
|
-
"clean": "rimraf .turbo dist",
|
|
487
|
-
"nuke": "rimraf .turbo dist node_modules"
|
|
488
|
-
};
|
|
489
|
-
var devDependencies = {
|
|
490
|
-
"@types/fs-extra": "^11.0.4",
|
|
491
|
-
"@types/js-yaml": "^4.0.9",
|
|
492
|
-
"@types/lodash.uniq": "^4.5.9",
|
|
493
|
-
"eslint": "^9.35.0",
|
|
494
|
-
"openapi-types": "^12.1.3",
|
|
495
|
-
"rimraf": "^6.0.1",
|
|
496
|
-
"tsdown": "^0.15.2",
|
|
497
|
-
"typescript": "^5.9.2",
|
|
498
|
-
"vitest": "^3.2.4"
|
|
499
|
-
};
|
|
500
|
-
var dependencies = {
|
|
501
|
-
"@apidevtools/swagger-parser": "^12.0.0",
|
|
502
|
-
"@commander-js/extra-typings": "^14.0.0",
|
|
503
|
-
"@orval/angular": "workspace:*",
|
|
504
|
-
"@orval/axios": "workspace:*",
|
|
505
|
-
"@orval/core": "workspace:*",
|
|
506
|
-
"@orval/fetch": "workspace:*",
|
|
507
|
-
"@orval/hono": "workspace:*",
|
|
508
|
-
"@orval/mcp": "workspace:*",
|
|
509
|
-
"@orval/mock": "workspace:*",
|
|
510
|
-
"@orval/query": "workspace:*",
|
|
511
|
-
"@orval/swr": "workspace:*",
|
|
512
|
-
"@orval/zod": "workspace:*",
|
|
513
|
-
"chalk": "^4.1.2",
|
|
514
|
-
"chokidar": "^4.0.3",
|
|
515
|
-
"commander": "^14.0.1",
|
|
516
|
-
"enquirer": "^2.4.1",
|
|
517
|
-
"execa": "^5.1.1",
|
|
518
|
-
"find-up": "5.0.0",
|
|
519
|
-
"fs-extra": "^11.3.1",
|
|
520
|
-
"js-yaml": "4.1.0",
|
|
521
|
-
"lodash.uniq": "^4.5.0",
|
|
522
|
-
"openapi3-ts": "4.5.0",
|
|
523
|
-
"string-argv": "^0.3.2",
|
|
524
|
-
"tsconfck": "^2.1.2",
|
|
525
|
-
"typedoc": "^0.28.12",
|
|
526
|
-
"typedoc-plugin-coverage": "^4.0.1",
|
|
527
|
-
"typedoc-plugin-markdown": "^4.8.1"
|
|
528
|
-
};
|
|
529
|
-
var package_default = {
|
|
530
|
-
name,
|
|
531
|
-
description,
|
|
532
|
-
version,
|
|
533
|
-
license,
|
|
534
|
-
files,
|
|
535
|
-
bin,
|
|
536
|
-
type,
|
|
537
|
-
exports: exports$1,
|
|
538
|
-
engines,
|
|
539
|
-
keywords,
|
|
540
|
-
author,
|
|
541
|
-
repository,
|
|
542
|
-
scripts,
|
|
543
|
-
devDependencies,
|
|
544
|
-
dependencies
|
|
545
|
-
};
|
|
389
|
+
var version = "8.0.0-rc.0";
|
|
546
390
|
|
|
547
391
|
//#endregion
|
|
548
392
|
//#region src/utils/request.ts
|
|
549
393
|
const request = (urlOptions, data) => {
|
|
550
394
|
return new Promise((resolve, reject) => {
|
|
551
|
-
const req =
|
|
395
|
+
const req = https.request(urlOptions, (res) => {
|
|
552
396
|
let body = "";
|
|
553
397
|
res.on("data", (chunk) => body += chunk.toString());
|
|
554
398
|
res.on("error", reject);
|
|
@@ -595,9 +439,9 @@ const getGithubSpecReq = ({ accessToken, repo, owner, branch, path: path$1 }) =>
|
|
|
595
439
|
let githubToken = null;
|
|
596
440
|
const getGithubAcessToken = async (githubTokenPath) => {
|
|
597
441
|
if (githubToken) return githubToken;
|
|
598
|
-
if (await
|
|
442
|
+
if (await fs$1.pathExists(githubTokenPath)) return fs$1.readFile(githubTokenPath, "utf8");
|
|
599
443
|
else {
|
|
600
|
-
const answers = await
|
|
444
|
+
const answers = await enquirer.prompt([{
|
|
601
445
|
type: "input",
|
|
602
446
|
name: "githubToken",
|
|
603
447
|
message: "Please provide a GitHub token with `repo` rules checked (https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)"
|
|
@@ -607,12 +451,12 @@ const getGithubAcessToken = async (githubTokenPath) => {
|
|
|
607
451
|
message: "Would you like to store your token for the next time? (stored in your node_modules)"
|
|
608
452
|
}]);
|
|
609
453
|
githubToken = answers.githubToken;
|
|
610
|
-
if (answers.saveToken) await
|
|
454
|
+
if (answers.saveToken) await fs$1.outputFile(githubTokenPath, answers.githubToken);
|
|
611
455
|
return answers.githubToken;
|
|
612
456
|
}
|
|
613
457
|
};
|
|
614
458
|
const getGithubOpenApi = async (url$1) => {
|
|
615
|
-
const githubTokenPath =
|
|
459
|
+
const githubTokenPath = upath.join(import.meta.dirname, ".githubToken");
|
|
616
460
|
const accessToken = await getGithubAcessToken(githubTokenPath);
|
|
617
461
|
const [info] = url$1.split("github.com/").slice(-1);
|
|
618
462
|
const [owner, repo, , branch, ...paths] = info.split("/");
|
|
@@ -627,22 +471,22 @@ const getGithubOpenApi = async (url$1) => {
|
|
|
627
471
|
}));
|
|
628
472
|
if (body.errors?.length) {
|
|
629
473
|
if (body.errors?.some((error) => error?.type === "NOT_FOUND")) {
|
|
630
|
-
if ((await
|
|
474
|
+
if ((await enquirer.prompt([{
|
|
631
475
|
type: "confirm",
|
|
632
476
|
name: "removeToken",
|
|
633
477
|
message: "Your token doesn't have the correct permissions, should we remove it?"
|
|
634
|
-
}])).removeToken) await
|
|
478
|
+
}])).removeToken) await fs$1.unlink(githubTokenPath);
|
|
635
479
|
}
|
|
636
480
|
}
|
|
637
481
|
return body.data?.repository?.object.text;
|
|
638
482
|
} catch (error) {
|
|
639
483
|
if (!error.body) throw new Error(`Oups... 🍻. ${error}`);
|
|
640
484
|
if (error.body.message === "Bad credentials") {
|
|
641
|
-
if ((await
|
|
485
|
+
if ((await enquirer.prompt([{
|
|
642
486
|
type: "confirm",
|
|
643
487
|
name: "removeToken",
|
|
644
488
|
message: "Your token doesn't have the correct permissions, should we remove it?"
|
|
645
|
-
}])).removeToken) await
|
|
489
|
+
}])).removeToken) await fs$1.unlink(githubTokenPath);
|
|
646
490
|
}
|
|
647
491
|
throw new Error(error.body.message || `Oups... 🍻. ${error}`);
|
|
648
492
|
}
|
|
@@ -657,21 +501,25 @@ const githubResolver = {
|
|
|
657
501
|
}
|
|
658
502
|
};
|
|
659
503
|
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/utils/http-resolver.ts
|
|
506
|
+
const httpResolver = { safeUrlResolver: false };
|
|
507
|
+
|
|
660
508
|
//#endregion
|
|
661
509
|
//#region src/utils/package-json.ts
|
|
662
510
|
const loadPackageJson = async (packageJson, workspace = process.cwd()) => {
|
|
663
511
|
if (!packageJson) {
|
|
664
|
-
const pkgPath = await (
|
|
512
|
+
const pkgPath = await findUp(["package.json"], { cwd: workspace });
|
|
665
513
|
if (pkgPath) {
|
|
666
|
-
const pkg = await
|
|
514
|
+
const pkg = await dynamicImport(pkgPath, workspace);
|
|
667
515
|
if (isPackageJson(pkg)) return await maybeReplaceCatalog(pkg, workspace);
|
|
668
516
|
else throw new Error("Invalid package.json file");
|
|
669
517
|
}
|
|
670
518
|
return;
|
|
671
519
|
}
|
|
672
520
|
const normalizedPath = normalizePath(packageJson, workspace);
|
|
673
|
-
if (
|
|
674
|
-
const pkg = await
|
|
521
|
+
if (fs$1.existsSync(normalizedPath)) {
|
|
522
|
+
const pkg = await dynamicImport(normalizedPath);
|
|
675
523
|
if (isPackageJson(pkg)) return await maybeReplaceCatalog(pkg, workspace);
|
|
676
524
|
else throw new Error(`Invalid package.json file: ${normalizedPath}`);
|
|
677
525
|
}
|
|
@@ -682,71 +530,67 @@ const maybeReplaceCatalog = async (pkg, workspace) => {
|
|
|
682
530
|
...Object.entries(pkg.dependencies ?? {}),
|
|
683
531
|
...Object.entries(pkg.devDependencies ?? {}),
|
|
684
532
|
...Object.entries(pkg.peerDependencies ?? {})
|
|
685
|
-
].some(([, value]) =>
|
|
686
|
-
const filePath = await (
|
|
533
|
+
].some(([, value]) => isString(value) && value.startsWith("catalog:"))) return pkg;
|
|
534
|
+
const filePath = await findUp("pnpm-workspace.yaml", { cwd: workspace });
|
|
687
535
|
if (!filePath) {
|
|
688
|
-
|
|
536
|
+
log(`⚠️ ${chalk.yellow("package.json contains pnpm catalog: in dependencies, but no pnpm-workspace.yaml was found.")}`);
|
|
689
537
|
return pkg;
|
|
690
538
|
}
|
|
691
|
-
const file = await
|
|
692
|
-
const pnpmWorkspaceFile =
|
|
539
|
+
const file = await fs$1.readFile(filePath, "utf8");
|
|
540
|
+
const pnpmWorkspaceFile = yaml.load(file);
|
|
693
541
|
performSubstitution(pkg.dependencies, pnpmWorkspaceFile);
|
|
694
542
|
performSubstitution(pkg.devDependencies, pnpmWorkspaceFile);
|
|
695
543
|
performSubstitution(pkg.peerDependencies, pnpmWorkspaceFile);
|
|
696
544
|
return pkg;
|
|
697
545
|
};
|
|
698
|
-
const performSubstitution = (dependencies
|
|
699
|
-
if (!dependencies
|
|
700
|
-
for (const [packageName, version$1] of Object.entries(dependencies
|
|
546
|
+
const performSubstitution = (dependencies, pnpmWorkspaceFile) => {
|
|
547
|
+
if (!dependencies) return;
|
|
548
|
+
for (const [packageName, version$1] of Object.entries(dependencies)) if (version$1 === "catalog:" || version$1 === "catalog:default") {
|
|
701
549
|
if (!pnpmWorkspaceFile.catalog) {
|
|
702
|
-
|
|
550
|
+
log(`⚠️ ${chalk.yellow(`when reading from pnpm-workspace.yaml, catalog: substitution for the package '${packageName}' failed as there were no default catalog.`)}`);
|
|
703
551
|
continue;
|
|
704
552
|
}
|
|
705
553
|
const sub = pnpmWorkspaceFile.catalog[packageName];
|
|
706
554
|
if (!sub) {
|
|
707
|
-
|
|
555
|
+
log(`⚠️ ${chalk.yellow(`when reading from pnpm-workspace.yaml, catalog: substitution for the package '${packageName}' failed as there were no matching package in the default catalog.`)}`);
|
|
708
556
|
continue;
|
|
709
557
|
}
|
|
710
|
-
dependencies
|
|
558
|
+
dependencies[packageName] = sub;
|
|
711
559
|
} else if (version$1.startsWith("catalog:")) {
|
|
712
560
|
const catalogName = version$1.slice(8);
|
|
713
561
|
const catalog = pnpmWorkspaceFile.catalogs?.[catalogName];
|
|
714
562
|
if (!catalog) {
|
|
715
|
-
|
|
563
|
+
log(`⚠️ ${chalk.yellow(`when reading from pnpm-workspace.yaml, '${version$1}' substitution for the package '${packageName}' failed as there were no matching catalog named '${catalogName}'. (available named catalogs are: ${Object.keys(pnpmWorkspaceFile.catalogs ?? {}).join(", ")})`)}`);
|
|
716
564
|
continue;
|
|
717
565
|
}
|
|
718
566
|
const sub = catalog[packageName];
|
|
719
567
|
if (!sub) {
|
|
720
|
-
|
|
568
|
+
log(`⚠️ ${chalk.yellow(`when reading from pnpm-workspace.yaml, '${version$1}' substitution for the package '${packageName}' failed as there were no package in the catalog named '${catalogName}'. (packages in the catalog are: ${Object.keys(catalog).join(", ")})`)}`);
|
|
721
569
|
continue;
|
|
722
570
|
}
|
|
723
|
-
dependencies
|
|
571
|
+
dependencies[packageName] = sub;
|
|
724
572
|
}
|
|
725
573
|
};
|
|
726
574
|
|
|
727
575
|
//#endregion
|
|
728
576
|
//#region src/utils/tsconfig.ts
|
|
729
577
|
const loadTsconfig = async (tsconfig, workspace = process.cwd()) => {
|
|
730
|
-
if (
|
|
731
|
-
const configPath = await (
|
|
732
|
-
if (configPath) return (await
|
|
578
|
+
if (isUndefined(tsconfig)) {
|
|
579
|
+
const configPath = await findUp(["tsconfig.json", "jsconfig.json"], { cwd: workspace });
|
|
580
|
+
if (configPath) return (await parse(configPath)).tsconfig;
|
|
733
581
|
return;
|
|
734
582
|
}
|
|
735
|
-
if (
|
|
583
|
+
if (isString(tsconfig)) {
|
|
736
584
|
const normalizedPath = normalizePath(tsconfig, workspace);
|
|
737
|
-
if (
|
|
738
|
-
const config = await
|
|
585
|
+
if (fs$1.existsSync(normalizedPath)) {
|
|
586
|
+
const config = await parse(normalizedPath);
|
|
739
587
|
return config.referenced?.find(({ tsconfigFile }) => tsconfigFile === normalizedPath)?.tsconfig || config.tsconfig;
|
|
740
588
|
}
|
|
741
589
|
return;
|
|
742
590
|
}
|
|
743
|
-
if (
|
|
591
|
+
if (isObject(tsconfig)) return tsconfig;
|
|
744
592
|
};
|
|
745
593
|
|
|
746
|
-
//#endregion
|
|
747
|
-
//#region src/utils/http-resolver.ts
|
|
748
|
-
const httpResolver = { safeUrlResolver: false };
|
|
749
|
-
|
|
750
594
|
//#endregion
|
|
751
595
|
//#region src/utils/options.ts
|
|
752
596
|
/**
|
|
@@ -757,16 +601,16 @@ function defineConfig(options) {
|
|
|
757
601
|
return options;
|
|
758
602
|
}
|
|
759
603
|
const createFormData = (workspace, formData) => {
|
|
760
|
-
const defaultArrayHandling =
|
|
604
|
+
const defaultArrayHandling = FormDataArrayHandling.SERIALIZE;
|
|
761
605
|
if (formData === void 0) return {
|
|
762
606
|
disabled: false,
|
|
763
607
|
arrayHandling: defaultArrayHandling
|
|
764
608
|
};
|
|
765
|
-
if (
|
|
609
|
+
if (isBoolean(formData)) return {
|
|
766
610
|
disabled: !formData,
|
|
767
611
|
arrayHandling: defaultArrayHandling
|
|
768
612
|
};
|
|
769
|
-
if (
|
|
613
|
+
if (isString(formData)) return {
|
|
770
614
|
disabled: false,
|
|
771
615
|
mutator: normalizeMutator(workspace, formData),
|
|
772
616
|
arrayHandling: defaultArrayHandling
|
|
@@ -783,24 +627,24 @@ const createFormData = (workspace, formData) => {
|
|
|
783
627
|
};
|
|
784
628
|
};
|
|
785
629
|
const normalizeOptions = async (optionsExport, workspace = process.cwd(), globalOptions = {}) => {
|
|
786
|
-
const options = await (
|
|
787
|
-
if (!options.input) throw new Error(chalk.
|
|
788
|
-
if (!options.output) throw new Error(chalk.
|
|
789
|
-
const inputOptions =
|
|
790
|
-
const outputOptions =
|
|
630
|
+
const options = await (isFunction(optionsExport) ? optionsExport() : optionsExport);
|
|
631
|
+
if (!options.input) throw new Error(chalk.red(`Config require an input`));
|
|
632
|
+
if (!options.output) throw new Error(chalk.red(`Config require an output`));
|
|
633
|
+
const inputOptions = isString(options.input) ? { target: options.input } : options.input;
|
|
634
|
+
const outputOptions = isString(options.output) ? { target: options.output } : options.output;
|
|
791
635
|
const outputWorkspace = normalizePath(outputOptions.workspace || "", workspace);
|
|
792
636
|
const { clean, prettier, client, httpClient, mode, biome } = globalOptions;
|
|
793
637
|
const tsconfig = await loadTsconfig(outputOptions.tsconfig || globalOptions.tsconfig, workspace);
|
|
794
638
|
const packageJson = await loadPackageJson(outputOptions.packageJson || globalOptions.packageJson, workspace);
|
|
795
639
|
const mockOption = outputOptions.mock ?? globalOptions.mock;
|
|
796
|
-
let mock;
|
|
797
|
-
if (typeof mockOption === "boolean" && mockOption) mock =
|
|
798
|
-
else if (
|
|
799
|
-
else if (mockOption) mock = {
|
|
800
|
-
...
|
|
640
|
+
let mock$1;
|
|
641
|
+
if (typeof mockOption === "boolean" && mockOption) mock$1 = DEFAULT_MOCK_OPTIONS;
|
|
642
|
+
else if (isFunction(mockOption)) mock$1 = mockOption;
|
|
643
|
+
else if (mockOption) mock$1 = {
|
|
644
|
+
...DEFAULT_MOCK_OPTIONS,
|
|
801
645
|
...mockOption
|
|
802
646
|
};
|
|
803
|
-
else mock = void 0;
|
|
647
|
+
else mock$1 = void 0;
|
|
804
648
|
const defaultFileExtension = ".ts";
|
|
805
649
|
const globalQueryOptions = {
|
|
806
650
|
useQuery: true,
|
|
@@ -818,19 +662,19 @@ const normalizeOptions = async (optionsExport, workspace = process.cwd(), global
|
|
|
818
662
|
validation: inputOptions.validation || false,
|
|
819
663
|
override: { transformer: normalizePath(inputOptions.override?.transformer, workspace) },
|
|
820
664
|
converterOptions: inputOptions.converterOptions ?? {},
|
|
821
|
-
parserOptions:
|
|
665
|
+
parserOptions: mergeDeep(parserDefaultOptions, inputOptions.parserOptions ?? {}),
|
|
822
666
|
filters: inputOptions.filters
|
|
823
667
|
},
|
|
824
668
|
output: {
|
|
825
669
|
target: globalOptions.output ? normalizePath(globalOptions.output, process.cwd()) : normalizePath(outputOptions.target, outputWorkspace),
|
|
826
670
|
schemas: normalizePath(outputOptions.schemas, outputWorkspace),
|
|
827
|
-
namingConvention: outputOptions.namingConvention ||
|
|
671
|
+
namingConvention: outputOptions.namingConvention || NamingConvention.CAMEL_CASE,
|
|
828
672
|
fileExtension: outputOptions.fileExtension || defaultFileExtension,
|
|
829
673
|
workspace: outputOptions.workspace ? outputWorkspace : void 0,
|
|
830
|
-
client: outputOptions.client ?? client ??
|
|
831
|
-
httpClient: outputOptions.httpClient ?? httpClient ??
|
|
674
|
+
client: outputOptions.client ?? client ?? OutputClient.AXIOS_FUNCTIONS,
|
|
675
|
+
httpClient: outputOptions.httpClient ?? httpClient ?? OutputHttpClient.FETCH,
|
|
832
676
|
mode: normalizeOutputMode(outputOptions.mode ?? mode),
|
|
833
|
-
mock,
|
|
677
|
+
mock: mock$1,
|
|
834
678
|
clean: outputOptions.clean ?? clean ?? false,
|
|
835
679
|
docs: outputOptions.docs ?? false,
|
|
836
680
|
prettier: outputOptions.prettier ?? prettier ?? false,
|
|
@@ -855,27 +699,27 @@ const normalizeOptions = async (optionsExport, workspace = process.cwd(), global
|
|
|
855
699
|
tags: normalizeOperationsAndTags(outputOptions.override?.tags ?? {}, outputWorkspace, { query: globalQueryOptions }),
|
|
856
700
|
mutator: normalizeMutator(outputWorkspace, outputOptions.override?.mutator),
|
|
857
701
|
formData: createFormData(outputWorkspace, outputOptions.override?.formData),
|
|
858
|
-
formUrlEncoded: (
|
|
702
|
+
formUrlEncoded: (isBoolean(outputOptions.override?.formUrlEncoded) ? outputOptions.override?.formUrlEncoded : normalizeMutator(outputWorkspace, outputOptions.override?.formUrlEncoded)) ?? true,
|
|
859
703
|
paramsSerializer: normalizeMutator(outputWorkspace, outputOptions.override?.paramsSerializer),
|
|
860
|
-
header: outputOptions.override?.header === false ? false :
|
|
704
|
+
header: outputOptions.override?.header === false ? false : isFunction(outputOptions.override?.header) ? outputOptions.override?.header : getDefaultFilesHeader,
|
|
861
705
|
requestOptions: outputOptions.override?.requestOptions ?? true,
|
|
862
706
|
namingConvention: outputOptions.override?.namingConvention ?? {},
|
|
863
707
|
components: {
|
|
864
708
|
schemas: {
|
|
865
|
-
suffix:
|
|
709
|
+
suffix: RefComponentSuffix.schemas,
|
|
866
710
|
itemSuffix: outputOptions.override?.components?.schemas?.itemSuffix ?? "Item",
|
|
867
711
|
...outputOptions.override?.components?.schemas
|
|
868
712
|
},
|
|
869
713
|
responses: {
|
|
870
|
-
suffix:
|
|
714
|
+
suffix: RefComponentSuffix.responses,
|
|
871
715
|
...outputOptions.override?.components?.responses
|
|
872
716
|
},
|
|
873
717
|
parameters: {
|
|
874
|
-
suffix:
|
|
718
|
+
suffix: RefComponentSuffix.parameters,
|
|
875
719
|
...outputOptions.override?.components?.parameters
|
|
876
720
|
},
|
|
877
721
|
requestBodies: {
|
|
878
|
-
suffix:
|
|
722
|
+
suffix: RefComponentSuffix.requestBodies,
|
|
879
723
|
...outputOptions.override?.components?.requestBodies
|
|
880
724
|
}
|
|
881
725
|
},
|
|
@@ -920,23 +764,22 @@ const normalizeOptions = async (optionsExport, workspace = process.cwd(), global
|
|
|
920
764
|
fetch: {
|
|
921
765
|
includeHttpResponseReturnType: outputOptions.override?.fetch?.includeHttpResponseReturnType ?? true,
|
|
922
766
|
forceSuccessResponse: outputOptions.override?.fetch?.forceSuccessResponse ?? false,
|
|
923
|
-
explode: outputOptions.override?.fetch?.explode ?? true,
|
|
924
767
|
...outputOptions.override?.fetch
|
|
925
768
|
},
|
|
926
769
|
useDates: outputOptions.override?.useDates || false,
|
|
927
770
|
useDeprecatedOperations: outputOptions.override?.useDeprecatedOperations ?? true,
|
|
928
|
-
enumGenerationType: outputOptions.override?.
|
|
771
|
+
enumGenerationType: outputOptions.override?.enumGenerationType ?? "const",
|
|
929
772
|
suppressReadonlyModifier: outputOptions.override?.suppressReadonlyModifier || false
|
|
930
773
|
},
|
|
931
774
|
allParamsOptional: outputOptions.allParamsOptional ?? false,
|
|
932
775
|
urlEncodeParameters: outputOptions.urlEncodeParameters ?? false,
|
|
933
776
|
optionsParamRequired: outputOptions.optionsParamRequired ?? false,
|
|
934
|
-
propertySortOrder: outputOptions.propertySortOrder ??
|
|
777
|
+
propertySortOrder: outputOptions.propertySortOrder ?? PropertySortOrder.SPECIFICATION
|
|
935
778
|
},
|
|
936
779
|
hooks: options.hooks ? normalizeHooks(options.hooks) : {}
|
|
937
780
|
};
|
|
938
|
-
if (!normalizedOptions.input.target) throw new Error(chalk.
|
|
939
|
-
if (!normalizedOptions.output.target && !normalizedOptions.output.schemas) throw new Error(chalk.
|
|
781
|
+
if (!normalizedOptions.input.target) throw new Error(chalk.red(`Config require an input target`));
|
|
782
|
+
if (!normalizedOptions.output.target && !normalizedOptions.output.schemas) throw new Error(chalk.red(`Config require an output target or schemas`));
|
|
940
783
|
return normalizedOptions;
|
|
941
784
|
};
|
|
942
785
|
const parserDefaultOptions = {
|
|
@@ -947,27 +790,27 @@ const parserDefaultOptions = {
|
|
|
947
790
|
}
|
|
948
791
|
};
|
|
949
792
|
const normalizeMutator = (workspace, mutator) => {
|
|
950
|
-
if (
|
|
951
|
-
if (!mutator.path) throw new Error(chalk.
|
|
793
|
+
if (isObject(mutator)) {
|
|
794
|
+
if (!mutator.path) throw new Error(chalk.red(`Mutator need a path`));
|
|
952
795
|
return {
|
|
953
796
|
...mutator,
|
|
954
|
-
path:
|
|
797
|
+
path: upath.resolve(workspace, mutator.path),
|
|
955
798
|
default: (mutator.default || !mutator.name) ?? false
|
|
956
799
|
};
|
|
957
800
|
}
|
|
958
|
-
if (
|
|
959
|
-
path:
|
|
801
|
+
if (isString(mutator)) return {
|
|
802
|
+
path: upath.resolve(workspace, mutator),
|
|
960
803
|
default: true
|
|
961
804
|
};
|
|
962
805
|
return mutator;
|
|
963
806
|
};
|
|
964
807
|
const normalizePathOrUrl = (path$1, workspace) => {
|
|
965
|
-
if (
|
|
808
|
+
if (isString(path$1) && !isUrl(path$1)) return normalizePath(path$1, workspace);
|
|
966
809
|
return path$1;
|
|
967
810
|
};
|
|
968
811
|
const normalizePath = (path$1, workspace) => {
|
|
969
|
-
if (!
|
|
970
|
-
return
|
|
812
|
+
if (!isString(path$1)) return path$1;
|
|
813
|
+
return upath.resolve(workspace, path$1);
|
|
971
814
|
};
|
|
972
815
|
const normalizeOperationsAndTags = (operationsOrTags, workspace, global) => {
|
|
973
816
|
return Object.fromEntries(Object.entries(operationsOrTags).map(([key, { transformer, mutator, formData, formUrlEncoded, paramsSerializer, query: query$1, zod: zod$1,...rest }]) => {
|
|
@@ -1010,22 +853,22 @@ const normalizeOperationsAndTags = (operationsOrTags, workspace, global) => {
|
|
|
1010
853
|
...transformer ? { transformer: normalizePath(transformer, workspace) } : {},
|
|
1011
854
|
...mutator ? { mutator: normalizeMutator(workspace, mutator) } : {},
|
|
1012
855
|
...createFormData(workspace, formData),
|
|
1013
|
-
...formUrlEncoded ? { formUrlEncoded:
|
|
856
|
+
...formUrlEncoded ? { formUrlEncoded: isBoolean(formUrlEncoded) ? formUrlEncoded : normalizeMutator(workspace, formUrlEncoded) } : {},
|
|
1014
857
|
...paramsSerializer ? { paramsSerializer: normalizeMutator(workspace, paramsSerializer) } : {}
|
|
1015
858
|
}];
|
|
1016
859
|
}));
|
|
1017
860
|
};
|
|
1018
861
|
const normalizeOutputMode = (mode) => {
|
|
1019
|
-
if (!mode) return
|
|
1020
|
-
if (!Object.values(
|
|
1021
|
-
|
|
1022
|
-
return
|
|
862
|
+
if (!mode) return OutputMode.SINGLE;
|
|
863
|
+
if (!Object.values(OutputMode).includes(mode)) {
|
|
864
|
+
createLogger().warn(chalk.yellow(`Unknown the provided mode => ${mode}`));
|
|
865
|
+
return OutputMode.SINGLE;
|
|
1023
866
|
}
|
|
1024
867
|
return mode;
|
|
1025
868
|
};
|
|
1026
869
|
const normalizeHooks = (hooks) => {
|
|
1027
870
|
return Object.keys(hooks).reduce((acc, key) => {
|
|
1028
|
-
if (
|
|
871
|
+
if (isString(hooks[key])) return {
|
|
1029
872
|
...acc,
|
|
1030
873
|
[key]: [hooks[key]]
|
|
1031
874
|
};
|
|
@@ -1033,11 +876,11 @@ const normalizeHooks = (hooks) => {
|
|
|
1033
876
|
...acc,
|
|
1034
877
|
[key]: hooks[key]
|
|
1035
878
|
};
|
|
1036
|
-
else if (
|
|
879
|
+
else if (isFunction(hooks[key])) return {
|
|
1037
880
|
...acc,
|
|
1038
881
|
[key]: [hooks[key]]
|
|
1039
882
|
};
|
|
1040
|
-
else if (
|
|
883
|
+
else if (isObject(hooks[key])) return {
|
|
1041
884
|
...acc,
|
|
1042
885
|
[key]: [hooks[key]]
|
|
1043
886
|
};
|
|
@@ -1046,10 +889,10 @@ const normalizeHooks = (hooks) => {
|
|
|
1046
889
|
};
|
|
1047
890
|
const normalizeHonoOptions = (hono$1 = {}, workspace) => {
|
|
1048
891
|
return {
|
|
1049
|
-
...hono$1.handlers ? { handlers:
|
|
892
|
+
...hono$1.handlers ? { handlers: upath.resolve(workspace, hono$1.handlers) } : {},
|
|
1050
893
|
compositeRoute: hono$1.compositeRoute ?? "",
|
|
1051
894
|
validator: hono$1.validator ?? true,
|
|
1052
|
-
validatorOutputPath: hono$1.validatorOutputPath ?
|
|
895
|
+
validatorOutputPath: hono$1.validatorOutputPath ? upath.resolve(workspace, hono$1.validatorOutputPath) : ""
|
|
1053
896
|
};
|
|
1054
897
|
};
|
|
1055
898
|
const normalizeJSDocOptions = (jsdoc = {}) => {
|
|
@@ -1058,12 +901,13 @@ const normalizeJSDocOptions = (jsdoc = {}) => {
|
|
|
1058
901
|
const normalizeQueryOptions = (queryOptions = {}, outputWorkspace, globalOptions = {}) => {
|
|
1059
902
|
if (queryOptions.options) console.warn("[WARN] Using query options is deprecated and will be removed in a future major release. Please use queryOptions or mutationOptions instead.");
|
|
1060
903
|
return {
|
|
1061
|
-
...
|
|
1062
|
-
...
|
|
1063
|
-
...
|
|
1064
|
-
...
|
|
1065
|
-
...
|
|
1066
|
-
...
|
|
904
|
+
...isUndefined(queryOptions.usePrefetch) ? {} : { usePrefetch: queryOptions.usePrefetch },
|
|
905
|
+
...isUndefined(queryOptions.useInvalidate) ? {} : { useInvalidate: queryOptions.useInvalidate },
|
|
906
|
+
...isUndefined(queryOptions.useQuery) ? {} : { useQuery: queryOptions.useQuery },
|
|
907
|
+
...isUndefined(queryOptions.useSuspenseQuery) ? {} : { useSuspenseQuery: queryOptions.useSuspenseQuery },
|
|
908
|
+
...isUndefined(queryOptions.useMutation) ? {} : { useMutation: queryOptions.useMutation },
|
|
909
|
+
...isUndefined(queryOptions.useInfinite) ? {} : { useInfinite: queryOptions.useInfinite },
|
|
910
|
+
...isUndefined(queryOptions.useSuspenseInfiniteQuery) ? {} : { useSuspenseInfiniteQuery: queryOptions.useSuspenseInfiniteQuery },
|
|
1067
911
|
...queryOptions.useInfiniteQueryParam ? { useInfiniteQueryParam: queryOptions.useInfiniteQueryParam } : {},
|
|
1068
912
|
...queryOptions.options ? { options: queryOptions.options } : {},
|
|
1069
913
|
...globalOptions.queryKey ? { queryKey: globalOptions.queryKey } : {},
|
|
@@ -1072,25 +916,25 @@ const normalizeQueryOptions = (queryOptions = {}, outputWorkspace, globalOptions
|
|
|
1072
916
|
...queryOptions?.queryOptions ? { queryOptions: normalizeMutator(outputWorkspace, queryOptions?.queryOptions) } : {},
|
|
1073
917
|
...globalOptions.mutationOptions ? { mutationOptions: globalOptions.mutationOptions } : {},
|
|
1074
918
|
...queryOptions?.mutationOptions ? { mutationOptions: normalizeMutator(outputWorkspace, queryOptions?.mutationOptions) } : {},
|
|
1075
|
-
...
|
|
1076
|
-
...
|
|
1077
|
-
...
|
|
1078
|
-
...
|
|
1079
|
-
...
|
|
1080
|
-
...
|
|
1081
|
-
...
|
|
1082
|
-
...
|
|
1083
|
-
...
|
|
1084
|
-
...
|
|
1085
|
-
...
|
|
1086
|
-
...
|
|
1087
|
-
...
|
|
1088
|
-
...
|
|
1089
|
-
...
|
|
919
|
+
...isUndefined(globalOptions.shouldExportQueryKey) ? {} : { shouldExportQueryKey: globalOptions.shouldExportQueryKey },
|
|
920
|
+
...isUndefined(queryOptions.shouldExportQueryKey) ? {} : { shouldExportQueryKey: queryOptions.shouldExportQueryKey },
|
|
921
|
+
...isUndefined(globalOptions.shouldExportHttpClient) ? {} : { shouldExportHttpClient: globalOptions.shouldExportHttpClient },
|
|
922
|
+
...isUndefined(queryOptions.shouldExportHttpClient) ? {} : { shouldExportHttpClient: queryOptions.shouldExportHttpClient },
|
|
923
|
+
...isUndefined(globalOptions.shouldExportMutatorHooks) ? {} : { shouldExportMutatorHooks: globalOptions.shouldExportMutatorHooks },
|
|
924
|
+
...isUndefined(queryOptions.shouldExportMutatorHooks) ? {} : { shouldExportMutatorHooks: queryOptions.shouldExportMutatorHooks },
|
|
925
|
+
...isUndefined(globalOptions.shouldSplitQueryKey) ? {} : { shouldSplitQueryKey: globalOptions.shouldSplitQueryKey },
|
|
926
|
+
...isUndefined(queryOptions.shouldSplitQueryKey) ? {} : { shouldSplitQueryKey: queryOptions.shouldSplitQueryKey },
|
|
927
|
+
...isUndefined(globalOptions.signal) ? {} : { signal: globalOptions.signal },
|
|
928
|
+
...isUndefined(globalOptions.useOperationIdAsQueryKey) ? {} : { useOperationIdAsQueryKey: globalOptions.useOperationIdAsQueryKey },
|
|
929
|
+
...isUndefined(queryOptions.useOperationIdAsQueryKey) ? {} : { useOperationIdAsQueryKey: queryOptions.useOperationIdAsQueryKey },
|
|
930
|
+
...isUndefined(globalOptions.signal) ? {} : { signal: globalOptions.signal },
|
|
931
|
+
...isUndefined(queryOptions.signal) ? {} : { signal: queryOptions.signal },
|
|
932
|
+
...isUndefined(globalOptions.version) ? {} : { version: globalOptions.version },
|
|
933
|
+
...isUndefined(queryOptions.version) ? {} : { version: queryOptions.version }
|
|
1090
934
|
};
|
|
1091
935
|
};
|
|
1092
936
|
const getDefaultFilesHeader = ({ title, description: description$1, version: version$1 } = {}) => [
|
|
1093
|
-
`Generated by ${
|
|
937
|
+
`Generated by ${name} v${version} 🍺`,
|
|
1094
938
|
`Do not edit manually.`,
|
|
1095
939
|
...title ? [title] : [],
|
|
1096
940
|
...description$1 ? [description$1] : [],
|
|
@@ -1104,16 +948,16 @@ const startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
|
|
|
1104
948
|
const { watch } = await import("chokidar");
|
|
1105
949
|
const ignored = ["**/{.git,node_modules}/**"];
|
|
1106
950
|
const watchPaths = typeof watchOptions === "boolean" ? defaultTarget : Array.isArray(watchOptions) ? watchOptions.filter((path$1) => typeof path$1 === "string") : watchOptions;
|
|
1107
|
-
|
|
951
|
+
log(`Watching for changes in ${Array.isArray(watchPaths) ? watchPaths.map((v) => "\"" + v + "\"").join(" | ") : "\"" + watchPaths + "\""}`);
|
|
1108
952
|
watch(watchPaths, {
|
|
1109
953
|
ignorePermissionErrors: true,
|
|
1110
954
|
ignored
|
|
1111
|
-
}).on("all", async (type
|
|
1112
|
-
|
|
955
|
+
}).on("all", async (type, file) => {
|
|
956
|
+
log(`Change detected: ${type} ${file}`);
|
|
1113
957
|
try {
|
|
1114
958
|
await watchFn();
|
|
1115
959
|
} catch (error) {
|
|
1116
|
-
|
|
960
|
+
logError(error);
|
|
1117
961
|
}
|
|
1118
962
|
});
|
|
1119
963
|
};
|
|
@@ -1121,23 +965,23 @@ const startWatcher = async (watchOptions, watchFn, defaultTarget = ".") => {
|
|
|
1121
965
|
//#endregion
|
|
1122
966
|
//#region src/utils/execute-hook.ts
|
|
1123
967
|
const executeHook = async (name$1, commands = [], args = []) => {
|
|
1124
|
-
|
|
968
|
+
log(chalk.white(`Running ${name$1} hook...`));
|
|
1125
969
|
for (const command of commands) try {
|
|
1126
|
-
if (
|
|
1127
|
-
else if (
|
|
1128
|
-
else if (
|
|
970
|
+
if (isString(command)) await executeCommand(command, args);
|
|
971
|
+
else if (isFunction(command)) await command(args);
|
|
972
|
+
else if (isObject(command)) await executeObjectCommand(command, args);
|
|
1129
973
|
} catch (error) {
|
|
1130
|
-
|
|
974
|
+
logError(error, `Failed to run ${name$1} hook`);
|
|
1131
975
|
}
|
|
1132
976
|
};
|
|
1133
977
|
async function executeCommand(command, args) {
|
|
1134
|
-
const [cmd, ..._args] = [...
|
|
1135
|
-
await
|
|
978
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command), ...args];
|
|
979
|
+
await execa(cmd, _args);
|
|
1136
980
|
}
|
|
1137
981
|
async function executeObjectCommand(command, args) {
|
|
1138
982
|
if (command.injectGeneratedDirsAndFiles === false) args = [];
|
|
1139
|
-
if (
|
|
1140
|
-
else if (
|
|
983
|
+
if (isString(command.command)) await executeCommand(command.command, args);
|
|
984
|
+
else if (isFunction(command.command)) await command.command();
|
|
1141
985
|
}
|
|
1142
986
|
|
|
1143
987
|
//#endregion
|
|
@@ -1145,7 +989,7 @@ async function executeObjectCommand(command, args) {
|
|
|
1145
989
|
const getHeader = (option, info) => {
|
|
1146
990
|
if (!option) return "";
|
|
1147
991
|
const header = option(info);
|
|
1148
|
-
return Array.isArray(header) ?
|
|
992
|
+
return Array.isArray(header) ? jsDoc({ description: header }) : header;
|
|
1149
993
|
};
|
|
1150
994
|
const writeSpecs = async (builder, workspace, options, projectName) => {
|
|
1151
995
|
const { info = {
|
|
@@ -1153,9 +997,9 @@ const writeSpecs = async (builder, workspace, options, projectName) => {
|
|
|
1153
997
|
version: 0
|
|
1154
998
|
}, schemas, target } = builder;
|
|
1155
999
|
const { output } = options;
|
|
1156
|
-
const projectTitle = projectName
|
|
1000
|
+
const projectTitle = projectName ?? info.title;
|
|
1157
1001
|
const specsName = Object.keys(schemas).reduce((acc, specKey) => {
|
|
1158
|
-
acc[specKey] =
|
|
1002
|
+
acc[specKey] = upath.getSpecName(specKey, target).slice(1).split("/").join("-");
|
|
1159
1003
|
return acc;
|
|
1160
1004
|
}, {});
|
|
1161
1005
|
const header = getHeader(output.override.header, info);
|
|
@@ -1167,16 +1011,15 @@ const writeSpecs = async (builder, workspace, options, projectName) => {
|
|
|
1167
1011
|
"split"
|
|
1168
1012
|
].includes(output.mode) ? ".ts" : output.fileExtension ?? ".ts";
|
|
1169
1013
|
await Promise.all(Object.entries(schemas).map(([specKey, schemas$1]) => {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
schemaPath,
|
|
1014
|
+
return writeSchemas({
|
|
1015
|
+
schemaPath: isRootKey(specKey, target) ? rootSchemaPath : upath.join(rootSchemaPath, specsName[specKey]),
|
|
1173
1016
|
schemas: schemas$1,
|
|
1174
1017
|
target,
|
|
1175
1018
|
namingConvention: output.namingConvention,
|
|
1176
1019
|
fileExtension,
|
|
1177
1020
|
specsName,
|
|
1178
1021
|
specKey,
|
|
1179
|
-
isRootKey:
|
|
1022
|
+
isRootKey: isRootKey(specKey, target),
|
|
1180
1023
|
header,
|
|
1181
1024
|
indexFiles: output.indexFiles
|
|
1182
1025
|
});
|
|
@@ -1193,39 +1036,39 @@ const writeSpecs = async (builder, workspace, options, projectName) => {
|
|
|
1193
1036
|
});
|
|
1194
1037
|
if (output.workspace) {
|
|
1195
1038
|
const workspacePath = output.workspace;
|
|
1196
|
-
const imports = implementationPaths.filter((path$1) => !output.mock || !path$1.endsWith(`.${
|
|
1197
|
-
if (output.schemas) imports.push(
|
|
1039
|
+
const imports = implementationPaths.filter((path$1) => !output.mock || !path$1.endsWith(`.${getMockFileExtensionByTypeName(output.mock)}.ts`)).map((path$1) => upath.relativeSafe(workspacePath, getFileInfo(path$1).pathWithoutExtension));
|
|
1040
|
+
if (output.schemas) imports.push(upath.relativeSafe(workspacePath, getFileInfo(output.schemas).dirname));
|
|
1198
1041
|
if (output.indexFiles) {
|
|
1199
|
-
const indexFile =
|
|
1200
|
-
if (await
|
|
1201
|
-
const data = await
|
|
1042
|
+
const indexFile = upath.join(workspacePath, "/index.ts");
|
|
1043
|
+
if (await fs$1.pathExists(indexFile)) {
|
|
1044
|
+
const data = await fs$1.readFile(indexFile, "utf8");
|
|
1202
1045
|
const importsNotDeclared = imports.filter((imp) => !data.includes(imp));
|
|
1203
|
-
await
|
|
1204
|
-
} else await
|
|
1046
|
+
await fs$1.appendFile(indexFile, uniq(importsNotDeclared).map((imp) => `export * from '${imp}';\n`).join(""));
|
|
1047
|
+
} else await fs$1.outputFile(indexFile, uniq(imports).map((imp) => `export * from '${imp}';`).join("\n") + "\n");
|
|
1205
1048
|
implementationPaths = [indexFile, ...implementationPaths];
|
|
1206
1049
|
}
|
|
1207
1050
|
}
|
|
1208
1051
|
if (builder.extraFiles.length > 0) {
|
|
1209
|
-
await Promise.all(builder.extraFiles.map(async (file) =>
|
|
1052
|
+
await Promise.all(builder.extraFiles.map(async (file) => fs$1.outputFile(file.path, file.content)));
|
|
1210
1053
|
implementationPaths = [...implementationPaths, ...builder.extraFiles.map((file) => file.path)];
|
|
1211
1054
|
}
|
|
1212
|
-
const paths = [...output.schemas ? [
|
|
1055
|
+
const paths = [...output.schemas ? [getFileInfo(output.schemas).dirname] : [], ...implementationPaths];
|
|
1213
1056
|
if (options.hooks.afterAllFilesWrite) await executeHook("afterAllFilesWrite", options.hooks.afterAllFilesWrite, paths);
|
|
1214
1057
|
if (output.prettier) try {
|
|
1215
|
-
await
|
|
1058
|
+
await execa("prettier", ["--write", ...paths]);
|
|
1216
1059
|
} catch {
|
|
1217
|
-
|
|
1060
|
+
log(chalk.yellow(`⚠️ ${projectTitle ? `${projectTitle} - ` : ""}Globally installed prettier not found`));
|
|
1218
1061
|
}
|
|
1219
1062
|
if (output.biome) try {
|
|
1220
|
-
await
|
|
1063
|
+
await execa("biome", [
|
|
1221
1064
|
"check",
|
|
1222
1065
|
"--write",
|
|
1223
1066
|
...paths
|
|
1224
1067
|
]);
|
|
1225
1068
|
} catch (error) {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1069
|
+
let message = `⚠️ ${projectTitle ? `${projectTitle} - ` : ""}biome not found`;
|
|
1070
|
+
if (error instanceof ExecaError && error.exitCode === 1) message = error.message;
|
|
1071
|
+
log(chalk.yellow(message));
|
|
1229
1072
|
}
|
|
1230
1073
|
if (output.docs) try {
|
|
1231
1074
|
let config = {};
|
|
@@ -1251,17 +1094,17 @@ const writeSpecs = async (builder, workspace, options, projectName) => {
|
|
|
1251
1094
|
else throw new Error("TypeDoc not initialized");
|
|
1252
1095
|
} catch (error) {
|
|
1253
1096
|
const message = error instanceof Error ? error.message : `⚠️ ${projectTitle ? `${projectTitle} - ` : ""}Unable to generate docs`;
|
|
1254
|
-
|
|
1097
|
+
log(chalk.yellow(message));
|
|
1255
1098
|
}
|
|
1256
|
-
|
|
1099
|
+
createSuccessMessage(projectTitle);
|
|
1257
1100
|
};
|
|
1258
1101
|
const getWriteMode = (mode) => {
|
|
1259
1102
|
switch (mode) {
|
|
1260
|
-
case
|
|
1261
|
-
case
|
|
1262
|
-
case
|
|
1263
|
-
case
|
|
1264
|
-
default: return
|
|
1103
|
+
case OutputMode.SPLIT: return writeSplitMode;
|
|
1104
|
+
case OutputMode.TAGS: return writeTagsMode;
|
|
1105
|
+
case OutputMode.TAGS_SPLIT: return writeSplitTagsMode;
|
|
1106
|
+
case OutputMode.SINGLE:
|
|
1107
|
+
default: return writeSingleMode;
|
|
1265
1108
|
}
|
|
1266
1109
|
};
|
|
1267
1110
|
|
|
@@ -1270,20 +1113,19 @@ const getWriteMode = (mode) => {
|
|
|
1270
1113
|
const generateSpec = async (workspace, options, projectName) => {
|
|
1271
1114
|
if (options.output.clean) {
|
|
1272
1115
|
const extraPatterns = Array.isArray(options.output.clean) ? options.output.clean : [];
|
|
1273
|
-
if (options.output.target) await
|
|
1116
|
+
if (options.output.target) await removeFilesAndEmptyFolders([
|
|
1274
1117
|
"**/*",
|
|
1275
1118
|
"!**/*.d.ts",
|
|
1276
1119
|
...extraPatterns
|
|
1277
|
-
],
|
|
1278
|
-
if (options.output.schemas) await
|
|
1120
|
+
], getFileInfo(options.output.target).dirname);
|
|
1121
|
+
if (options.output.schemas) await removeFilesAndEmptyFolders([
|
|
1279
1122
|
"**/*",
|
|
1280
1123
|
"!**/*.d.ts",
|
|
1281
1124
|
...extraPatterns
|
|
1282
|
-
],
|
|
1283
|
-
|
|
1125
|
+
], getFileInfo(options.output.schemas).dirname);
|
|
1126
|
+
log(`${projectName ? `${projectName}: ` : ""}Cleaning output folder`);
|
|
1284
1127
|
}
|
|
1285
|
-
|
|
1286
|
-
await writeSpecs(writeSpecBuilder, workspace, options, projectName);
|
|
1128
|
+
await writeSpecs(await importSpecs(workspace, options), workspace, options, projectName);
|
|
1287
1129
|
};
|
|
1288
1130
|
const generateSpecs = async (config, workspace, projectName) => {
|
|
1289
1131
|
if (projectName) {
|
|
@@ -1291,8 +1133,7 @@ const generateSpecs = async (config, workspace, projectName) => {
|
|
|
1291
1133
|
if (options) try {
|
|
1292
1134
|
await generateSpec(workspace, options, projectName);
|
|
1293
1135
|
} catch (error) {
|
|
1294
|
-
|
|
1295
|
-
throw new __orval_core.ErrorWithTag(errorMsg, projectName, { cause: error });
|
|
1136
|
+
throw new ErrorWithTag(error instanceof Error ? error.message : "unknown error", projectName, { cause: error });
|
|
1296
1137
|
}
|
|
1297
1138
|
else throw new Error("Project not found");
|
|
1298
1139
|
return;
|
|
@@ -1301,32 +1142,31 @@ const generateSpecs = async (config, workspace, projectName) => {
|
|
|
1301
1142
|
for (const [projectName$1, options] of Object.entries(config)) {
|
|
1302
1143
|
if (!options) {
|
|
1303
1144
|
hasErrors = true;
|
|
1304
|
-
|
|
1145
|
+
logError("No options found", projectName$1);
|
|
1305
1146
|
continue;
|
|
1306
1147
|
}
|
|
1307
1148
|
try {
|
|
1308
1149
|
await generateSpec(workspace, options, projectName$1);
|
|
1309
1150
|
} catch (error) {
|
|
1310
1151
|
hasErrors = true;
|
|
1311
|
-
|
|
1152
|
+
logError(error, projectName$1);
|
|
1312
1153
|
}
|
|
1313
1154
|
}
|
|
1314
1155
|
if (hasErrors) throw new Error("One or more project failed, see above for details");
|
|
1315
1156
|
};
|
|
1316
1157
|
function findConfigFile(configFilePath) {
|
|
1317
1158
|
if (configFilePath) {
|
|
1318
|
-
if (!
|
|
1159
|
+
if (!fs.existsSync(configFilePath)) throw new Error(`Config file ${configFilePath} does not exist`);
|
|
1319
1160
|
return configFilePath;
|
|
1320
1161
|
}
|
|
1321
|
-
const root =
|
|
1162
|
+
const root = process$1.cwd();
|
|
1322
1163
|
for (const ext of [
|
|
1323
1164
|
".ts",
|
|
1324
1165
|
".js",
|
|
1325
|
-
".mjs"
|
|
1326
|
-
".cjs"
|
|
1166
|
+
".mjs"
|
|
1327
1167
|
]) {
|
|
1328
|
-
const fullPath =
|
|
1329
|
-
if (
|
|
1168
|
+
const fullPath = path.resolve(root, `orval.config${ext}`);
|
|
1169
|
+
if (fs.existsSync(fullPath)) return fullPath;
|
|
1330
1170
|
}
|
|
1331
1171
|
throw new Error(`No config file found in ${root}`);
|
|
1332
1172
|
}
|
|
@@ -1334,64 +1174,23 @@ const generateConfig = async (configFile, options) => {
|
|
|
1334
1174
|
const configFilePath = findConfigFile(configFile);
|
|
1335
1175
|
let configExternal;
|
|
1336
1176
|
try {
|
|
1337
|
-
const importedModule = await import(
|
|
1177
|
+
const importedModule = await import(url.pathToFileURL(configFilePath).href);
|
|
1338
1178
|
if (importedModule.default === void 0) throw new Error(`${configFilePath} doesn't have a default export`);
|
|
1339
1179
|
configExternal = importedModule.default;
|
|
1340
1180
|
} catch (error) {
|
|
1341
1181
|
const errorMsg = error instanceof Error ? error.message : "unknown error";
|
|
1342
1182
|
throw new Error(`failed to load from ${configFilePath} => ${errorMsg}`);
|
|
1343
1183
|
}
|
|
1344
|
-
const workspace =
|
|
1345
|
-
const config = await (
|
|
1346
|
-
const normalizedConfig = await
|
|
1184
|
+
const workspace = path.dirname(configFilePath);
|
|
1185
|
+
const config = await (isFunction(configExternal) ? configExternal() : configExternal);
|
|
1186
|
+
const normalizedConfig = await asyncReduce(Object.entries(config), async (acc, [key, value]) => {
|
|
1347
1187
|
acc[key] = await normalizeOptions(value, workspace, options);
|
|
1348
1188
|
return acc;
|
|
1349
1189
|
}, {});
|
|
1350
|
-
const fileToWatch = Object.entries(normalizedConfig).filter(([project]) => options?.projectName === void 0 || project === options.projectName).map(([, options$1]) => options$1?.input.target).filter((target) =>
|
|
1190
|
+
const fileToWatch = Object.entries(normalizedConfig).filter(([project]) => options?.projectName === void 0 || project === options.projectName).map(([, options$1]) => options$1?.input.target).filter((target) => isString(target));
|
|
1351
1191
|
await (options?.watch && fileToWatch.length > 0 ? startWatcher(options.watch, () => generateSpecs(normalizedConfig, workspace, options.projectName), fileToWatch) : generateSpecs(normalizedConfig, workspace, options?.projectName));
|
|
1352
1192
|
};
|
|
1353
1193
|
|
|
1354
1194
|
//#endregion
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
get: function () {
|
|
1358
|
-
return __toESM;
|
|
1359
|
-
}
|
|
1360
|
-
});
|
|
1361
|
-
Object.defineProperty(exports, 'defineConfig', {
|
|
1362
|
-
enumerable: true,
|
|
1363
|
-
get: function () {
|
|
1364
|
-
return defineConfig;
|
|
1365
|
-
}
|
|
1366
|
-
});
|
|
1367
|
-
Object.defineProperty(exports, 'generateConfig', {
|
|
1368
|
-
enumerable: true,
|
|
1369
|
-
get: function () {
|
|
1370
|
-
return generateConfig;
|
|
1371
|
-
}
|
|
1372
|
-
});
|
|
1373
|
-
Object.defineProperty(exports, 'generateSpec', {
|
|
1374
|
-
enumerable: true,
|
|
1375
|
-
get: function () {
|
|
1376
|
-
return generateSpec;
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
Object.defineProperty(exports, 'normalizeOptions', {
|
|
1380
|
-
enumerable: true,
|
|
1381
|
-
get: function () {
|
|
1382
|
-
return normalizeOptions;
|
|
1383
|
-
}
|
|
1384
|
-
});
|
|
1385
|
-
Object.defineProperty(exports, 'package_default', {
|
|
1386
|
-
enumerable: true,
|
|
1387
|
-
get: function () {
|
|
1388
|
-
return package_default;
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
Object.defineProperty(exports, 'startWatcher', {
|
|
1392
|
-
enumerable: true,
|
|
1393
|
-
get: function () {
|
|
1394
|
-
return startWatcher;
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
//# sourceMappingURL=generate-B5LnJ5C4.js.map
|
|
1195
|
+
export { normalizeOptions as a, version as c, defineConfig as i, generateSpec as n, description as o, startWatcher as r, name as s, generateConfig as t };
|
|
1196
|
+
//# sourceMappingURL=generate-Cg1NHQEp.js.map
|