Sha256: a602f78feb4d803602f90c741046ab90dee883ad13041768962d9ae6ca1642dd

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

# Utils

## The Generator

This directory hosts The Generator, a tool that generates the classes for each API endpoint from the [Elasticsearch REST API JSON Specification](https://github.com/elastic/elasticsearch/tree/master/rest-api-spec).

### Generate

To generate the code, you need to have the Elasticsearch REST API spec files in `tmp/rest-api-spec` in the root of the project. You can run a rake task from the root of the project to download the specs corresponding to the current running cluster:
```bash
$ rake elasticsearch:download_artifacts
```

Once the JSON files have been downloaded, you need to run (from this folder):
```bash
$ thor api:code:generate
```

- The oss Ruby code will be generated in `elasticsearch-api/lib/elasticsearch/api/actions`.  
- The xpack Ruby code will be generated in `elasticsearch-xpack/lib/elasticsearch/xpack/api/actions`.
- The generator runs Rubocop to autolint and clean up the generated files.

Alternatively, you can pass in `oss` or `xpack` as parameters to generate only one of the 2 sets of endpoints:

```bash
$ thor api:code:generate --api=xpack
$ thor api:code:generate --api=oss
```

### Development

The main entry point is `generate_source.rb`, which contains a class that implements a Thor task: `generate`:

```
$ thor api:code:generate
```

It uses [Thor::Actions](https://github.com/erikhuda/thor/wiki/Actions)' `template` method and `templates/method.erb` to generate the final code. The `generator` directory contains some helpers used to generate the code. The ERB template is split into partials and you can find all ERB files in the `templates` directory.

There's also a lister task:

```
$ thor api:list
```

It's implemented in `lister.rb` and it lists all the REST API endpoints from the JSON specification.

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
elasticsearch-api-7.17.11 utils/README.md
elasticsearch-api-7.17.10 utils/README.md
elasticsearch-api-7.17.9 utils/README.md
elasticsearch-api-7.17.8 utils/README.md
elasticsearch-api-7.17.7 utils/README.md
elasticsearch-api-7.17.1 utils/README.md
elasticsearch-api-7.17.0 utils/README.md
elasticsearch-api-7.16.3 utils/README.md
elasticsearch-api-7.16.1 utils/README.md
elasticsearch-api-7.16.0 utils/README.md
elasticsearch-api-7.15.0 utils/README.md
elasticsearch-api-7.14.1 utils/README.md
elasticsearch-api-7.14.1.pre utils/README.md
elasticsearch-api-7.14.0 utils/README.md