Skip to content

Commit 9021f88

Browse files
fix: ignore openapi path metadata in sparsekernel check
1 parent 9a7c600 commit 9021f88

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

scripts/check-sparsekernel-openapi.mjs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import { parse } from "yaml";
55
const OPENAPI_PATH = "schemas/sparsekernel.openapi.yaml";
66
const DAEMON_PATH = "crates/sparsekernel-cli/src/lib.rs";
77
const CLIENT_PATH = "packages/sparsekernel-client/src/index.ts";
8+
const OPENAPI_HTTP_METHODS = new Set([
9+
"get",
10+
"post",
11+
"put",
12+
"patch",
13+
"delete",
14+
"options",
15+
"head",
16+
"trace",
17+
]);
818
const CLIENT_SCHEMA_MAPPINGS = [
919
mapping("SparseKernelHealth", "Health"),
1020
mapping("SparseKernelInspect", "Inspect"),
@@ -293,7 +303,7 @@ function collectOpenApiRouteKeys(paths) {
293303
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
294304
continue;
295305
}
296-
for (const method of Object.keys(operations)) {
306+
for (const method of Object.keys(operations).filter(isOpenApiHttpMethod)) {
297307
routeKeys.add(`${method.toUpperCase()} ${routePath}`);
298308
}
299309
}
@@ -328,7 +338,7 @@ export function collectOpenApiOperationIdProblems(paths) {
328338
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
329339
continue;
330340
}
331-
for (const [method, operation] of Object.entries(operations)) {
341+
for (const [method, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
332342
const routeKey = `${method.toUpperCase()} ${routePath}`;
333343
const operationId = operationIdFor(operation);
334344
if (!operationId) {
@@ -391,7 +401,7 @@ export function collectOpenApiMissingJsonResponseSchemaRoutes(paths) {
391401
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
392402
continue;
393403
}
394-
for (const [method, operation] of Object.entries(operations)) {
404+
for (const [method, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
395405
const schema = jsonResponseSchema(operation);
396406
if (!schema) {
397407
routes.push(`${method.toUpperCase()} ${routePath}`);
@@ -407,7 +417,7 @@ export function collectOpenApiInlineObjectResponseSchemaRoutes(paths) {
407417
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
408418
continue;
409419
}
410-
for (const [method, operation] of Object.entries(operations)) {
420+
for (const [method, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
411421
const schema = jsonResponseSchema(operation);
412422
if (schema && isInlineObjectResponseSchema(schema)) {
413423
routes.push(`${method.toUpperCase()} ${routePath}`);
@@ -427,7 +437,7 @@ export function collectOpenApiInlineArrayResponseItemRoutes(paths) {
427437
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
428438
continue;
429439
}
430-
for (const [method, operation] of Object.entries(operations)) {
440+
for (const [method, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
431441
const schema = jsonResponseSchema(operation);
432442
if (schema?.type === "array" && !schema.items?.$ref) {
433443
routes.push(`${method.toUpperCase()} ${routePath}`);
@@ -454,7 +464,7 @@ export function collectOpenApiRequestBodySchemaNames(paths) {
454464
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
455465
continue;
456466
}
457-
for (const operation of Object.values(operations)) {
467+
for (const [, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
458468
const ref = requestBodySchemaRef(operation);
459469
if (ref?.startsWith("#/components/schemas/")) {
460470
schemaNames.add(ref.slice("#/components/schemas/".length));
@@ -478,7 +488,7 @@ export function collectOpenApiInlineRequestBodyRoutes(paths) {
478488
if (!operations || typeof operations !== "object" || Array.isArray(operations)) {
479489
continue;
480490
}
481-
for (const [method, operation] of Object.entries(operations)) {
491+
for (const [method, operation] of Object.entries(operations).filter(isOpenApiOperationEntry)) {
482492
const schema = requestBodySchema(operation);
483493
if (schema && !schema.$ref) {
484494
routes.add(`${method.toUpperCase()} ${routePath}`);
@@ -504,6 +514,14 @@ function requestBodySchema(operation) {
504514
return schema;
505515
}
506516

517+
function isOpenApiOperationEntry([method]) {
518+
return isOpenApiHttpMethod(method);
519+
}
520+
521+
function isOpenApiHttpMethod(method) {
522+
return OPENAPI_HTTP_METHODS.has(method.toLowerCase());
523+
}
524+
507525
function methodForClientCall(callName) {
508526
return callName === "getJson" ? "GET" : "POST";
509527
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("scripts/check-sparsekernel-openapi", () => {
8888
it("finds missing and duplicate operation ids", () => {
8989
const paths = {
9090
"/tasks": {
91+
parameters: [{ name: "agentId", in: "query" }],
9192
get: { operationId: "listTasks" },
9293
},
9394
"/tasks/enqueue": {
@@ -107,6 +108,7 @@ describe("scripts/check-sparsekernel-openapi", () => {
107108
it("finds operations missing 200 JSON response schemas", () => {
108109
const paths = {
109110
"/health": {
111+
parameters: [{ name: "agentId", in: "query" }],
110112
get: {
111113
responses: {
112114
"200": {
@@ -220,6 +222,7 @@ describe("scripts/check-sparsekernel-openapi", () => {
220222
it("finds inline request body schemas that bypass client parity mappings", () => {
221223
const paths = {
222224
"/leases/release-expired": {
225+
parameters: [{ name: "agentId", in: "query" }],
223226
post: {
224227
requestBody: {
225228
content: {

0 commit comments

Comments
 (0)