Skip to content

Commit 1cf94e6

Browse files
test: cover sparsekernel referenced schemas
1 parent b83086c commit 1cf94e6

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

scripts/check-sparsekernel-openapi.mjs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,10 @@ export function checkSparseKernelOpenApi({ openapiText, daemonSource, clientSour
240240
}
241241

242242
const mappedSchemaNames = new Set(CLIENT_SCHEMA_MAPPINGS.map((item) => item.schemaName));
243-
const referencedSchemaNames = [...collectSchemaRefs(openapi)]
244-
.filter((ref) => ref.startsWith("#/components/schemas/"))
245-
.map((ref) => ref.slice("#/components/schemas/".length));
246243
pushSetDiff(
247244
errors,
248245
"SparseKernel OpenAPI referenced schemas missing client parity mapping",
249-
new Set(referencedSchemaNames),
246+
collectOpenApiReferencedSchemaNames(openapi),
250247
mappedSchemaNames,
251248
);
252249

@@ -311,6 +308,14 @@ export function collectOpenApiRequestBodySchemaNames(paths) {
311308
return schemaNames;
312309
}
313310

311+
export function collectOpenApiReferencedSchemaNames(openapi) {
312+
return new Set(
313+
[...collectSchemaRefs(openapi)]
314+
.filter((ref) => ref.startsWith("#/components/schemas/"))
315+
.map((ref) => ref.slice("#/components/schemas/".length)),
316+
);
317+
}
318+
314319
export function collectOpenApiInlineRequestBodyRoutes(paths) {
315320
const routes = new Set();
316321
for (const [routePath, operations] of Object.entries(paths)) {

test/scripts/check-sparsekernel-openapi.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import {
33
collectOpenApiInlineRequestBodyRoutes,
4+
collectOpenApiReferencedSchemaNames,
45
collectOpenApiRequestBodySchemaNames,
56
} from "../../scripts/check-sparsekernel-openapi.mjs";
67

@@ -26,6 +27,45 @@ describe("scripts/check-sparsekernel-openapi", () => {
2627
expect([...collectOpenApiRequestBodySchemaNames(paths)]).toEqual(["EnqueueTaskInput"]);
2728
});
2829

30+
it("collects all referenced component schemas for client parity coverage", () => {
31+
const openapi = {
32+
paths: {
33+
"/tasks": {
34+
get: {
35+
responses: {
36+
"200": {
37+
content: {
38+
"application/json": {
39+
schema: {
40+
type: "array",
41+
items: { $ref: "#/components/schemas/Task" },
42+
},
43+
},
44+
},
45+
},
46+
},
47+
},
48+
},
49+
"/tasks/enqueue": {
50+
post: {
51+
requestBody: {
52+
content: {
53+
"application/json": {
54+
schema: { $ref: "#/components/schemas/EnqueueTaskInput" },
55+
},
56+
},
57+
},
58+
},
59+
},
60+
},
61+
};
62+
63+
expect([...collectOpenApiReferencedSchemaNames(openapi)].sort()).toEqual([
64+
"EnqueueTaskInput",
65+
"Task",
66+
]);
67+
});
68+
2969
it("finds inline request body schemas that bypass client parity mappings", () => {
3070
const paths = {
3171
"/leases/release-expired": {

0 commit comments

Comments
 (0)