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