Skip to content

Commit 3d39ecb

Browse files
committed
test: fix tests
1 parent bcb77a8 commit 3d39ecb

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

src/core/generateOpenApiSpec.test.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("generateOpenApiSpec", () => {
6464

6565
const result = await generateOpenApiSpec(schemas);
6666

67-
expect(result).toEqual({
67+
expect(result).toStrictEqual({
6868
openapi: "3.1.0",
6969
info: {
7070
title: "Test Service",
@@ -78,13 +78,11 @@ describe("generateOpenApiSpec", () => {
7878
operationId: "getUsers",
7979
parameters: [
8080
{
81-
description: "List of the column names",
8281
in: "query",
8382
name: "select",
84-
required: false,
83+
required: true,
8584
schema: {
8685
default: [],
87-
description: "List of the column names",
8886
items: {
8987
enum: [
9088
"id",
@@ -96,7 +94,6 @@ describe("generateOpenApiSpec", () => {
9694
},
9795
},
9896
],
99-
requestBody: undefined,
10097
responses: {
10198
200: {
10299
content: {
@@ -112,11 +109,9 @@ describe("generateOpenApiSpec", () => {
112109
description: "Returns a list of users",
113110
},
114111
400: {
115-
content: undefined,
116112
description: "Bad Request",
117113
},
118114
500: {
119-
content: undefined,
120115
description: "Internal Server Error",
121116
},
122117
},
@@ -127,7 +122,6 @@ describe("generateOpenApiSpec", () => {
127122
post: {
128123
description: "Create a new user",
129124
operationId: "createUser",
130-
parameters: undefined,
131125
requestBody: {
132126
content: {
133127
"application/json": {
@@ -150,11 +144,9 @@ describe("generateOpenApiSpec", () => {
150144
description: "User created successfully",
151145
},
152146
400: {
153-
content: undefined,
154147
description: "Bad Request",
155148
},
156149
409: {
157-
content: undefined,
158150
description: "Email already exists",
159151
},
160152
500: {
@@ -183,6 +175,7 @@ describe("generateOpenApiSpec", () => {
183175
},
184176
additionalProperties: false,
185177
required: ["id", "name"],
178+
$schema: "https://json-schema.org/draft/2020-12/schema",
186179
},
187180
NewUserDTO: {
188181
type: "object",
@@ -196,6 +189,7 @@ describe("generateOpenApiSpec", () => {
196189
},
197190
additionalProperties: false,
198191
required: ["name"],
192+
$schema: "https://json-schema.org/draft/2020-12/schema",
199193
},
200194
},
201195
},
@@ -249,13 +243,11 @@ describe("generateOpenApiSpec", () => {
249243
operationId: "getUsers",
250244
parameters: [
251245
{
252-
description: "List of the column names",
253246
in: "query",
254247
name: "select",
255-
required: false,
248+
required: true,
256249
schema: {
257250
default: [],
258-
description: "List of the column names",
259251
items: {
260252
enum: [
261253
"id",
@@ -267,7 +259,6 @@ describe("generateOpenApiSpec", () => {
267259
},
268260
},
269261
],
270-
requestBody: undefined,
271262
responses: {
272263
200: {
273264
content: {
@@ -283,11 +274,9 @@ describe("generateOpenApiSpec", () => {
283274
description: "Returns a list of users",
284275
},
285276
400: {
286-
content: undefined,
287277
description: "Bad Request",
288278
},
289279
500: {
290-
content: undefined,
291280
description: "Internal Server Error",
292281
},
293282
},
@@ -298,7 +287,6 @@ describe("generateOpenApiSpec", () => {
298287
post: {
299288
description: "Create a new user",
300289
operationId: "createUser",
301-
parameters: undefined,
302290
requestBody: {
303291
content: {
304292
"application/json": {
@@ -321,11 +309,9 @@ describe("generateOpenApiSpec", () => {
321309
description: "User created successfully",
322310
},
323311
400: {
324-
content: undefined,
325312
description: "Bad Request",
326313
},
327314
409: {
328-
content: undefined,
329315
description: "Email already exists",
330316
},
331317
500: {
@@ -354,6 +340,7 @@ describe("generateOpenApiSpec", () => {
354340
},
355341
additionalProperties: false,
356342
required: ["id", "name"],
343+
$schema: "https://json-schema.org/draft/2020-12/schema",
357344
},
358345
NewUserDTO: {
359346
type: "object",
@@ -367,6 +354,7 @@ describe("generateOpenApiSpec", () => {
367354
},
368355
additionalProperties: false,
369356
required: ["name"],
357+
$schema: "https://json-schema.org/draft/2020-12/schema",
370358
},
371359
},
372360
},

src/core/generateOpenApiSpec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
6565
},
6666
};
6767

68-
return {
68+
return JSON.parse(JSON.stringify({
6969
openapi: "3.1.0",
7070
info: {
7171
title: metadata.serviceName,
@@ -76,5 +76,5 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
7676
...(clearUnusedSchemasOption ? clearUnusedSchemasFunction(pathsAndComponents) : pathsAndComponents),
7777
security,
7878
tags: [],
79-
} as Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>;
79+
})) as Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>;
8080
}

src/core/mask.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ describe("maskWithReference", () => {
2525
},
2626
required: ["id", "name"],
2727
additionalProperties: false,
28+
// @ts-expect-error: @omer-x/openapi-types doesn't have this
29+
$schema: "https://json-schema.org/draft/2020-12/schema",
2830
};
2931

3032
const result = maskWithReference(schema, storedSchemas, true);
@@ -80,6 +82,8 @@ describe("maskWithReference", () => {
8082
},
8183
required: ["id", "name"],
8284
additionalProperties: false,
85+
// @ts-expect-error: @omer-x/openapi-types doesn't have this
86+
$schema: "https://json-schema.org/draft/2020-12/schema",
8387
};
8488
const result = maskWithReference(schema, storedSchemas, true);
8589
expect(result).toEqual({

src/core/route.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ describe("bundlePaths", () => {
125125
email: {
126126
type: "string",
127127
format: "email",
128+
pattern: "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
128129
},
129130
},
130131
required: ["name", "email"],
131132
additionalProperties: false,
133+
$schema: "https://json-schema.org/draft/2020-12/schema",
132134
},
133135
},
134136
},
@@ -140,7 +142,7 @@ describe("bundlePaths", () => {
140142
const storedSchemas: Record<string, ZodType> = {
141143
UserDTO: z.object({
142144
name: z.string(),
143-
email: z.string().email(),
145+
email: z.email(),
144146
}),
145147
};
146148

src/core/schema.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ describe("bundleSchemas", () => {
2828
},
2929
additionalProperties: false,
3030
required: ["name", "age"],
31+
// @ts-expect-error: @omer-x/openapi-types doesn't have this
32+
$schema: "https://json-schema.org/draft/2020-12/schema",
3133
},
3234
Product: {
3335
type: "object",
@@ -41,12 +43,14 @@ describe("bundleSchemas", () => {
4143
},
4244
additionalProperties: false,
4345
required: ["title", "price"],
46+
// @ts-expect-error: @omer-x/openapi-types doesn't have this
47+
$schema: "https://json-schema.org/draft/2020-12/schema",
4448
},
4549
};
4650

4751
it("should convert and mask schemas correctly", () => {
4852
const result = bundleSchemas(mockSchemas);
49-
expect(result).toEqual(mockOpenAPISchemas);
53+
expect(result).toStrictEqual(mockOpenAPISchemas);
5054
});
5155

5256
it("should handle empty schemas object", () => {

0 commit comments

Comments
 (0)