Skip to content

Commit a090aa0

Browse files
authored
Add local Protobuf conversion instructions to README (opensearch-project#362)
* Add local Protobuf conversion instructions to README Signed-off-by: xil <fridalu66@gmail.com> * update changelog Signed-off-by: xil <fridalu66@gmail.com> * rephrase Signed-off-by: xil <fridalu66@gmail.com> * update Signed-off-by: xil <fridalu66@gmail.com> * Add Prerequisites Signed-off-by: xil <fridalu66@gmail.com> --------- Signed-off-by: xil <fridalu66@gmail.com>
1 parent 305e3f2 commit a090aa0

3 files changed

Lines changed: 72 additions & 77 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
44

55
## [Unreleased]
66
### Added
7+
- Add local Protobuf conversion instructions to README ([#362](https://github.com/opensearch-project/opensearch-protobufs/pull/362))
78

89
### Changed
910

DEVELOPER_GUIDE.md

Lines changed: 71 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,41 @@ Install bazel, using the version in .bazelversion.
44
# Compile protos and grpc
55

66
## All artifacts
7-
```
8-
bazel build //...
9-
```
7+
Generate protobuf libraries for your preferred language:
108

11-
## Java
12-
```
9+
```bash
10+
# Java
1311
bazel build //:java_protos_all
14-
```
1512

16-
## Python
17-
```
13+
# Python
1814
bazel build //:python_protos_all
19-
```
2015

21-
## Go
22-
```
16+
# Go
2317
bazel build //:go_protos_all
18+
19+
# All languages
20+
bazel build //:java_protos_all //:python_protos_all //:go_protos_all
21+
```
22+
23+
### Docker Build Options
24+
25+
Use Docker to build and test protobuf libraries:
26+
27+
```bash
28+
# Java
29+
docker build --target build-bazel-java .
30+
docker build --target package-bazel-java .
31+
docker build --target test-bazel-java .
32+
33+
# Python
34+
docker build --target build-bazel-python .
35+
docker build --target package-bazel-python .
36+
docker build --target test-bazel-python .
37+
38+
# Go
39+
docker build --target build-bazel-go .
40+
docker build --target package-bazel-go .
41+
docker build --target test-bazel-go .
2442
```
2543

2644
# Proto generated code
@@ -83,44 +101,61 @@ bazel build //:opensearch_protos_wheel
83101
pip install bazel-bin/opensearch_protos-*-py3-none-any.whl
84102
```
85103

86-
# Protobuf Convert Process
104+
# Protobuf Local Convert Guide
87105

88-
**ProtoConvertProcess** consists of the following steps:
89-
- **Preprocessing** Preprocess downloaded [OpenSearch API Specification](https://github.com/opensearch-project/opensearch-api-specification) before convert to Protobuf-schema.
90-
- **Conversion** The prepared API specification is transformed into a Protobuf schema using [openapi-generator](https://github.com/OpenAPITools/openapi-generator).
91-
- **Postprocessing** The resulting Protobuf files are refined and adjusted to meet the standards after the conversion.
106+
To generate Protobuf definitions from the latest OpenSearch API specification, follow these steps. All commands are intended to be run from the project root directory.
92107

93-
The [Spec Preprocessing](tools/proto-convert/src/PreProcessing.ts) includes two steps:
108+
## Prerequisites
94109

95-
1. **Filter**
96-
- Filters only the target APIs defined in [spec-filter.yaml](tools/proto-convert/src/config/spec-filter.yaml).
97-
- Extract a single API per group from the OpenSearch spec.
110+
- **Node.js** >= v22
111+
- **Java** >= 17
98112

99-
2. **Sanitizer**
100-
- Normalizes schema and property names to be compatible with Protobuf naming rules.
113+
1. **Download the latest OpenSearch API Specification**
101114

102-
**Setup**
103115

104-
1. Install [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs)
105-
2. Install project dependencies:
116+
```bash
117+
curl -L -o opensearch-openapi.yaml \
118+
https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml
119+
```
106120

121+
2. **Run Preprocessing**
107122

108-
npm run preprocessing -- --help
109-
**Arguments**
123+
```bash
124+
npm ci && npm run preprocessing
125+
```
110126

111-
- `--input <path>`: The path read downloaded opensearch-api-specification yaml file, defaults to `<repository-root>/build/opensearch-openapi.yaml`.
112-
- `--output <path>`: The path to write the final preprocessed spec to, defaults to `<repository-root>/build/processed-opensearch-openapi.yaml`.
127+
3. **Download OpenAPI Generator CLI**
113128

114-
**Example**
129+
```bash
130+
curl -L -f -o openapi-generator-cli.jar \
131+
https://github.com/opensearch-project/opensearch-protobufs/releases/download/openapi-generator-tool/openapi-generator-cli.jar
132+
```
115133

116-
```bash
117-
npm run preprocessing -i <input_path> -o <output_path>
118-
```
134+
4. **Convert to Protobuf**
135+
136+
```bash
137+
java -jar openapi-generator-cli.jar generate -c tools/proto-convert/src/config/protobuf-generator-config.yaml
138+
```
139+
140+
5. **Run Postprocessing**
141+
142+
```bash
143+
npm run postprocessing
144+
```
145+
146+
After these steps, you will find the generated Protobuf service definitions in the `generated/services/default_service.proto`. Note that service files need be manually created. You can use `generated/services/default_service.proto` as a reference for defining gRPC service definitions.
147+
148+
### Additional Notes
149+
150+
- **For Search/Bulk Requests:**
151+
Protobufs for search and bulk operations are already provided in the repository. Some schemas are excluded from generation because they don't have gRPC supported. The exclusion list is defined in [`spec-filter.yaml`](tools/proto-convert/src/config/spec-filter.yaml) under the `excluded_schemas` section.
152+
153+
- **For Other Requests:**
154+
For other APIs, generate Protobuf definitions locally and review them to ensure they meet your requirements. We recommend implementing and testing a gRPC server with the generated Protobufs to verify correctness. Once validated, submit a Pull Request to add the new API path to [`spec-filter.yaml`](tools/proto-convert/src/config/spec-filter.yaml). A maintainer will merge the PR and run the workflow to automatically generate and incorporate the Protobufs.
155+
156+
**Note:** Make sure you are running all commands from the project root folder.
119157

120-
**openapi-generator**
121158

122-
OpenAPI Generator offers a range of configuration options. The configuration is specified in the [protobuf-generator-config.yaml](tools/proto-convert/src/config/protobuf-generator-config.yaml).
123-
OpenAPI Generator supports the customization of mustache templates to generate the desired output, with the templates located in [protobuf-schema-template](tools/proto-convert/src/config/protobuf-schema-template)
124159
# Ignored files
125160

126161
All generated files are excluded from version control via the `.gitignore` file. This includes:

README.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,6 @@ The [opensearch-api-specification repo](https://github.com/opensearch-project/op
66

77
This repository will also include a variety of tooling and CI, linters and validators, and generated code, which is described in more detail below.
88

9-
## Quick Start
10-
11-
### Build Protobuf Libraries
12-
13-
Generate protobuf libraries for your preferred language:
14-
15-
```bash
16-
# Java
17-
bazel build //:java_protos_all
18-
19-
# Python
20-
bazel build //:python_protos_all
21-
22-
# Go
23-
bazel build //:go_protos_all
24-
25-
# All languages
26-
bazel build //:java_protos_all //:python_protos_all //:go_protos_all
27-
```
28-
29-
### Docker Build Options
30-
31-
Use Docker to build and test protobuf libraries:
32-
33-
```bash
34-
# Java
35-
docker build --target build-bazel-java .
36-
docker build --target package-bazel-java .
37-
docker build --target test-bazel-java .
38-
39-
# Python
40-
docker build --target build-bazel-python .
41-
docker build --target package-bazel-python .
42-
docker build --target test-bazel-python .
43-
44-
# Go
45-
docker build --target build-bazel-go .
46-
docker build --target package-bazel-go .
47-
docker build --target test-bazel-go .
48-
```
49-
509
## Releases
5110

5211
Each OpenSearch Protobufs release includes:

0 commit comments

Comments
 (0)