基于bilibili kratos的protoc-gen-bswagger修改而来,通过proto文件生成restful的swagger.json文档
对于生成的swagger.json有一些定制内容
https://github.com/protocolbuffers/protobuf
git clone https://github.com/dangerous1990/protoc-plugins.git
进入protoc-plugins项目执行
./init.sh
- hello.proto
syntax = "proto3";
import "google/api/annotations.proto";
service HelloWorld {
// hello
rpc Hello (HelloReq) returns (HelloReply) {
option (google.api.http) = {
post:"/hello"
};
};
}
message HelloReq{
}
message HelloReply{
string name =1;
}
- 使用protoc生成swagger.json
protoc -I"${GOPATH}/src/proto" -Iexample example/hello.proto --swagger_out=example