You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CLIENT_GENERATOR_GUIDE.md
+7-8
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,13 @@ In a client, the `search` operations are grouped in to a single API method, `cli
19
19
20
20
In the [published OpenAPI spec](https://github.com/opensearch-project/opensearch-api-specification/releases), this grouping is denoted by `x-operation-group` vendor extension in every operation definition. The value of this extension is the name of the API action (like `search` or `indices.get_field_mapping`). Operations with the same `x-operation-group` value are guaranteed to have the same query string parameters, response body, and request body (for PUT/POST/DELETE operations). Common path parameters are also guaranteed to be the same. The only differences between operations are the HTTP method and the path. With that in mind, below are rules on how to combine operations of different HTTP methods and path compositions.
21
21
22
-
- If an operation is marked with `x-ignorable: "true"`, then ignore the operation. Such an operation has been deprecated and has been replaced by a newer one. As far as the clients are concerned, ignorable operations do not exist.
22
+
- If an operation is marked with `x-ignorable: true`, then ignore the operation. Such an operation has been deprecated and has been superseded by a newer one. As far as the clients are concerned, ignorable operations do not exist.
23
23
- If two operations have identical HTTP methods, but different paths: use the path that best matches the path parameters provided.
24
24
- If two operations have identical path, but different HTTP methods:
25
25
- GET/POST: if the request body is provided then use POST, otherwise use GET
26
26
- PUT/POST: Either works, but PUT is preferred when an optional path parameter is provided.
27
27
28
-
The psuedo-code that combines the `search` operations into a single API method is as follows:
28
+
The pseudocode that combines the `search` operations into a single API method is as follows:
You will also encounter `x-overloaded-param: "metric"` for the `node_id` path parameter of `GET /_nodes/{node_id}` operation in `nodes.info` action. This is a special case where the path parameter is overloaded to accept either a node ID or a metric name. The `client.nodes.info` method when called with either `metric` or `node_id` (but not both), will use `GET /_nodes/{node_id}` operation (even though the path parameter name is `node_id`). When called with both `metric` and `node_id`, it will use `GET /_nodes/{node_id}/{metric}` operation.
45
+
You will also encounter `x-overloaded-param: metric` for the `node_id` path parameter of the `GET /_nodes/{node_id}` operation in `nodes.info` action. This is a special case where the path parameter is overloaded to accept either a node ID or a metric name. When the user evokes the `client.nodes.info` method with either `metric` or `node_id` (but not both), the method will use the `GET /_nodes/{node_id}` operation. When evoked with both `metric` and `node_id`, it will use the`GET /_nodes/{node_id}/{metric}` operation.
47
46
48
47
## Handling Bulk Operations
49
-
Some operations accept a bulk of data in the request body. For example, the `bulk` action accepts a bulk of index, update, and delete operations on multiple documents. Unlike other operations where the request body is a JSON object, the request body for bulk operations is a newline-seperated JSON string. The client will automatically convert the request body into a newline-seperated JSON objects. The request body of such operations will be denoted with `x-serialize: "bulk"` vendor extension.
48
+
Some operations accept a bulk of data in the request body. For example, the `bulk` action accepts a bulk of index, update, and delete operations on multiple documents. Unlike other operations where the request body is a **JSON object**, the request body for bulk operations is an **NDJSON** (i.e a [Newline-delimited JSON](https://github.com/ndjson/ndjson-spec)). When encountering this type of operation, the client must serialize the request body accordingly, and set the `Content-Type` header to `application/x-ndjson`.
50
49
51
50
## Parameter Validation
52
51
As of right now, most clients only validate whether required parameters are present. The clients do not validate the values of parameters against the enum values or regex patterns. This is to reduce performance overhead for the clients as the validation is already done on the server. However, the list of enum values and regex patterns are often written into the parameter description.
53
52
54
-
Some clients also check for the validity of query string parameter names to guard the users from typos. If you decide to implement this feature, make sure that it's performant. Scripting languages like Python and Ruby require the code to be loaded into memory at runtime, and constructs used for this feature can be expensive to load, as far as micro-services are concerned.
53
+
Some clients also check for the validity of query string parameter names to guard the users from typos. If you decide to implement this feature, make sure that it's performant. Scripting languages like Python and Ruby require the code to be loaded into memory at runtime, and constructs used for this feature can be expensive to load, as far as microservices are concerned.
55
54
56
55
## Global Parameters
57
-
All operations in the spec contain a set of parameters that are common across all operations. These parameters are denoted with `x-global: true` vendor extension. The generated clients should find a way to DRY these parameters.
56
+
All operations in the spec contain a set of parameters that are common across all operations. These parameters are denoted with `x-global: true` vendor extension. The generated clients should find a way to DRY these parameters in type definitions and method documentation.
58
57
59
58
## Default Parameter Values
60
-
Parameters can have default values either through schema or the `x-default` vendor extension. When both are present, `x-default` will takes precedence.
59
+
Parameters can have default values either through schema or the `x-default` vendor extension. When both are present, `x-default` will take precedence.
Copy file name to clipboardexpand all lines: DEVELOPER_GUIDE.md
+41-27
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,10 @@
3
3
-[File Structure](#file-structure)
4
4
-[Grouping Operations](#grouping-operations)
5
5
-[Grouping Schemas](#grouping-schemas)
6
+
-[Superseded Operations](#superseded-operations)
7
+
-[Global Parameters](#global-parameters)
6
8
-[OpenAPI Extensions](#openapi-extensions)
7
-
-[Linting](#linting)
9
+
-[Tools](#tools)
8
10
9
11
# Developer Guide
10
12
@@ -20,10 +22,6 @@ The Specification is written in OpenAPI 3, so understanding the OpenAPI 3 specif
20
22
21
23
To make editing the specification easier, we split the OpenAPI spec into multiple files that can be found in the [spec](spec) directory. The file structure is as follows:
22
24
23
-
- The API Operations are grouped by namespaces in [spec/namespaces](spec/namespaces/) directory. Each `.yaml` file in this directory represents a namespace and holds all paths and operations of the namespace.
24
-
- The data schemas are grouped by categories in [spec/schemas](spec/schemas/) directory. Each `.yaml` file in this directory represents a category.
25
-
- The [spec/opensearch-openapi.yaml](spec/opensearch-openapi.yaml) file is the OpenAPI root file that ties everything together.
26
-
27
25
```
28
26
spec
29
27
│
@@ -46,7 +44,11 @@ spec
46
44
└── opensearch-openapi.yaml
47
45
```
48
46
49
-
Every `.yaml` file is a valid OpenAPI 3 document. This means that you can use any OpenAPI 3 compatible tool to view and edit the files, and IDEs with OpenAPI support will provide you with autocompletion and validation in real-time.
47
+
- The API Operations are grouped by namespaces in [spec/namespaces/](spec/namespaces) directory. Each file in this directory represents a namespace and holds all paths and operations of the namespace.
48
+
- The data schemas are grouped by categories in [spec/schemas/](spec/schemas) directory. Each file in this directory represents a category.
49
+
- The [spec/opensearch-openapi.yaml](spec/opensearch-openapi.yaml) file is the OpenAPI root file that ties everything together.
50
+
51
+
Every `.yaml` file is a OpenAPI 3 document. This means that you can use any OpenAPI 3 compatible tool to view and edit the files, and IDEs with OpenAPI support will also offer autocomplete and validation in realtime.
50
52
51
53
## Grouping Operations
52
54
@@ -65,16 +67,44 @@ For this reason, every operation *must* be accompanied by the `x-operation-group
65
67
66
68
## Grouping Schemas
67
69
68
-
Schemas are grouped by categories to keep their names short and aid in client generation:
70
+
Schemas are grouped by categories to keep their names short, and aid in client generation (where the schemas are translated into data types/classes, and divided into packages/modules). The schema file names can be in one of the following formats:
69
71
70
72
-`_common` category holds the common schemas that are used across multiple namespaces and features.
71
73
-`_common.<sub_category>` category holds the common schemas of a specific sub_category. (e.g. `_common.mapping`)
72
74
-`<namespace>._common` category holds the common schemas of a specific namespace. (e.g. `cat._common`, `_core._common`)
73
75
-`<namespace>.<action>` category holds the schemas of a specific sub_category of a namespace. (e.g. `cat.aliases`, `_core.search`)
74
76
77
+
## Superseded Operations
78
+
79
+
When an operation is superseded by another operation with **identical functionality**, that is a rename or a change in the URL, it should be listed in [_superseded_operations.yaml](./spec/_superseded_operations.yaml) file. The merger tool will automatically generate the superseded operation in the OpenAPI spec. The superseded operation will have `deprecated: true` and `x-ignorable: true` properties to indicate that it should be ignored by the client generator.
80
+
81
+
For example, if the `_superseded_operations.yaml` file contains the following entry:
if and only if the superseding operations exist in the spec. A warning will be printed on the console if they do not.
99
+
100
+
Note that the path parameter names do not need to match. So, if the actual superseding operations have path of `/_plugins/_anomaly_detection/{node_id}/stats/{stat_id}`, the merger tool will recognize that it is the same as `/_plugins/_anomaly_detection/{nodeId}/stats/{stat}` and generate the superseded operations accordingly with the correct path parameter names.
101
+
102
+
## Global Parameters
103
+
Certain query parameters are global, and they are accepted by every operation. These parameters are listed in the [root file](spec/opensearch-openapi.yaml) under the `parameters` section with `x-global` set to true. The merger tool will automatically add these parameters to all operations.
104
+
75
105
## OpenAPI Extensions
76
106
77
-
This repository includes several penAPI Specification Extensions to fill in any metadata not directly supported OpenAPI:
107
+
This repository includes several OpenAPI Specification Extensions to fill in any metadata not natively supported by OpenAPI:
78
108
79
109
- `x-operation-group`: Used to group operations into API actions.
80
110
- `x-version-added`: OpenSearch version when the operation/parameter was added.
@@ -87,28 +117,12 @@ This repository includes several penAPI Specification Extensions to fill in any
87
117
88
118
## Tools
89
119
90
-
We authored a number of tools to merge and lint specs that live in [tools](tools/). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).
120
+
We authored a number of tools to merge and lint specs that live in [tools](tools). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).
91
121
92
122
### Merger
93
123
94
-
The spec merger "builds", aka combines various `.yaml` files into a complete OpenAPI spec. A [workflow](./.github/workflows/build.yml) publishes the output into [releases](https://github.com/opensearch-project/opensearch-api-specification/releases).
95
-
96
-
#### Auto-generating Superseded Operations
97
-
98
-
When an operation is superseded by another operation with **IDENTICAL FUNCTIONALITY**, that is a rename or a change in the URL, it should be listed in [_superseded_operations.yaml](./spec/_superseded_operations.yaml) file. The merger tool will automatically generate the superseded operation in the OpenAPI spec. The superseded operation will have `deprecated` and `x-ignorable` properties set to `true` to indicate that it should be ignored by the client generator.
99
-
For example, if the `_superseded_operations.yaml` file contains the following entry:
Then, the merger tool will generate 2 operations: `GET /_opendistro/_anomaly_detection/{nodeId}/stats/{stat}` and `POST /_opendistro/_anomaly_detection/{nodeId}/stats/{stat}` from `GET /_plugins/_anomaly_detection/{nodeId}/stats/{stat}` and `POST /_plugins/_anomaly_detection/{nodeId}/stats/{stat}` respectively, if they exist (A warning will be printed on the console if they do not). Note that the path parameter names do not need to match. So, if the actual superseding operations have path of `/_plugins/_anomaly_detection/{node_id}/stats/{stat_id}`, the merger tool will recognize that it is the same as `/_plugins/_anomaly_detection/{nodeId}/stats/{stat}` and generate the superseded operations accordingly with the correct path parameter names.
108
-
109
-
#### Auto-generating global parameters
110
-
Certain query parameters are global, and they are accepted by every operation. These parameters are listed in the [root file](spec/opensearch-openapi.yaml) under the `parameters` section with `x-global` set to true. The merger tool will automatically add these parameters to all operations.
124
+
The spec merger "builds", aka combines all `.yaml` files in a spec folder into a complete OpenAPI spec. A [workflow](./.github/workflows/build.yml) performs this task on the [spec folder](spec) of this repo then publishes the output into [releases](https://github.com/opensearch-project/opensearch-api-specification/releases).
111
125
112
126
### Linter
113
127
114
-
The spec linter that validates every `.yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter README](tools/README.md#linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.
128
+
The spec linter that validates every `.yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter README](tools/README.md#spec-linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.
@@ -38,10 +39,17 @@ This project has adopted the [Amazon Open Source Code of Conduct](CODE_OF_CONDUC
38
39
39
40
See [DEVELOPER_GUIDE](DEVELOPER_GUIDE.md).
40
41
41
-
## OpenSearch API Specs
42
+
## Client Generator Guide
43
+
44
+
See [CLIENT_GENERATOR_GUIDE](CLIENT_GENERATOR_GUIDE.md).
45
+
46
+
## Published Spec
42
47
43
48
OpenSearch API Specs are hosted at https://opensearch-project.github.io/opensearch-api-specification/. See [PUBLISHING_SPECS](PUBLISHING_SPECS.md) for more information.
44
49
50
+
Click [here](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main/opensearch-openapi.yaml) to download the latest OpenSearch OpenAPI yaml file.
51
+
52
+
45
53
## Security
46
54
47
55
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to [email protected]. Please do **not** create a public GitHub issue.
As a shortcut, if those parameters are not provided, the tool will use the default values:
30
+
-`../spec/opensearch-openapi.yaml` as the root path (i.e. the root file of the repo's [spec folder](../spec))
31
+
-`../opensearch-openapi.yaml` as the output path
32
+
33
+
```bash
34
+
npm run merge
35
+
```
36
+
37
+
## Spec Linter
27
38
28
39
The linter tool validates the OpenSearch spec files in the `spec` folder:
29
40
30
41
```bash
31
42
npm run lint:spec
32
43
```
33
44
34
-
It will print out all the errors and warnings in the spec files. This tool in still in development, and it will be integrated into the CI/CD pipeline and run automatically with every PR.
45
+
It will print out all the errors and warnings in the spec files.
0 commit comments