Skip to content

Commit cd96458

Browse files
authored
Switch to native OpenAPI (#208)
* ## Switching over to native OpenAPI: - Removed Smithy: - Removed Smithy models (`model` folder) - Removed Gradle - Removed legacy test framework - Removed build-openapi-specs workflow - Added Editable OpenAPI spec: - Added multi-file OpenApi spec (`spec` folder) - Added a tool to merge multi-file spec into single-file spec - Added build-single-file-specs workflow - Updated Documents ## Adding Request and Response Bodies The OpenAPI spec has also been updated with the request and response bodies that we extracted from ElasticSearch OpenAPI spec. This is done within the same PR as the native OpenAPI switch because we also used the ElasticSearch OpenAPI spec to map the query/path schemas to the schemas of many components in the bodies. Signed-off-by: Theo Truong <[email protected]> * # Removed coverage.yml Signed-off-by: Theo Truong <[email protected]> * # Removed references to Xpack Signed-off-by: Theo Truong <[email protected]> * # Removed hard-coded params for merger Signed-off-by: Theo Truong <[email protected]> --------- Signed-off-by: Theo Truong <[email protected]>
1 parent c256d99 commit cd96458

File tree

644 files changed

+85398
-60876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

644 files changed

+85398
-60876
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build OpenAPI specs
1+
name: Build latest single-file specs
22
on: [push, pull_request]
33

44
jobs:
@@ -8,17 +8,24 @@ jobs:
88
- name: Checkout the repo
99
uses: actions/checkout@v3
1010

11+
- name: Setup Node.js
12+
uses: actions/setup-node@v2
13+
with:
14+
node-version: '20'
15+
1116
- name: Build
12-
run: ./gradlew build
13-
14-
- name: Move OpenAPI specs to root
15-
run: mv build/smithyprojections/opensearch-api-specification/full/openapi/OpenSearch.openapi.json .
17+
working-directory: ./tools
18+
run: |-
19+
npm install
20+
export ROOT_PATH=../spec/OpenSearch.openapi.yaml
21+
export OUTPUT_PATH=../builds/OpenSearch.latest.yaml
22+
npm run merge -- $ROOT_PATH $OUTPUT_PATH
1623
1724
- name: Upload OpenAPI model artifact
1825
uses: actions/upload-artifact@v3
1926
with:
2027
name: opensearch-openapi
21-
path: ./OpenSearch.openapi.json
28+
path: ./builds/OpenSearch.latest.yaml
2229

2330
- name: GitHub App token
2431
id: github_app_token
@@ -34,9 +41,9 @@ jobs:
3441
if: github.repository == 'opensearch-project/opensearch-api-specification' && github.event_name == 'push' && github.event.ref == 'refs/heads/main'
3542
with:
3643
token: ${{ steps.github_app_token.outputs.token }}
37-
commit-message: Update OpenAPI specs
44+
commit-message: Build latest single-file specs
3845
signoff: true
39-
title: Update OpenAPI specs
46+
title: Build latest single-file specs
4047
body: |
41-
I've noticed an update to the models. This pull request updates the OpenAPI specs accordingly.
42-
branch: create-pull-request/specs-update
48+
I've noticed an update in the `./spec` folder. This pull request updates `./build/OpenSearch.latest.yaml` accordingly.
49+
branch: create-pull-request/single-file-specs

.github/workflows/ci.yaml

-46
This file was deleted.

.github/workflows/coverage.yml

-55
This file was deleted.

.github/workflows/domain-check.sh

-18
This file was deleted.

.gitignore

+7-44
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,11 @@
1-
# smithy files
2-
bin/
1+
# Mac OS
2+
.DS_Store
3+
4+
# Node.js
5+
node_modules
36

47
# intellij files
58
.idea/
6-
*.iml
7-
*.ipr
8-
*.iws
9-
build-idea/
10-
out/
11-
12-
# include shared intellij config
13-
!.idea/inspectionProfiles/Project_Default.xml
14-
!.idea/runConfigurations/Debug_OpenSearch.xml
15-
!.idea/vcs.xml
16-
17-
# These files are generated in the main tree by IntelliJ
18-
benchmarks/src/main/generated/*
19-
20-
# eclipse files
21-
.project
22-
.classpath
23-
.settings
24-
build-eclipse/
25-
26-
# netbeans files
27-
nb-configuration.xml
28-
nbactions.xml
29-
30-
# gradle stuff
31-
.gradle/
32-
build/
33-
34-
# vscode stuff
35-
.vscode/
36-
37-
# testing stuff
38-
**/.local*
39-
.vagrant/
40-
/logs/
41-
42-
# osx stuff
43-
.DS_Store
44-
45-
.smithy.lsp.log
469

47-
# Javascript stuff
48-
node_modules
10+
# VSCode files
11+
.vscode/

CLIENT_GENERATOR_GUIDE.md

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generate Clients for OpenSearch using OpenAPI Specification
22

3-
OpenSearch Clients are available in multiple programming languages. The biggest challenge with this is keeping the clients up to date with the latest changes in OpenSearch. To solve this problem, we're automating the process of generating clients for OpenSearch using the OpenAPI specification. While OpenAPI comes with many well established off-the-shelf client generators for most languages, the OpenSearch APIs come with a lot of quirkiness that makes it near impossible to use these off-the-shelf generators. For this reason, we've opted to write our own client generators that is specifically tailored to the OpenSearch APIs. This document will walk you through the process of generating clients from [OpenSearch OpenAPI spec](./OpenSearch.openapi.json), more specifically client API methods.
3+
OpenSearch Clients are available in multiple programming languages. The biggest challenge with this is keeping the clients up to date with the latest changes in OpenSearch. To solve this problem, we're automating the process of generating clients for OpenSearch using the OpenAPI specification. While OpenAPI comes with many well established off-the-shelf client generators for most languages, the OpenSearch APIs come with a lot of quirkiness that makes it near impossible to use these off-the-shelf generators. For this reason, we've opted to write our own client generators that is specifically tailored to the OpenSearch APIs. This document will walk you through the process of generating clients from [OpenSearch OpenAPI spec](builds/OpenSearch.latest.yaml), more specifically client API methods.
44

55
## The Grouping of API Operations
66
The OpenSearch clients, though written in different languages for different frameworks, share one distinct characteristic: API Operations are grouped into actions and namespaces. Operations serving the same functionality are often grouped together into a single API Action, which is represented in the client as an API method.
@@ -17,7 +17,7 @@ The **indices.get_field_mapping**, is consisted of 2 operations:
1717

1818
In a client, the `search` operations are grouped in to a single API method, `client.search(...)`, and the `indices.get_field_mapping` operations are grouped into a single API method, `get_field_mapping` of the `indices` namespace, `client.indices.get_field_mapping(...)`
1919

20-
In the [OpenAPI spec](./OpenSearch.openapi.json), 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.
20+
In the [OpenAPI spec](./builds/OpenSearch.latest.yaml), 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.
2121

2222
- 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.
2323
- If two operations have identical HTTP methods, but different paths: use the path that best matches the path parameters provided.
@@ -41,17 +41,8 @@ def search(self, index=None, body=None):
4141
return self.perform_request(method, path, body=body)
4242
```
4343

44-
## Handling Path Parameters
4544

46-
### List Type
47-
Path parameters in OpenSearch sometimes allow comma-seperated values. For example, the `index` parameter in `GET /{index}/_search` can either have the value of a single index, or a comma-seperated list of indices like `books,movies`. However, Smithy, the tool we use to draft OpenAPI spec, does not support list as a data-type for path parameters. To work around this, we use the `x-data-type: "list"` vendor extension to denote that a path parameter can be a comma-seperated list of values. The client, when receiving an array of values for a path parameter of type list, will join the values with a comma.
48-
49-
### Enum Options
50-
Path parameters are sometimes restricted to certain enum values. However, since Smithy does not allow enum type or enum-list type for path parameters, we use the `x-enum-options` vendor extension to denote the enum values that are allowed for a path parameter. As of right now, the clients do not validate the values of path parameters against the enum values, however, the list of these values are often written into the parameter description.
51-
52-
Path parameters can also come with `x-string-pattern` vendor extension to denote a regex pattern that the parameter value must match. The clients do NOT validate the values of path parameters against the regex pattern, however. So, it's safe to ignore this extension.
53-
54-
### Overloaded Name
45+
## Overloaded Name
5546
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.
5647

5748
## Handling Bulk Operations

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ As with other types of contributions, the first step is to [open an issue on Git
4242

4343
OpenSearch is an open source product released under the Apache 2.0 license (see either [the Apache site](https://www.apache.org/licenses/LICENSE-2.0) or the [LICENSE.txt file](LICENSE.txt)). The Apache 2.0 license allows you to freely use, modify, distribute, and sell your own products that include Apache 2.0 licensed software.
4444

45-
We respect intellectual property rights of others and we want to make sure all incoming contributions are correctly attributed and licensed. A Developer Certificate of Origin (DCO) is a lightweight mechanism to do that.
45+
We respect intellectual property rights of others, and we want to make sure all incoming contributions are correctly attributed and licensed. A Developer Certificate of Origin (DCO) is a lightweight mechanism to do that.
4646

4747
The DCO is a declaration attached to every contribution made by every developer. In the commit message of the contribution, the developer simply adds a `Signed-off-by` statement and thereby agrees to the DCO, which you can find below or at [DeveloperCertificate.org](http://developercertificate.org/).
4848

0 commit comments

Comments
 (0)