Skip to content

Commit ed7b3d0

Browse files
committed
Support validating multiple APIs at once
This means make validate api=search,index is possible, but more importantly that validation in CI will be much faster.
1 parent a07023b commit ed7b3d0

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

.github/validate-pr/index.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ async function run() {
8686

8787
cd(tsValidationPath)
8888

89+
// Collect all APIs to validate
90+
const apisToValidate = new Set()
91+
8992
for (const file of specFiles) {
9093
if (file.startsWith('specification/_types')) continue
9194
if (file.startsWith('specification/_spec_utils')) continue
@@ -102,32 +105,35 @@ async function run() {
102105
.filter(endpoint => endpoint.name.split('.').filter(s => !privateNames.includes(s))[0] === getApi(file).split('.')[0])
103106
.map(endpoint => endpoint.name)
104107
for (const api of apis) {
105-
const report = await getReport({
106-
api,
107-
'generate-report': false,
108-
request: true,
109-
response: true,
110-
ci: false,
111-
verbose: false
112-
})
113-
const namespace = getNamespace(api)
114-
// Asked to validate a specific API, so we only store that one
115-
reports.set(api, report.get(namespace)[0])
108+
apisToValidate.add(api)
116109
}
117110
} else {
118111
const api = getApi(file)
119-
const report = await getReport({
120-
api,
121-
'generate-report': false,
122-
request: true,
123-
response: true,
124-
ci: false,
125-
verbose: false
126-
})
112+
apisToValidate.add(api)
113+
}
114+
}
127115

116+
// Call getReport once with all APIs
117+
if (apisToValidate.size > 0) {
118+
const allApis = Array.from(apisToValidate).join(',')
119+
const report = await getReport({
120+
api: allApis,
121+
'generate-report': false,
122+
request: true,
123+
response: true,
124+
ci: false,
125+
verbose: false
126+
})
127+
128+
// Extract individual API reports from the combined result
129+
for (const api of apisToValidate) {
128130
const namespace = getNamespace(api)
129-
// Asked to validate a specific API, so we only store that one
130-
reports.set(api, report.get(namespace)[0])
131+
if (report.has(namespace)) {
132+
const namespaceReport = report.get(namespace).find(r => r.api === getName(api))
133+
if (namespaceReport) {
134+
reports.set(api, namespaceReport)
135+
}
136+
}
131137
}
132138
}
133139

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ make validate api=xpack.info type=request branch=main
234234

235235
# this will validate the xpack.info request and response types against the 8.15 branch
236236
make validate api=xpack.info branch=8.15
237+
238+
# this will validate the xpack.info and search request and response types against the 8.15 branch
239+
make validate api=xpack.info,search branch=8.15
237240
```
238241

239242
The last command above will install all the dependencies and run, download

compiler/run-validations.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ async function run () {
7878
process.exit(1)
7979
}
8080

81-
if (!apis.includes(options.api)) {
82-
spinner.fail(`The api '${options.api}' does not exists, did you mean '${closest(options.api, apis)}'?`)
81+
const apiList = options.api.split(',').map(api => api.trim())
82+
const invalidApis = apiList.filter(api => !apis.includes(api))
83+
if (invalidApis.length > 0) {
84+
const suggestions = invalidApis.map(api => `'${api}' (did you mean '${closest(api, apis)}'?)`).join(', ')
85+
spinner.fail(`The following APIs do not exist: ${suggestions}`)
8386
process.exit(1)
8487
}
8588
// if the empty string it's because the make target wasn't configured with a type argument

docs/validation-example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The example assumes that you have already performed the necessary steps to run a
1616
if not, take a look at the [README](../README.md).
1717

1818
```sh
19-
make validate api=index type=request branch=main
19+
make validate api=index branch=main
2020
```
2121

2222
You will see an output like the following:
@@ -82,7 +82,7 @@ open it with your favourite editor and perform the fix
8282
Finally run the validation again:
8383

8484
```sh
85-
make validate api=index type=request branch=main
85+
make validate api=index branch=main
8686
```
8787

8888
If there are no more errors, open a pull request with the fix.

0 commit comments

Comments
 (0)