Skip to content

Commit 791c9d1

Browse files
authored
Merge pull request #3794 from vcode-sh/fix/openapi-bigint-serialization
fix: resolve OpenAPI 500 error caused by BigInt serialization
2 parents 760edc6 + f076e72 commit 791c9d1

File tree

12 files changed

+39
-33
lines changed

12 files changed

+39
-33
lines changed

apps/dokploy/__test__/server/mechanizeDockerContainer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const createApplication = (
5757
env: null,
5858
},
5959
replicas: 1,
60-
stopGracePeriodSwarm: 0n,
60+
stopGracePeriodSwarm: 0,
6161
ulimitsSwarm: null,
6262
serverId: "server-id",
6363
...overrides,
@@ -76,8 +76,8 @@ describe("mechanizeDockerContainer", () => {
7676
});
7777
});
7878

79-
it("converts bigint stopGracePeriodSwarm to a number and keeps zero values", async () => {
80-
const application = createApplication({ stopGracePeriodSwarm: 0n });
79+
it("passes stopGracePeriodSwarm as a number and keeps zero values", async () => {
80+
const application = createApplication({ stopGracePeriodSwarm: 0 });
8181

8282
await mechanizeDockerContainer(application);
8383

apps/dokploy/components/dashboard/application/advanced/cluster/modify-swarm-settings.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ const menuItems: MenuItem[] = [
110110
},
111111
];
112112

113+
const hasStopGracePeriodSwarm = (
114+
value: unknown,
115+
): value is { stopGracePeriodSwarm: number | string | null } =>
116+
typeof value === "object" &&
117+
value !== null &&
118+
"stopGracePeriodSwarm" in value;
119+
113120
interface Props {
114121
id: string;
115122
type:

apps/dokploy/components/dashboard/application/advanced/cluster/swarm-forms/stop-grace-period-form.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { api } from "@/utils/api";
1616

1717
const hasStopGracePeriodSwarm = (
1818
value: unknown,
19-
): value is { stopGracePeriodSwarm: bigint | number | string | null } =>
19+
): value is { stopGracePeriodSwarm: number | string | null } =>
2020
typeof value === "object" &&
2121
value !== null &&
2222
"stopGracePeriodSwarm" in value;
@@ -68,19 +68,15 @@ export const StopGracePeriodForm = ({ id, type }: StopGracePeriodFormProps) => {
6868

6969
const form = useForm<any>({
7070
defaultValues: {
71-
value: null as bigint | null,
71+
value: null as number | null,
7272
},
7373
});
7474

7575
useEffect(() => {
7676
if (hasStopGracePeriodSwarm(data)) {
7777
const value = data.stopGracePeriodSwarm;
7878
const normalizedValue =
79-
value === null || value === undefined
80-
? null
81-
: typeof value === "bigint"
82-
? value
83-
: BigInt(value);
79+
value === null || value === undefined ? null : Number(value);
8480
form.reset({
8581
value: normalizedValue,
8682
});
@@ -136,7 +132,7 @@ export const StopGracePeriodForm = ({ id, type }: StopGracePeriodFormProps) => {
136132
}
137133
onChange={(e) =>
138134
field.onChange(
139-
e.target.value ? BigInt(e.target.value) : null,
135+
e.target.value ? Number(e.target.value) : null,
140136
)
141137
}
142138
/>

apps/dokploy/pages/api/[...trpc].ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
1616
return createOpenApiNextHandler({
1717
router: appRouter,
1818
createContext: createTRPCContext,
19+
onError:
20+
process.env.NODE_ENV === "development"
21+
? ({ path, error }: { path: string | undefined; error: Error }) => {
22+
console.error(
23+
`❌ OpenAPI failed on ${path ?? "<no-path>"}: ${error.message}`,
24+
);
25+
}
26+
: undefined,
1927
})(req, res);
2028
};
2129

packages/server/src/db/schema/application.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export const applications = pgTable("application", {
174174
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
175175
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
176176
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
177-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
177+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
178178
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
179179
ulimitsSwarm: json("ulimitsSwarm").$type<UlimitsSwarm>(),
180180
//
@@ -369,7 +369,7 @@ const createSchema = createInsertSchema(applications, {
369369
watchPaths: z.array(z.string()).optional().optional(),
370370
previewLabels: z.array(z.string()).optional(),
371371
cleanCache: z.boolean().optional(),
372-
stopGracePeriodSwarm: z.bigint().nullable(),
372+
stopGracePeriodSwarm: z.number().nullable(),
373373
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
374374
ulimitsSwarm: UlimitsSwarmSchema.nullable(),
375375
enableSubmodules: z.boolean().optional(),

packages/server/src/db/schema/libsql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const libsql = pgTable("libsql", {
7979
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
8080
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
8181
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
82-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
82+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
8383
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
8484
replicas: integer("replicas").default(1).notNull(),
8585
createdAt: text("createdAt")
@@ -143,7 +143,7 @@ const createSchema = createInsertSchema(libsql, {
143143
modeSwarm: ServiceModeSwarmSchema.nullable(),
144144
labelsSwarm: LabelsSwarmSchema.nullable(),
145145
networkSwarm: NetworkSwarmSchema.nullable(),
146-
stopGracePeriodSwarm: z.bigint().nullable(),
146+
stopGracePeriodSwarm: z.number().nullable(),
147147
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
148148
});
149149

packages/server/src/db/schema/mariadb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const mariadb = pgTable("mariadb", {
7373
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
7474
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
7575
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
76-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
76+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
7777
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
7878
ulimitsSwarm: json("ulimitsSwarm").$type<UlimitsSwarm>(),
7979
replicas: integer("replicas").default(1).notNull(),
@@ -144,7 +144,7 @@ const createSchema = createInsertSchema(mariadb, {
144144
modeSwarm: ServiceModeSwarmSchema.nullable(),
145145
labelsSwarm: LabelsSwarmSchema.nullable(),
146146
networkSwarm: NetworkSwarmSchema.nullable(),
147-
stopGracePeriodSwarm: z.bigint().nullable(),
147+
stopGracePeriodSwarm: z.number().nullable(),
148148
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
149149
ulimitsSwarm: UlimitsSwarmSchema.nullable(),
150150
});

packages/server/src/db/schema/mongo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const mongo = pgTable("mongo", {
7676
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
7777
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
7878
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
79-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
79+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
8080
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
8181
ulimitsSwarm: json("ulimitsSwarm").$type<UlimitsSwarm>(),
8282
replicas: integer("replicas").default(1).notNull(),
@@ -142,7 +142,7 @@ const createSchema = createInsertSchema(mongo, {
142142
modeSwarm: ServiceModeSwarmSchema.nullable(),
143143
labelsSwarm: LabelsSwarmSchema.nullable(),
144144
networkSwarm: NetworkSwarmSchema.nullable(),
145-
stopGracePeriodSwarm: z.bigint().nullable(),
145+
stopGracePeriodSwarm: z.number().nullable(),
146146
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
147147
ulimitsSwarm: UlimitsSwarmSchema.nullable(),
148148
});

packages/server/src/db/schema/mysql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const mysql = pgTable("mysql", {
7171
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
7272
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
7373
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
74-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
74+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
7575
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
7676
ulimitsSwarm: json("ulimitsSwarm").$type<UlimitsSwarm>(),
7777
replicas: integer("replicas").default(1).notNull(),
@@ -141,7 +141,7 @@ const createSchema = createInsertSchema(mysql, {
141141
modeSwarm: ServiceModeSwarmSchema.nullable(),
142142
labelsSwarm: LabelsSwarmSchema.nullable(),
143143
networkSwarm: NetworkSwarmSchema.nullable(),
144-
stopGracePeriodSwarm: z.bigint().nullable(),
144+
stopGracePeriodSwarm: z.number().nullable(),
145145
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
146146
ulimitsSwarm: UlimitsSwarmSchema.nullable(),
147147
});

packages/server/src/db/schema/postgres.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const postgres = pgTable("postgres", {
7171
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
7272
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
7373
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
74-
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
74+
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "number" }),
7575
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
7676
ulimitsSwarm: json("ulimitsSwarm").$type<UlimitsSwarm>(),
7777
replicas: integer("replicas").default(1).notNull(),
@@ -136,7 +136,7 @@ const createSchema = createInsertSchema(postgres, {
136136
modeSwarm: ServiceModeSwarmSchema.nullable(),
137137
labelsSwarm: LabelsSwarmSchema.nullable(),
138138
networkSwarm: NetworkSwarmSchema.nullable(),
139-
stopGracePeriodSwarm: z.bigint().nullable(),
139+
stopGracePeriodSwarm: z.number().nullable(),
140140
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
141141
ulimitsSwarm: UlimitsSwarmSchema.nullable(),
142142
});

0 commit comments

Comments
 (0)