diff --git a/.github/validate-pr/index.js b/.github/validate-pr/index.js index a9095fcf5d..1c7c336daf 100644 --- a/.github/validate-pr/index.js +++ b/.github/validate-pr/index.js @@ -86,6 +86,9 @@ async function run() { cd(tsValidationPath) + // Collect all APIs to validate + const apisToValidate = new Set() + for (const file of specFiles) { if (file.startsWith('specification/_types')) continue if (file.startsWith('specification/_spec_utils')) continue @@ -97,32 +100,35 @@ async function run() { .filter(endpoint => endpoint.name.split('.').filter(s => !privateNames.includes(s))[0] === getApi(file).split('.')[0]) .map(endpoint => endpoint.name) for (const api of apis) { - const report = await getReport({ - api, - 'generate-report': false, - request: true, - response: true, - ci: false, - verbose: false - }) - const namespace = getNamespace(api) - // Asked to validate a specific API, so we only store that one - reports.set(api, report.get(namespace)[0]) + apisToValidate.add(api) } } else { const api = getApi(file) - const report = await getReport({ - api, - 'generate-report': false, - request: true, - response: true, - ci: false, - verbose: false - }) + apisToValidate.add(api) + } + } + // Call getReport once with all APIs + if (apisToValidate.size > 0) { + const allApis = Array.from(apisToValidate).join(',') + const report = await getReport({ + api: allApis, + 'generate-report': false, + request: true, + response: true, + ci: false, + verbose: false + }) + + // Extract individual API reports from the combined result + for (const api of apisToValidate) { const namespace = getNamespace(api) - // Asked to validate a specific API, so we only store that one - reports.set(api, report.get(namespace)[0]) + if (report.has(namespace)) { + const namespaceReport = report.get(namespace).find(r => r.api === getName(api)) + if (namespaceReport) { + reports.set(api, namespaceReport) + } + } } } diff --git a/README.md b/README.md index b098e14f87..440f3192d9 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,9 @@ make validate api=xpack.info type=request branch=main # this will validate the xpack.info request and response types against the 8.15 branch make validate api=xpack.info branch=8.15 + +# this will validate the xpack.info and search request and response types against the 8.15 branch +make validate api=xpack.info,search branch=8.15 ``` The last command above will install all the dependencies and run, download diff --git a/compiler/run-validations.js b/compiler/run-validations.js index 9f68cfd66d..065bf795b3 100755 --- a/compiler/run-validations.js +++ b/compiler/run-validations.js @@ -78,8 +78,11 @@ async function run () { process.exit(1) } - if (!apis.includes(options.api)) { - spinner.fail(`The api '${options.api}' does not exists, did you mean '${closest(options.api, apis)}'?`) + const apiList = options.api.split(',').map(api => api.trim()) + const invalidApis = apiList.filter(api => !apis.includes(api)) + if (invalidApis.length > 0) { + const suggestions = invalidApis.map(api => `'${api}' (did you mean '${closest(api, apis)}'?)`).join(', ') + spinner.fail(`The following APIs do not exist: ${suggestions}`) process.exit(1) } // if the empty string it's because the make target wasn't configured with a type argument diff --git a/docs/validation-example.md b/docs/validation-example.md index 5467635e39..7112a79d67 100644 --- a/docs/validation-example.md +++ b/docs/validation-example.md @@ -16,7 +16,7 @@ The example assumes that you have already performed the necessary steps to run a if not, take a look at the [README](../README.md). ```sh -make validate api=index type=request branch=main +make validate api=index branch=main ``` You will see an output like the following: @@ -82,7 +82,7 @@ open it with your favourite editor and perform the fix Finally run the validation again: ```sh -make validate api=index type=request branch=main +make validate api=index branch=main ``` If there are no more errors, open a pull request with the fix.