Skip to content

Commit 6010e4a

Browse files
Kinfe123RikhiSinghBekacru
authored
fix: circular ref json serialization (#29)
* feat: implement safeStringify to handle circular references in JSON serialization * update and test * test update * chore: add ref * chore: lint * chore: fix types * fix: tests * remove only modifier * chore: fix types --------- Co-authored-by: Rikhi Singh <114336052+RikhiSingh@users.noreply.github.com> Co-authored-by: Bereket Engida <86073083+Bekacru@users.noreply.github.com> Co-authored-by: Bereket Engida <Bekacru@gmail.com>
1 parent c2f8c8e commit 6010e4a

6 files changed

Lines changed: 579 additions & 22 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"typescript": "^5.6.0-beta",
3535
"valibot": "1.0.0-beta.15",
3636
"vitest": "^3.1.1",
37-
"zod": "^3.24.1"
37+
"zod": "^4.0.1"
3838
},
3939
"dependencies": {
4040
"@better-fetch/fetch": "^1.1.4",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/endpoint.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe("types", async () => {
143143
"/path",
144144
{
145145
method: "POST",
146-
body: z.record(z.string()),
146+
body: z.record(z.string(), z.string()),
147147
metadata: {
148148
$Infer: {
149149
body: {} as {
@@ -206,7 +206,7 @@ describe("types", async () => {
206206
"/path",
207207
{
208208
method: "POST",
209-
body: z.record(z.string()),
209+
body: z.record(z.string(), z.string()),
210210
metadata: {
211211
$Infer: {
212212
query: {} as {

src/openapi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ZodObject, ZodOptional, ZodSchema } from "zod";
1+
import { ZodObject, ZodOptional, ZodType } from "zod";
22
import type { Endpoint, EndpointOptions } from "./endpoint";
33

44
export type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
@@ -82,7 +82,7 @@ export interface Path {
8282
}
8383
const paths: Record<string, Path> = {};
8484

85-
function getTypeFromZodType(zodType: ZodSchema) {
85+
function getTypeFromZodType(zodType: ZodType<any>) {
8686
switch (zodType.constructor.name) {
8787
case "ZodString":
8888
return "string";
@@ -107,7 +107,7 @@ function getParameters(options: EndpointOptions) {
107107
}
108108
if (options.query instanceof ZodObject) {
109109
Object.entries(options.query.shape).forEach(([key, value]) => {
110-
if (value instanceof ZodSchema) {
110+
if (value instanceof ZodObject) {
111111
parameters.push({
112112
name: key,
113113
in: "query",
@@ -139,7 +139,7 @@ function getRequestBody(options: EndpointOptions): any {
139139
const properties: Record<string, any> = {};
140140
const required: string[] = [];
141141
Object.entries(shape).forEach(([key, value]) => {
142-
if (value instanceof ZodSchema) {
142+
if (value instanceof ZodObject) {
143143
properties[key] = {
144144
type: getTypeFromZodType(value),
145145
description: value.description,

0 commit comments

Comments
 (0)