@omer-x/next-openapi-json-generator 1.3.3 → 2.0.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/index.cjs CHANGED
@@ -28,11 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- default: () => src_default
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
34
  });
35
- module.exports = __toCommonJS(src_exports);
35
+ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // src/core/generateOpenApiSpec.ts
38
38
  var import_node_path4 = __toESM(require("path"), 1);
@@ -272,36 +272,9 @@ function deepEqual(a, b) {
272
272
  }
273
273
 
274
274
  // src/core/zod-to-openapi.ts
275
- var import_zod_to_json_schema = require("zod-to-json-schema");
276
-
277
- // src/utils/zod-schema.ts
278
- function isFile(schema) {
279
- const file = new File([], "nothing.txt");
280
- const plainObject = { name: "test", size: 0 };
281
- const fileResult = schema.safeParse(file);
282
- const objectResult = schema.safeParse(plainObject);
283
- return fileResult.success && !objectResult.success;
284
- }
285
-
286
- // src/core/zod-to-openapi.ts
275
+ var import_zod = require("zod");
287
276
  function convertToOpenAPI(schema, isArray) {
288
- const result = (0, import_zod_to_json_schema.zodToJsonSchema)(isArray ? schema.array() : schema, {
289
- target: "openApi3",
290
- $refStrategy: "none"
291
- });
292
- if (result.type === "object" && result.properties) {
293
- for (const [propName, prop] of Object.entries(schema.shape)) {
294
- if (isFile(prop)) {
295
- result.properties[propName] = {
296
- type: "string",
297
- format: "binary",
298
- description: prop.description
299
- // contentEncoding: "base64", // swagger-ui-react doesn't support this
300
- };
301
- }
302
- }
303
- }
304
- return result;
277
+ return import_zod.z.toJSONSchema(isArray ? schema.array() : schema);
305
278
  }
306
279
 
307
280
  // src/core/mask.ts
@@ -434,6 +407,7 @@ async function generateOpenApiSpec(schemas, {
434
407
  exclude: excludeOption = [],
435
408
  routeDefinerName = "defineRoute",
436
409
  rootPath: additionalRootPath,
410
+ info,
437
411
  servers,
438
412
  security,
439
413
  securitySchemes,
@@ -468,18 +442,19 @@ async function generateOpenApiSpec(schemas, {
468
442
  securitySchemes
469
443
  }
470
444
  };
471
- return {
445
+ return JSON.parse(JSON.stringify({
472
446
  openapi: "3.1.0",
473
447
  info: {
474
448
  title: metadata.serviceName,
475
- version: metadata.version
449
+ version: metadata.version,
450
+ ...info ?? {}
476
451
  },
477
452
  servers,
478
453
  ...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
479
454
  security,
480
455
  tags: []
481
- };
456
+ }));
482
457
  }
483
458
 
484
459
  // src/index.ts
485
- var src_default = generateOpenApiSpec;
460
+ var index_default = generateOpenApiSpec;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { OpenApiDocument } from '@omer-x/openapi-types';
2
2
  import { ComponentsObject } from '@omer-x/openapi-types/components';
3
- import { ServerObject } from '@omer-x/openapi-types/server';
4
3
  import { ZodType } from 'zod';
5
4
 
6
5
  type GeneratorOptions = {
@@ -8,11 +7,12 @@ type GeneratorOptions = {
8
7
  exclude?: string[];
9
8
  routeDefinerName?: string;
10
9
  rootPath?: string;
11
- servers?: ServerObject[];
10
+ info?: OpenApiDocument["info"];
11
+ servers?: OpenApiDocument["servers"];
12
12
  security?: OpenApiDocument["security"];
13
13
  securitySchemes?: ComponentsObject["securitySchemes"];
14
14
  clearUnusedSchemas?: boolean;
15
15
  };
16
- declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
16
+ declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, info, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
17
17
 
18
18
  export { generateOpenApiSpec as default };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { OpenApiDocument } from '@omer-x/openapi-types';
2
2
  import { ComponentsObject } from '@omer-x/openapi-types/components';
3
- import { ServerObject } from '@omer-x/openapi-types/server';
4
3
  import { ZodType } from 'zod';
5
4
 
6
5
  type GeneratorOptions = {
@@ -8,11 +7,12 @@ type GeneratorOptions = {
8
7
  exclude?: string[];
9
8
  routeDefinerName?: string;
10
9
  rootPath?: string;
11
- servers?: ServerObject[];
10
+ info?: OpenApiDocument["info"];
11
+ servers?: OpenApiDocument["servers"];
12
12
  security?: OpenApiDocument["security"];
13
13
  securitySchemes?: ComponentsObject["securitySchemes"];
14
14
  clearUnusedSchemas?: boolean;
15
15
  };
16
- declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
16
+ declare function generateOpenApiSpec(schemas: Record<string, ZodType>, { include: includeOption, exclude: excludeOption, routeDefinerName, rootPath: additionalRootPath, info, servers, security, securitySchemes, clearUnusedSchemas: clearUnusedSchemasOption, }?: GeneratorOptions): Promise<Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>>;
17
17
 
18
18
  export { generateOpenApiSpec as default };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core/generateOpenApiSpec.ts
2
- import path4 from "node:path";
2
+ import path4 from "path";
3
3
  import getPackageMetadata from "@omer-x/package-metadata";
4
4
 
5
5
  // src/utils/object.ts
@@ -35,7 +35,7 @@ function clearUnusedSchemas({
35
35
  // src/core/dir.ts
36
36
  import { constants } from "fs";
37
37
  import fs from "fs/promises";
38
- import path from "node:path";
38
+ import path from "path";
39
39
  import { Minimatch } from "minimatch";
40
40
  async function directoryExists(dirPath) {
41
41
  try {
@@ -72,7 +72,7 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
72
72
  }
73
73
 
74
74
  // src/core/isDocumentedRoute.ts
75
- import fs2 from "node:fs/promises";
75
+ import fs2 from "fs/promises";
76
76
  async function isDocumentedRoute(routePath2) {
77
77
  try {
78
78
  const rawCode = await fs2.readFile(routePath2, "utf-8");
@@ -83,8 +83,8 @@ async function isDocumentedRoute(routePath2) {
83
83
  }
84
84
 
85
85
  // src/core/next.ts
86
- import fs3 from "node:fs/promises";
87
- import path2 from "node:path";
86
+ import fs3 from "fs/promises";
87
+ import path2 from "path";
88
88
 
89
89
  // src/utils/generateRandomString.ts
90
90
  function generateRandomString(length) {
@@ -207,7 +207,7 @@ function verifyOptions(include, exclude) {
207
207
  }
208
208
 
209
209
  // src/core/getRoutePathName.ts
210
- import path3 from "node:path";
210
+ import path3 from "path";
211
211
  function getRoutePathName(filePath, rootPath) {
212
212
  const dirName = path3.dirname(filePath);
213
213
  return "/" + path3.relative(rootPath, dirName).replaceAll("[", "{").replaceAll("]", "}").replaceAll("\\", "/");
@@ -236,36 +236,9 @@ function deepEqual(a, b) {
236
236
  }
237
237
 
238
238
  // src/core/zod-to-openapi.ts
239
- import { zodToJsonSchema } from "zod-to-json-schema";
240
-
241
- // src/utils/zod-schema.ts
242
- function isFile(schema) {
243
- const file = new File([], "nothing.txt");
244
- const plainObject = { name: "test", size: 0 };
245
- const fileResult = schema.safeParse(file);
246
- const objectResult = schema.safeParse(plainObject);
247
- return fileResult.success && !objectResult.success;
248
- }
249
-
250
- // src/core/zod-to-openapi.ts
239
+ import { z } from "zod";
251
240
  function convertToOpenAPI(schema, isArray) {
252
- const result = zodToJsonSchema(isArray ? schema.array() : schema, {
253
- target: "openApi3",
254
- $refStrategy: "none"
255
- });
256
- if (result.type === "object" && result.properties) {
257
- for (const [propName, prop] of Object.entries(schema.shape)) {
258
- if (isFile(prop)) {
259
- result.properties[propName] = {
260
- type: "string",
261
- format: "binary",
262
- description: prop.description
263
- // contentEncoding: "base64", // swagger-ui-react doesn't support this
264
- };
265
- }
266
- }
267
- }
268
- return result;
241
+ return z.toJSONSchema(isArray ? schema.array() : schema);
269
242
  }
270
243
 
271
244
  // src/core/mask.ts
@@ -398,6 +371,7 @@ async function generateOpenApiSpec(schemas, {
398
371
  exclude: excludeOption = [],
399
372
  routeDefinerName = "defineRoute",
400
373
  rootPath: additionalRootPath,
374
+ info,
401
375
  servers,
402
376
  security,
403
377
  securitySchemes,
@@ -432,21 +406,22 @@ async function generateOpenApiSpec(schemas, {
432
406
  securitySchemes
433
407
  }
434
408
  };
435
- return {
409
+ return JSON.parse(JSON.stringify({
436
410
  openapi: "3.1.0",
437
411
  info: {
438
412
  title: metadata.serviceName,
439
- version: metadata.version
413
+ version: metadata.version,
414
+ ...info ?? {}
440
415
  },
441
416
  servers,
442
417
  ...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
443
418
  security,
444
419
  tags: []
445
- };
420
+ }));
446
421
  }
447
422
 
448
423
  // src/index.ts
449
- var src_default = generateOpenApiSpec;
424
+ var index_default = generateOpenApiSpec;
450
425
  export {
451
- src_default as default
426
+ index_default as default
452
427
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/next-openapi-json-generator",
3
- "version": "1.3.3",
3
+ "version": "2.0.0",
4
4
  "description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
5
5
  "keywords": [
6
6
  "next.js",
@@ -40,28 +40,28 @@
40
40
  }
41
41
  },
42
42
  "scripts": {
43
- "test": "jest",
43
+ "test": "vitest run --coverage",
44
+ "test:watch": "vitest --coverage",
44
45
  "dev": "tsup --watch",
45
46
  "build": "tsup"
46
47
  },
48
+ "peerDependencies": {
49
+ "@omer-x/next-openapi-route-handler": "^2",
50
+ "@omer-x/openapi-types": "^1",
51
+ "zod": "^4",
52
+ "typescript": "^5"
53
+ },
47
54
  "dependencies": {
48
55
  "@omer-x/package-metadata": "^1.0.2",
49
- "minimatch": "^10.0.1",
50
- "typescript": "^5.7.2",
51
- "zod-to-json-schema": "^3.24.1"
56
+ "minimatch": "^10.0.3"
52
57
  },
53
58
  "devDependencies": {
54
- "@omer-x/eslint-config": "^2.1.2",
55
- "@types/node": "^22.10.2",
56
- "eslint": "^9.16.0",
57
- "semantic-release": "^24.2.0",
58
- "ts-jest": "^29.2.5",
59
- "ts-node": "^10.9.2",
60
- "tsup": "^8.3.5",
61
- "zod": "^3.24.1"
62
- },
63
- "peerDependencies": {
64
- "@omer-x/next-openapi-route-handler": "^1",
65
- "@omer-x/openapi-types": "^1"
59
+ "@omer-x/eslint-config": "^2.1.3",
60
+ "@types/node": "^24.0.14",
61
+ "@vitest/coverage-v8": "^3.2.4",
62
+ "eslint": "^9.31.0",
63
+ "semantic-release": "^24.2.7",
64
+ "tsup": "^8.5.0",
65
+ "vitest": "^3.2.4"
66
66
  }
67
67
  }