fix for empty default response

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2022-03-03 19:11:57 +03:00
parent e6b8324395
commit 41e32e36b3
2 changed files with 46 additions and 41 deletions

View File

@ -653,49 +653,54 @@ func (g *openapiv3Generator) buildOperationV3(
opt := eopt.(*v3.Operation)
if r := opt.Responses; r != nil {
responses = r
}
if ref := responses.Default.GetReference(); ref != nil && ref.GetXRef() != "" {
xref := strings.TrimPrefix(ref.GetXRef(), ".")
description := "Default"
if strings.Contains(xref, "micro.errors.Error") {
description += " Error"
}
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
if err != nil {
log.Printf("unknown ref type %s err %v", xref, err)
} else {
responses.Default.Oneof = &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: description,
Content: g.responseContentForMessage(&protogen.Message{
Desc: desc.(protoreflect.MessageDescriptor),
}),
},
}
}
}
for _, rref := range responses.GetResponseOrReference() {
if ref := rref.Value.GetReference(); ref != nil && ref.GetXRef() != "" {
xref := strings.TrimPrefix(ref.GetXRef(), ".")
description := "Default"
if strings.Contains(xref, "micro.errors.Error") {
description += " Error"
}
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
if err != nil {
log.Printf("unknown ref type %s err %v", xref, err)
} else {
responses.Default.Oneof = &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: description,
Content: g.responseContentForMessage(&protogen.Message{
Desc: desc.(protoreflect.MessageDescriptor),
}),
},
rd := responses.Default
if rd != nil {
if ref := rd.GetReference(); ref != nil && ref.GetXRef() != "" {
xref := strings.TrimPrefix(ref.GetXRef(), ".")
description := "Default"
if strings.Contains(xref, "micro.errors.Error") {
description += " Error"
}
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
if err != nil {
log.Printf("unknown ref type %s err %v", xref, err)
} else {
responses.Default.Oneof = &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: description,
Content: g.responseContentForMessage(&protogen.Message{
Desc: desc.(protoreflect.MessageDescriptor),
}),
},
}
}
}
}
for _, rref := range responses.GetResponseOrReference() {
if ref := rref.Value.GetReference(); ref != nil && ref.GetXRef() != "" {
xref := strings.TrimPrefix(ref.GetXRef(), ".")
description := "Default"
if strings.Contains(xref, "micro.errors.Error") {
description += " Error"
}
desc, err := protofiles.FindDescriptorByName(protoreflect.FullName(xref))
if err != nil {
log.Printf("unknown ref type %s err %v", xref, err)
} else {
responses.Default.Oneof = &v3.ResponseOrReference_Response{
Response: &v3.Response{
Description: description,
Content: g.responseContentForMessage(&protogen.Message{
Desc: desc.(protoreflect.MessageDescriptor),
}),
},
}
}
}
}
} else {
responses = &v3.Responses{}
}
} else {
responses = &v3.Responses{}

View File

@ -16,8 +16,8 @@ var (
microServerPackage = protogen.GoImportPath("go.unistack.org/micro/v3/server")
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-proto/v3/codec")
microErrorsPackage = protogen.GoImportPath("go.unistack.org/micro-proto/v3/errors")
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"