This is protoc plugin for generating TypeScript definitions.
- Generate TypeScript definitions according to the spec. (https://developers.google.com/protocol-buffers/docs/proto3#json)
- Generate request class from the method definition if custom options are defined (https://cloud.google.com/service-infrastructure/docs/service-management/reference/rpc/google.api#http)
First you need to install ProtocolBuffers v3.0.0 or later.
Then, install this plugin via npm
.
npm install protoc-gen-jsonpb-ts --save-dev
This plugin uses custom options. You should define these options in proto.
Example
rpc Method(Request) returns (Response) {
option (google.api.http) = {
post : "/v1/method"
body : "*"
};
}
Then, generate definitions using protoc
command.
protoc \
-I submodules/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--plugin=./node_modules/.bin/protoc-gen-jsonpb-ts \
--jsonpb-ts_out=. \
path/to/your_service.proto
This plugin looks for a config file named protoc-gen-tsconfig.json
and loads settings from it.
{
ignorePackage: boolean; // defalut false
jsonFormat: boolean; // default true
}
Also supporting cli options.
protoc --jsonpb-ts_out=ignorePackage=true:.
ignorePackage
By default, use package
as a namespace
. If true, namespace
will not be made.
jsonFormat
By default, the well-known type is changed according to this specification. If true, you can use all types as it is.
Some examples are available under example directory