typed-openapi 1.4.0 → 1.4.2

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.
@@ -4,15 +4,22 @@ import {
4
4
  generateTanstackQueryFile,
5
5
  mapOpenApiEndpoints,
6
6
  prettify
7
- } from "./chunk-DU37V6HC.js";
7
+ } from "./chunk-FM2BOVDQ.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 !`);
@@ -77,7 +77,7 @@ 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
- return t.literal(value === null ? "null" : `"${value}"`);
80
+ return t.literal(value === null ? "null" : value === true ? "true" : value === false ? "false" : `"${value}"`);
81
81
  }
82
82
  if (schemaType === "string") {
83
83
  return t.union(schema.enum.map((value) => t.literal(`"${value}"`)));
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-6PTWWQX6.js";
3
+ } from "./chunk-4LBBEM6D.js";
4
4
  import {
5
5
  allowedRuntimes
6
- } from "./chunk-DU37V6HC.js";
6
+ } from "./chunk-FM2BOVDQ.js";
7
7
 
8
8
  // src/cli.ts
9
9
  import { cac } from "cac";
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  openApiSchemaToTs,
9
9
  tsFactory,
10
10
  unwrap
11
- } from "./chunk-DU37V6HC.js";
11
+ } from "./chunk-FM2BOVDQ.js";
12
12
  export {
13
13
  createBoxFactory,
14
14
  createFactory,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateClientFiles
3
- } from "./chunk-6PTWWQX6.js";
3
+ } from "./chunk-4LBBEM6D.js";
4
4
  import {
5
5
  prettify
6
- } from "./chunk-DU37V6HC.js";
6
+ } from "./chunk-FM2BOVDQ.js";
7
7
  export {
8
8
  generateClientFiles,
9
9
  prettify
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-openapi",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.4.2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {
@@ -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,7 @@ 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
- return t.literal(value === null ? "null" : `"${value}"`);
68
+ return t.literal(value === null ? "null" : value === true ? "true" : value === false ? "false" : `"${value}"`);
69
69
  }
70
70
 
71
71
  if (schemaType === "string") {