基于bilibili kratos的protoc-gen-bswagger修改而来,通过proto文件生成restful的swagger.json文档
对于生成的swagger.json有一些定制内容
https://github.com/protocolbuffers/protobuf
git clone https://github.com/dangerous1990/protoc-gen-yswagger.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 --yswagger_out=example
# 支持覆盖requestID
protoc -I"${GOPATH}/src/proto" -Iexample example/hello.proto --yswagger_out=example --yswagger_opt='requestID=request_id'
post | get | delete | put | |
---|---|---|---|---|
path | ✅ | ✅ | ✅ | ✅ |
query | ❌ | ✅ | ✅ | ✅ |
form | ✅ | ❌ | ❌ | ❌ |
json | ✅ | ❌ | ❌ | ✅ |
- path参数
string id = 1 [(gogoproto.moretags) = 'params:"id"'];
- query参数
string key1 = 2 [(gogoproto.moretags) = 'query:"key"'];
- form参数
string key1 = 2 [(gogoproto.moretags) = 'form:"key"'];
- json参数
string key1 = 2 [(gogoproto.jsontag) = 'key'];