[OpenAPI Generator](https://openapi-generator.tech) is used to generate protobuf schema (`.proto3`) files from OpenAPI specifications of MEC012 RNI API.
>**NOTE:** At the time of writing, the tool does not support OAS 3.1 version and we have to first convert the [RNI API](./RniAPI.yaml) to OAS 3.0 for generating protobuf schema.
1. Convert OAS for [RNI API](./RniAPI.yaml) from 3.1 to 3.0
- Change the value of `openapi` field from 3.1.0 to 3.0.0
- Use this [VS code extension](https://marketplace.visualstudio.com/items?itemName=42Crunch.vscode-openapi) to see the errors in the downgraded YAML (v3.0)
- Manually fix the errors
- mostly related to `examples`<-->`example` interchange
- or some 3.1 fields that are not supported in 3.0 (comment them out)
2. Generate proto files
- Install the `openapi-generator-cli.jar` using the installation procedure mentioned [here](https://openapi-generator.tech/docs/installation#jar).
- Generate the proto files using the following command
3. Carefully inspect the generated `.proto` files for any inconsistencies. Some of the things to look out for:
- Proto3 generated files for enumerations, structures containing allOf, oneOf, anyOf etc. may need to be touched manually
- Check that all the nested models are being _imported_ correctly in their parent models
- Remove redundant proto files
4. Validate protobuf schema by generating code from proto3 descriptions in different languages. See [this section](#code-generation-from-proto3) for more details.
# Code Generation from proto3
Below are some code generation examples for Python, Go and Ruby. For other languages, please refer to https://grpc.io/docs/quickstart/.
### Python
1. Install the grpcio-tools package
```sh
$ pip install grpcio-tools
```
2. Create a directory for generated Python stubs
```sh
$ mkdir python-stubs
```
3. Run the following commands from the root of the directory containing this README that you are reading.
> The generated `<data_model>.pb.go` files will contain all the protocol buffer code to populate, serialize, and retrieve request and response message types defined in the `models` folder.
> And the `rni_service_grpc.pb.go` will contain the stubs for the methods defined in the `rni_service.proto` file.
### Ruby
1. Install gRPC Ruby Plugin and required tools
```sh
$ gem install grpc
$ sudo apt install ruby-grpc-tools
```
2. Generate code
```sh
$ mkdir ruby-stubs
```
Run the following command to create Ruby modules for all the data models defined in the proto files.
Run the following command to generate `rni_service_pb.rb` and `rni_service_services_pb.rb` files, containing stub and service classes for the endpoints and methods defined in MEC012 RNI service.