Skip to content

Commit e722235

Browse files
authored
Improve type validation DX (#1174)
1 parent c4ce528 commit e722235

30 files changed

+1065
-153
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ specification/lib
4949

5050
artifacts
5151
.github/download-artifacts/package-lock.json
52+
53+
.validation.json
54+
compiler/lib
55+
typescript-generator/lib

Makefile

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
SHELL := /bin/bash
22

3-
validation-all: ## Run Validation on all Endpoints
4-
@echo ">> running validations for all endpoints .."
5-
./run-validations.sh
3+
validate: ## Validate a given endpoint request or response
4+
@node compiler/run-validations.js --api $(api) --type $(type) --stack-version $(stack-version)
65

7-
validation-all-fresh: ## Run Validation on all Endpoints with a fresh setup
8-
@echo ">> running validations for all endpoints .."
9-
PULL_LATEST=true ./run-validations.sh
10-
11-
validation-api: ## Validate Endpoint with param: api=<api-name>
12-
test -n "$(api)" # missing api param
13-
./run-validations.sh --api $(api)
14-
15-
validation-api-request: ## Validate request of Endpoint with param: api=<api-name>
16-
test -n "$(api)" # missing api param
17-
./run-validations.sh --api $(api) --request --verbose
18-
19-
validation-api-response: ## Validate response of Endpoint with param: api=<api-name>
20-
test -n "$(api)" # missing api param
21-
./run-validations.sh --api $(api) --response --verbose
6+
validate-no-cache: ## Validate a given endpoint request or response without local cache
7+
@node compiler/run-validations.js --api $(api) --type $(type) --stack-version $(stack-version) --no-cache
228

239
license-check: ## Add the license headers to the files
2410
@echo ">> checking license headers .."
@@ -48,7 +34,7 @@ spec-imports-fix: ## Fix the TypeScript imports
4834
spec-dangling-types: ## Generate the dangling types rreport
4935
@npm run generate-dangling --prefix compiler
5036

51-
setup-env: ## Install dependencies for contrib target
37+
setup: ## Install dependencies for contrib target
5238
@make clean-dep
5339
@npm install --prefix compiler
5440
@npm install --prefix typescript-generator

README.md

+9-38
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nvm install 14
3232
$ git clone https://github.com/elastic/elasticsearch-specification.git
3333
3434
# install the dependencies
35-
$ make setup-env
35+
$ make setup
3636
3737
# generate the JSON representation
3838
$ make spec-generate
@@ -46,11 +46,8 @@ $ cat output/schema/schema.json
4646
```
4747
Usage:
4848
make <target>
49-
validation-all Run Validation on all Endpoints
50-
validation-all-fresh Run Validation on all Endpoints with a fresh setup
51-
validation-api Validate Endpoint with param: api=<api-name>
52-
validation-api-request Validate request of Endpoint with param: api=<api-name>
53-
validation-api-response Validate response of Endpoint with param: api=<api-name>
49+
validate Validate a given endpoint request or response
50+
validate-no-cache Validate a given endpoint request or response without local cache
5451
license-check Add the license headers to the files
5552
license-add Add the license headers to the files
5653
spec-format-check Check specification formatting rules
@@ -60,6 +57,7 @@ Usage:
6057
spec-imports-fix Fix the TypeScript imports
6158
spec-dangling-types Generate the dangling types rreport
6259
setup-env Install dependencies for contrib target
60+
clean-dep Clean npm dependencies
6361
contrib Pre contribution target
6462
help Display help
6563
```
@@ -189,40 +187,18 @@ git clone https://github.com/elastic/elasticsearch-specification.git
189187
git clone https://github.com/elastic/clients-flight-recorder.git
190188

191189
cd elasticsearch-specification
192-
STACK_VERSION=... ./run-validations.sh
190+
# this will validate the xpack.info request type agains the 8.1.0 stack version
191+
make validate api=xpack.info type=request stack-version=8.1.0-SNAPSHOT
193192
```
194193

195194
The last command above will install all the dependencies and run, download
196195
the test recordings and finally validate the specification.
197-
If you need to download the recordings again, run `STACK_VERSION=... PULL_LATEST=true ./run-validations.sh`.
198-
199-
You can validate a specific API with the `--api` option, same goes for `--request` and `--response`.
200-
For example, the following command validates the index request api:
201-
202-
```js
203-
STACK_VERSION=... ./run-validations.sh --api index --request
204-
```
205-
The following command validates the index response api:
206-
207-
```js
208-
STACK_VERSION=... ./run-validations.sh --api index --response
209-
```
210-
The following command validates the index request and response api:
211-
212-
```js
213-
STACK_VERSION=... ./run-validations.sh --api index --request --response
214-
```
196+
If you need to download the recordings again, run `make validate-no-cache api=xpack.info type=request stack-version=8.1.0-SNAPSHOT`.
215197

216198
Once you see the errors, you can fix the original definition in `/specification`
217199
and then run the command again until the types validator does not trigger any new error.
218200
Finally open a pull request with your changes.
219201

220-
Namespaced APIs can be validated in the same way, for example:
221-
222-
```js
223-
STACK_VERSION=... ./run-validations.sh --api cat.health --request
224-
```
225-
226202
## Documentation
227203

228204
- [How to add a new API](./docs/add-new-api.md)
@@ -269,12 +245,7 @@ You should copy from there the updated endpoint defintion and change it here.
269245

270246
### The validation in broken on GitHub but works on my machine!
271247

272-
Very likely the recordings on your machine are stale, you can download
273-
the latest version with:
274-
275-
```sh
276-
STACK_VERSION=... PULL_LATEST=true ./run-validations.sh
277-
```
248+
Very likely the recordings on your machine are stale, rerun the validation with the `validate-no-cache` make target.
278249

279250
You should pull the latest change from the `client-flight-recorder` as well.
280251

@@ -309,7 +280,7 @@ If you are using MacOS, run the following command to fix the issue:
309280
brew install coreutils
310281
```
311282

312-
### The `recordings-dev` folder contains a zip file and not the `tmp-*` folders
283+
### The `recordings` folder contains a zip file and not the `tmp-*` folders
313284

314285
Very likely your system does not have the `zip` command installed.
315286
```sh

0 commit comments

Comments
 (0)