@riktajs/swagger 0.1.3 → 0.2.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.
@@ -1,5 +1,5 @@
1
- import type { ZodType, ZodTypeDef } from 'zod';
1
+ import { type ZodType } from 'zod';
2
2
  import type { OpenApiSchemaObject } from '../types.js';
3
- export declare function isZodSchema(value: unknown): value is ZodType<unknown, ZodTypeDef, unknown>;
3
+ export declare function isZodSchema(value: unknown): value is ZodType<unknown>;
4
4
  export declare function zodToOpenApi(schema: ZodType): OpenApiSchemaObject;
5
5
  export declare function toOpenApiSchema(schemaOrOpenApi: ZodType | OpenApiSchemaObject | undefined): OpenApiSchemaObject | undefined;
@@ -1,8 +1,8 @@
1
- import { zodToJsonSchema } from 'zod-to-json-schema';
1
+ import { z } from 'zod';
2
2
  export function isZodSchema(value) {
3
3
  return (value !== null &&
4
4
  typeof value === 'object' &&
5
- '_def' in value &&
5
+ ('_zod' in value || '_def' in value) &&
6
6
  'safeParse' in value &&
7
7
  typeof value.safeParse === 'function');
8
8
  }
@@ -85,9 +85,22 @@ function jsonSchemaToOpenApi(jsonSchema) {
85
85
  return result;
86
86
  }
87
87
  export function zodToOpenApi(schema) {
88
- const jsonSchema = zodToJsonSchema(schema, {
89
- target: 'openApi3',
90
- $refStrategy: 'none',
88
+ const jsonSchema = z.toJSONSchema(schema, {
89
+ target: 'openapi-3.0',
90
+ unrepresentable: 'any',
91
+ override: (ctx) => {
92
+ const def = ctx.zodSchema._zod?.def;
93
+ if (!def)
94
+ return;
95
+ if (def.type === 'date') {
96
+ ctx.jsonSchema.type = 'string';
97
+ ctx.jsonSchema.format = 'date-time';
98
+ }
99
+ if (def.type === 'bigint') {
100
+ ctx.jsonSchema.type = 'integer';
101
+ ctx.jsonSchema.format = 'int64';
102
+ }
103
+ },
91
104
  });
92
105
  return jsonSchemaToOpenApi(jsonSchema);
93
106
  }
package/package.json CHANGED
@@ -1,63 +1,62 @@
1
- {
2
- "name": "@riktajs/swagger",
3
- "version": "0.1.3",
4
- "description": "Automatic OpenAPI/Swagger documentation generation for Rikta Framework",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "clean": "rm -rf dist",
13
- "prebuild": "npm run clean",
14
- "build": "tsc",
15
- "dev": "tsc --watch",
16
- "test": "vitest run",
17
- "test:watch": "vitest",
18
- "test:coverage": "vitest run --coverage",
19
- "prepublishOnly": "npm run build"
20
- },
21
- "keywords": [
22
- "rikta",
23
- "swagger",
24
- "openapi",
25
- "documentation",
26
- "fastify",
27
- "typescript",
28
- "decorators",
29
- "api-docs"
30
- ],
31
- "author": "",
32
- "license": "MIT",
33
- "peerDependencies": {
34
- "@riktajs/core": ">=0.4.3",
35
- "fastify": ">=5.0.0",
36
- "reflect-metadata": ">=0.2.0",
37
- "zod": ">=3.20.0"
38
- },
39
- "peerDependenciesMeta": {
40
- "zod": {
41
- "optional": true
42
- }
43
- },
44
- "dependencies": {
45
- "@fastify/swagger": "^9.4.2",
46
- "@fastify/swagger-ui": "^5.2.1",
47
- "fastify-plugin": "^5.0.1",
48
- "zod-to-json-schema": "^3.25.1"
49
- },
50
- "devDependencies": {
51
- "@riktajs/core": "*",
52
- "@types/node": "^22.10.2",
53
- "@vitest/coverage-v8": "^2.1.9",
54
- "fastify": "^5.3.2",
55
- "reflect-metadata": "^0.2.2",
56
- "typescript": "^5.7.2",
57
- "vitest": "^2.1.8",
58
- "zod": "^3.25.76"
59
- },
60
- "engines": {
61
- "node": ">=20.0.0"
62
- }
63
- }
1
+ {
2
+ "name": "@riktajs/swagger",
3
+ "version": "0.2.0",
4
+ "description": "Automatic OpenAPI/Swagger documentation generation for Rikta Framework",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "clean": "rm -rf dist",
13
+ "prebuild": "npm run clean",
14
+ "build": "tsc",
15
+ "dev": "tsc --watch",
16
+ "test": "vitest run",
17
+ "test:watch": "vitest",
18
+ "test:coverage": "vitest run --coverage",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "keywords": [
22
+ "rikta",
23
+ "swagger",
24
+ "openapi",
25
+ "documentation",
26
+ "fastify",
27
+ "typescript",
28
+ "decorators",
29
+ "api-docs"
30
+ ],
31
+ "author": "",
32
+ "license": "MIT",
33
+ "peerDependencies": {
34
+ "@riktajs/core": ">=0.4.3",
35
+ "fastify": ">=5.0.0",
36
+ "reflect-metadata": ">=0.2.0",
37
+ "zod": ">=4.0.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "zod": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "dependencies": {
45
+ "@fastify/swagger": "^9.4.2",
46
+ "@fastify/swagger-ui": "^5.2.1",
47
+ "fastify-plugin": "^5.0.1"
48
+ },
49
+ "devDependencies": {
50
+ "@riktajs/core": "*",
51
+ "@types/node": "^22.10.2",
52
+ "@vitest/coverage-v8": "^2.1.9",
53
+ "fastify": "^5.3.2",
54
+ "reflect-metadata": "^0.2.2",
55
+ "typescript": "^5.7.2",
56
+ "vitest": "^2.1.8",
57
+ "zod": "^4.3.5"
58
+ },
59
+ "engines": {
60
+ "node": ">=20.0.0"
61
+ }
62
+ }