typed-openapi 1.5.1 → 2.0.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/{chunk-OVT6OLBK.js → chunk-4EZJSCLI.js} +341 -50
- package/dist/chunk-GD55PFNE.js +208 -0
- package/dist/cli.js +11 -5
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -1
- package/dist/node.export.d.ts +10 -1
- package/dist/node.export.js +2 -2
- package/dist/{types-DLE5RaXi.d.ts → types-DsI2d-HE.d.ts} +2 -0
- package/package.json +6 -1
- package/src/cli.ts +13 -4
- package/src/default-fetcher.generator.ts +101 -0
- package/src/generate-client-files.ts +75 -15
- package/src/generator.ts +197 -26
- package/src/map-openapi-endpoints.ts +55 -4
- package/src/openapi-schema-to-ts.ts +3 -2
- package/src/tanstack-query.generator.ts +69 -25
- package/dist/chunk-O7DZWQK4.js +0 -68
package/dist/chunk-O7DZWQK4.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
allowedRuntimes,
|
|
3
|
-
generateFile,
|
|
4
|
-
generateTanstackQueryFile,
|
|
5
|
-
mapOpenApiEndpoints
|
|
6
|
-
} from "./chunk-OVT6OLBK.js";
|
|
7
|
-
import {
|
|
8
|
-
prettify
|
|
9
|
-
} from "./chunk-KAEXXJ7X.js";
|
|
10
|
-
|
|
11
|
-
// src/generate-client-files.ts
|
|
12
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
13
|
-
import { basename, join, dirname } from "pathe";
|
|
14
|
-
import { type } from "arktype";
|
|
15
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
16
|
-
var cwd = process.cwd();
|
|
17
|
-
var now = /* @__PURE__ */ new Date();
|
|
18
|
-
async function ensureDir(dirPath) {
|
|
19
|
-
try {
|
|
20
|
-
await mkdir(dirPath, { recursive: true });
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error(`Error ensuring directory: ${error.message}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
var optionsSchema = type({
|
|
26
|
-
"output?": "string",
|
|
27
|
-
runtime: allowedRuntimes,
|
|
28
|
-
tanstack: "boolean | string",
|
|
29
|
-
schemasOnly: "boolean"
|
|
30
|
-
});
|
|
31
|
-
async function generateClientFiles(input, options) {
|
|
32
|
-
const openApiDoc = await SwaggerParser.bundle(input);
|
|
33
|
-
const ctx = mapOpenApiEndpoints(openApiDoc, options);
|
|
34
|
-
console.log(`Found ${ctx.endpointList.length} endpoints`);
|
|
35
|
-
const content = await prettify(
|
|
36
|
-
generateFile({
|
|
37
|
-
...ctx,
|
|
38
|
-
runtime: options.runtime,
|
|
39
|
-
schemasOnly: options.schemasOnly,
|
|
40
|
-
nameTransform: options.nameTransform
|
|
41
|
-
})
|
|
42
|
-
);
|
|
43
|
-
const outputPath = join(
|
|
44
|
-
cwd,
|
|
45
|
-
options.output ?? input + `.${options.runtime === "none" ? "client" : options.runtime}.ts`
|
|
46
|
-
);
|
|
47
|
-
console.log("Generating client...", outputPath);
|
|
48
|
-
await ensureDir(dirname(outputPath));
|
|
49
|
-
await writeFile(outputPath, content);
|
|
50
|
-
if (options.tanstack) {
|
|
51
|
-
const tanstackContent = await generateTanstackQueryFile({
|
|
52
|
-
...ctx,
|
|
53
|
-
relativeApiClientPath: "./" + basename(outputPath)
|
|
54
|
-
});
|
|
55
|
-
const tanstackOutputPath = join(
|
|
56
|
-
dirname(outputPath),
|
|
57
|
-
typeof options.tanstack === "string" ? options.tanstack : `tanstack.client.ts`
|
|
58
|
-
);
|
|
59
|
-
console.log("Generating tanstack client...", tanstackOutputPath);
|
|
60
|
-
await ensureDir(dirname(tanstackOutputPath));
|
|
61
|
-
await writeFile(tanstackOutputPath, tanstackContent);
|
|
62
|
-
}
|
|
63
|
-
console.log(`Done in ${(/* @__PURE__ */ new Date()).getTime() - now.getTime()}ms !`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export {
|
|
67
|
-
generateClientFiles
|
|
68
|
-
};
|