Skip to content

[Backport 8.19] Support validating multiple APIs at once #4674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions .github/validate-pr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions compiler/run-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/validation-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.