update openapi generators #29

Merged
vtolstov merged 3 commits from rework into master 2022-02-02 02:29:30 +03:00
4 changed files with 650 additions and 263 deletions
Showing only changes of commit 1ca4bd7668 - Show all commits

3
go.mod
View File

@ -8,6 +8,3 @@ require (
golang.org/x/tools v0.1.8
google.golang.org/protobuf v1.27.1
)
//replace go.unistack.org/micro/v3 => ../micro
//replace go.unistack.org/micro-proto => ../micro-proto

File diff suppressed because it is too large Load Diff

20
util.go
View File

@ -62,9 +62,15 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
if strings.HasPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".") {
ref = strings.TrimPrefix(ref, "."+string(service.Desc.ParentFile().Package())+".")
}
if ref == "micro.codec.Frame" || ref == ".micro.codec.Frame" {
if ref[0] == '.' {
ref = ref[1:]
}
switch ref {
case "micro.codec.Frame":
gfile.P(`errmap["`, rsp.Name, `"] = &`, microCodecPackage.Ident("Frame"), "{}")
} else {
case "micro.errors.Error":
gfile.P(`errmap["`, rsp.Name, `"] = &`, microErrorsPackage.Ident("Error"), "{}")
default:
gfile.P(`errmap["`, rsp.Name, `"] = &`, ref, "{}")
}
}
@ -165,7 +171,7 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
}
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") RecvAndClose() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error) {")
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error) {")
gfile.P("msg := &", gfile.QualifiedGoIdent(method.Output.GoIdent), "{}")
gfile.P("err := s.RecvMsg(msg)")
gfile.P("if err == nil {")
@ -183,6 +189,10 @@ func generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protog
gfile.P("return s.stream.Close()")
gfile.P("}")
gfile.P()
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") CloseSend() error {")
gfile.P("return s.stream.CloseSend()")
gfile.P("}")
gfile.P()
gfile.P("func (s *", unexport(serviceName), "Client", method.GoName, ") Context() ", contextPackage.Ident("Context"), " {")
gfile.P("return s.stream.Context()")
gfile.P("}")
@ -478,7 +488,8 @@ func generateServiceClientStreamInterface(gfile *protogen.GeneratedFile, service
gfile.P("SendMsg(msg interface{}) error")
gfile.P("RecvMsg(msg interface{}) error")
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
gfile.P("RecvAndClose() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error)")
gfile.P("CloseAndRecv() (*", gfile.QualifiedGoIdent(method.Output.GoIdent), ", error)")
gfile.P("CloseSend() () error")
}
gfile.P("Close() error")
if method.Desc.IsStreamingClient() {
@ -505,6 +516,7 @@ func generateServiceServerStreamInterface(gfile *protogen.GeneratedFile, service
gfile.P("RecvMsg(msg interface{}) error")
if method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
gfile.P("SendAndClose(msg *", gfile.QualifiedGoIdent(method.Output.GoIdent), ") error")
gfile.P("CloseSend() error")
}
gfile.P("Close() error")
if method.Desc.IsStreamingClient() {

View File

@ -17,6 +17,7 @@ var (
microClientHttpPackage = protogen.GoImportPath("go.unistack.org/micro-client-http/v3")
microServerHttpPackage = protogen.GoImportPath("go.unistack.org/micro-server-http/v3")
microCodecPackage = protogen.GoImportPath("go.unistack.org/micro/v3/codec")
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro/v3/errors")
timePackage = protogen.GoImportPath("time")
deprecationComment = "// Deprecated: Do not use."
versionComment = "v3.5.3"