Commit 7218d342 authored by Muhammad Hamza's avatar Muhammad Hamza
Browse files

update proto3 generation README for AppPkgMgmt API

parent 1768c2fb
Loading
Loading
Loading
Loading
+98 −15
Original line number Diff line number Diff line
# gPRC for mec0102
# gPRC for mec010-2

ETSI GS MEC 010-2 - Part 2: Application lifecycle, rules and requirements management described using OpenAPI.
The ETSI MEC ISG Application Package Management API described using OpenAPI.

## Overview
These files were generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
@@ -14,19 +14,102 @@ For more information, please visit [https://forge.etsi.org/rep/mec/gs010-2-app-p

Below are some usage examples for 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 command from the root of the directory containing this README that you are reading.

   - Models:
  
        ```sh
        $ python -m grpc_tools.protoc -I./AppPkgMgmtProto3/proto3 --python_out=./python-stubs ./AppPkgMgmtProto3/proto3/models/*
        ```
    
        The above command will generate .py files for all the data models in the ./models directory

   - Services:

        ```sh
        $ python -m grpc_tools.protoc -I./AppPkgMgmtProto3/proto3 --python_out=./python-stubs --grpc_python_out=./python-stubs ./AppPkgMgmtProto3/proto3/services/*
        ```

        The above command will generate service files for the Application Package Management API, containing:
        - Python data models used in the Application Package Management API
        - Classes and functions needed for the supported HTTP methods in the Application Package Management API

### Go

1. Install protocol buffer compiler
    ```sh
    $ apt install -y protobuf-compiler
    ```
# assuming `protoc-gen-go` has been installed with `go get -u github.com/golang/protobuf/protoc-gen-go`
mkdir /var/tmp/go/
protoc --go_out=/var/tmp/go/ services/*
protoc --go_out=/var/tmp/go/ models/*
2. Install Go plugins for `protoc`
    ```sh
    $ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1
    ```
    ```sh
    $ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
    ```
3. Update `PATH` so `protoc` can find the plugins
    ```sh
    $ export PATH="$PATH:$(go env GOPATH)/bin"
    ```
4. Define a go package by appending `option go_package = "./mec0102.services.apppkgmgmtservice";` in .proto files like this:

    ```Go
    syntax = "proto3";

    package mec0102.services.apppkgmgmtservice;

    option go_package = "./mec0102.services.apppkgmgmtservice";

    import public "models/<xyz>.proto";
    ```

5. Generate Go code for models and services
    ```sh 
    $ mkdir go-stubs

    $ protoc --go_out=./go-stubs ./AppPkgMgmtProto3/proto3/models/* -I./AppPkgMgmtProto3/proto3
    
    $ protoc --go_out=./go-stubs ./AppPkgMgmtProto3/proto3/services/* --go-grpc_out=go-stubs -I./AppPkgMgmtProto3/proto3
    ```


    > 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.

    > The `<xyz_grpc>.pb.go` file will contain the stubs for the methods defined in the `<xyz_service>.proto` file.

### Ruby

1. Install gRPC Ruby Plugin and required tools
   ```sh
   $ gem install grpc
   $ sudo apt install ruby-grpc-tools
   ```
# assuming `grpc_tools_ruby_protoc` has been installed via `gem install grpc-tools`
RUBY_OUTPUT_DIR="/var/tmp/ruby/mec0102"
mkdir $RUBY_OUTPUT_DIR
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib services/*
grpc_tools_ruby_protoc --ruby_out=$RUBY_OUTPUT_DIR --grpc_out=$RUBY_OUTPUT_DIR/lib models/*

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.

    ```sh
    $ grpc_tools_ruby_protoc -I./AppPkgMgmtProto3/proto3 --ruby_out=ruby-stubs ./AppPkgMgmtProto3/proto3/models/*
    ```

    Run the following command to generate services files, containing stub and service classes for the endpoints and methods defined in Application Package Management API.

    ```sh
    $ grpc_tools_ruby_protoc -I./AppPkgMgmtProto3/proto3 --ruby_out=ruby-stubs --grpc_out=ruby-stubs ./AppPkgMgmtProto3/proto3/services/*
    ```
 No newline at end of file