protoc-gen-jsonpb-ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

protoc-gen-jsonpb-ts

This is protoc plugin for generating TypeScript definitions.

Feature

  • 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)

Installation

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

Usage

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

Configuration

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

Options

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

Examples

Some examples are available under example directory

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i protoc-gen-jsonpb-ts

Weekly Downloads

17

Version

0.1.9

License

MIT

Unpacked Size

6.72 MB

Total Files

1220

Last publish

Collaborators

  • sue71