typed-openapi 1.4.1 → 1.4.3
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-FM2BOVDQ.js → chunk-5UEEXUUO.js} +11 -1
- package/dist/{chunk-7FXHZEBG.js → chunk-UQGHH67X.js} +11 -2
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/dist/node.export.js +2 -2
- package/package.json +1 -1
- package/src/generate-client-files.ts +11 -1
- package/src/openapi-schema-to-ts.ts +11 -1
|
@@ -77,7 +77,17 @@ var openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }) => {
|
|
|
77
77
|
if (schema.enum) {
|
|
78
78
|
if (schema.enum.length === 1) {
|
|
79
79
|
const value = schema.enum[0];
|
|
80
|
-
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return t.literal("null");
|
|
82
|
+
} else if (value === true) {
|
|
83
|
+
return t.literal("true");
|
|
84
|
+
} else if (value === false) {
|
|
85
|
+
return t.literal("false");
|
|
86
|
+
} else if (typeof value === "number") {
|
|
87
|
+
return t.literal(`${value}`);
|
|
88
|
+
} else {
|
|
89
|
+
return t.literal(`"${value}"`);
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
92
|
if (schemaType === "string") {
|
|
83
93
|
return t.union(schema.enum.map((value) => t.literal(`"${value}"`)));
|
|
@@ -4,15 +4,22 @@ import {
|
|
|
4
4
|
generateTanstackQueryFile,
|
|
5
5
|
mapOpenApiEndpoints,
|
|
6
6
|
prettify
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5UEEXUUO.js";
|
|
8
8
|
|
|
9
9
|
// src/generate-client-files.ts
|
|
10
10
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
11
11
|
import { basename, join, dirname } from "pathe";
|
|
12
12
|
import { type } from "arktype";
|
|
13
|
-
import { writeFile } from "fs/promises";
|
|
13
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
14
14
|
var cwd = process.cwd();
|
|
15
15
|
var now = /* @__PURE__ */ new Date();
|
|
16
|
+
async function ensureDir(dirPath) {
|
|
17
|
+
try {
|
|
18
|
+
await mkdir(dirPath, { recursive: true });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(`Error ensuring directory: ${error.message}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
16
23
|
var optionsSchema = type({
|
|
17
24
|
"output?": "string",
|
|
18
25
|
runtime: allowedRuntimes,
|
|
@@ -33,6 +40,7 @@ async function generateClientFiles(input, options) {
|
|
|
33
40
|
options.output ?? input + `.${options.runtime === "none" ? "client" : options.runtime}.ts`
|
|
34
41
|
);
|
|
35
42
|
console.log("Generating client...", outputPath);
|
|
43
|
+
await ensureDir(dirname(outputPath));
|
|
36
44
|
await writeFile(outputPath, content);
|
|
37
45
|
if (options.tanstack) {
|
|
38
46
|
const tanstackContent = await generateTanstackQueryFile({
|
|
@@ -41,6 +49,7 @@ async function generateClientFiles(input, options) {
|
|
|
41
49
|
});
|
|
42
50
|
const tanstackOutputPath = join(dirname(outputPath), typeof options.tanstack === "string" ? options.tanstack : `tanstack.client.ts`);
|
|
43
51
|
console.log("Generating tanstack client...", tanstackOutputPath);
|
|
52
|
+
await ensureDir(dirname(tanstackOutputPath));
|
|
44
53
|
await writeFile(tanstackOutputPath, tanstackContent);
|
|
45
54
|
}
|
|
46
55
|
console.log(`Done in ${(/* @__PURE__ */ new Date()).getTime() - now.getTime()}ms !`);
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/dist/node.export.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import SwaggerParser from "@apidevtools/swagger-parser";
|
|
|
2
2
|
import type { OpenAPIObject } from "openapi3-ts/oas31";
|
|
3
3
|
import { basename, join, dirname } from "pathe";
|
|
4
4
|
import { type } from "arktype";
|
|
5
|
-
import { writeFile } from "fs/promises";
|
|
5
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
6
6
|
import { allowedRuntimes, generateFile } from "./generator.ts";
|
|
7
7
|
import { mapOpenApiEndpoints } from "./map-openapi-endpoints.ts";
|
|
8
8
|
import { generateTanstackQueryFile } from "./tanstack-query.generator.ts";
|
|
@@ -11,6 +11,14 @@ import { prettify } from "./format.ts";
|
|
|
11
11
|
const cwd = process.cwd();
|
|
12
12
|
const now = new Date();
|
|
13
13
|
|
|
14
|
+
async function ensureDir(dirPath: string): Promise<void> {
|
|
15
|
+
try {
|
|
16
|
+
await mkdir(dirPath, { recursive: true });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error(`Error ensuring directory: ${(error as Error).message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export const optionsSchema = type({
|
|
15
23
|
"output?": "string",
|
|
16
24
|
runtime: allowedRuntimes,
|
|
@@ -35,6 +43,7 @@ export async function generateClientFiles(input: string, options: typeof options
|
|
|
35
43
|
);
|
|
36
44
|
|
|
37
45
|
console.log("Generating client...", outputPath);
|
|
46
|
+
await ensureDir(dirname(outputPath));
|
|
38
47
|
await writeFile(outputPath, content);
|
|
39
48
|
|
|
40
49
|
if (options.tanstack) {
|
|
@@ -44,6 +53,7 @@ export async function generateClientFiles(input: string, options: typeof options
|
|
|
44
53
|
});
|
|
45
54
|
const tanstackOutputPath = join(dirname(outputPath), typeof options.tanstack === "string" ? options.tanstack : `tanstack.client.ts`);
|
|
46
55
|
console.log("Generating tanstack client...", tanstackOutputPath);
|
|
56
|
+
await ensureDir(dirname(tanstackOutputPath));
|
|
47
57
|
await writeFile(tanstackOutputPath, tanstackContent);
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -65,7 +65,17 @@ export const openApiSchemaToTs = ({ schema, meta: _inheritedMeta, ctx }: Openapi
|
|
|
65
65
|
if (schema.enum) {
|
|
66
66
|
if (schema.enum.length === 1) {
|
|
67
67
|
const value = schema.enum[0];
|
|
68
|
-
|
|
68
|
+
if (value === null) {
|
|
69
|
+
return t.literal("null");
|
|
70
|
+
} else if (value === true) {
|
|
71
|
+
return t.literal("true");
|
|
72
|
+
} else if (value === false) {
|
|
73
|
+
return t.literal("false");
|
|
74
|
+
} else if (typeof value === "number") {
|
|
75
|
+
return t.literal(`${value}`)
|
|
76
|
+
} else {
|
|
77
|
+
return t.literal(`"${value}"`);
|
|
78
|
+
}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
if (schemaType === "string") {
|