diff --git a/scripts/process-specs.ts b/scripts/process-specs.ts index b101f80b74e..a53f6e6e6e1 100644 --- a/scripts/process-specs.ts +++ b/scripts/process-specs.ts @@ -18,8 +18,8 @@ function processOpenAPISpec(spec: OpenAPIV3.Document) { // Process 'paths' property const newPaths: Record = {}; for (const [path, pathItem] of Object.entries(newSpec.paths)) { - // Remove 'watch' paths as they're deprecated / remove empty path items - if (path.includes('/watch/') || !pathItem) { + // Remove empty path items + if (!pathItem) { continue; } // Remove the specified part from the path key @@ -27,12 +27,13 @@ function processOpenAPISpec(spec: OpenAPIV3.Document) { // Process each method in the path (e.g., get, post) const newPathItem: Record = {}; - for (const method of Object.keys(pathItem)) { - // Filter out the 'namespace' param - if (method === 'parameters' && Array.isArray(pathItem.parameters)) { - pathItem.parameters = pathItem.parameters?.filter((param) => 'name' in param && param.name !== 'namespace'); - } + // Filter out namespace parameter at path level + if (Array.isArray(pathItem.parameters)) { + pathItem.parameters = filterNamespaceParameters(pathItem.parameters); + } + + for (const method of Object.keys(pathItem)) { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const operation = pathItem[method as keyof OpenAPIV3.PathItemObject]; @@ -45,6 +46,16 @@ function processOpenAPISpec(spec: OpenAPIV3.Document) { continue; } + // Filter out namespace parameter at operation level + if ( + operation && + typeof operation === 'object' && + 'parameters' in operation && + Array.isArray(operation.parameters) + ) { + operation.parameters = filterNamespaceParameters(operation.parameters); + } + updateRefs(operation); newPathItem[method] = operation; @@ -69,6 +80,13 @@ function processOpenAPISpec(spec: OpenAPIV3.Document) { return newSpec; } +/** + * Filter out namespace parameters from an array of parameters + */ +function filterNamespaceParameters(parameters: Array) { + return parameters.filter((param) => 'name' in param && param.name !== 'namespace'); +} + /** * Recursively update all $ref fields to remove k8s metadata from names */