Skip to content

gRPC Generation


Scaffold a complete [[grpc_routes]] config and synthetic stub files from a .proto file in one command.

Usage

sh
apitwin generate --proto geo.proto --out ./mocks

# Multiple proto files
apitwin generate --proto countries.proto --proto cities.proto --out ./mocks

# With extra import paths for proto imports
apitwin generate --proto geo.proto --import-path ./vendor/protos --format yaml

Generated output

For a CountryService with three methods:

mocks/
├── apitwin.toml            # [[grpc_routes]] for all methods
└── stubs/
    ├── CountryService_GetCountry.json
    ├── CountryService_ListCountries.json
    └── CountryService_CreateCountry.json

Stub synthesis

Stubs are synthesised from the output message descriptor — field names, types, and common naming patterns produce sensible placeholder values:

Field name patternSynthesised value
contains id"{{uuid}}"
contains email"user@example.com"
contains url / uri"https://example.com"
contains time / at / date"{{now}}"
contains name"Example Name"
bool typetrue
int32 / int64 etc.1
float / double1.0

Flags

FlagDefaultDescription
--proto <file>Path to a .proto file; repeat for multiple files
--import-path <dir>Extra directory for proto imports; repeat for multiple
--out <dir>mocksOutput directory
--format <fmt>tomlConfig format: toml, yaml, json

Serve immediately

After generating, start the server:

sh
apitwin --config ./mocks --grpc-proto geo.proto

If your protos import shared types from another directory, use --import-path on both commands:

sh
apitwin generate --proto proto/service/v1/service.proto --import-path proto/ --out ./mocks
apitwin --config ./mocks --grpc-proto proto/service/v1/service.proto --import-path proto/

See also: gRPC Quick Start | Configuration | OpenAPI Generation

Released under the MIT License.