@@ -5,6 +5,16 @@ import { parse } from "yaml";
55const OPENAPI_PATH = "schemas/sparsekernel.openapi.yaml" ;
66const DAEMON_PATH = "crates/sparsekernel-cli/src/lib.rs" ;
77const 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+ ] ) ;
818const 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+
507525function methodForClientCall ( callName ) {
508526 return callName === "getJson" ? "GET" : "POST" ;
509527}
0 commit comments