Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,33 @@ func encodeOpenAPI(file *wrapper, format Format) (*descriptor.ResponseFile, erro
}, nil
}

func deprecateFieldsAndMethods(file *descriptor.File) {
if opts := file.GetOptions(); opts != nil && opts.GetDeprecated() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we lift this check outside of this function so that it's clearer in the caller what's happening?

for _, msg := range file.Messages {
for _, field := range msg.GetField() {
if field.Options == nil {
field.Options = &descriptorpb.FieldOptions{}
}
field.Options.Deprecated = proto.Bool(true)
}
}
for _, svc := range file.Services {
for _, method := range svc.GetMethod() {
if method.Options == nil {
method.Options = &descriptorpb.MethodOptions{}
}
method.Options.Deprecated = proto.Bool(true)
}
}
}
}

func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.ResponseFile, error) {
var files []*descriptor.ResponseFile
for _, f := range targets {
// Because of how the generator merges definitions, it is simpler to deprecate field and methods here if the file is deprecated
deprecateFieldsAndMethods(f)
}
if g.reg.IsAllowMerge() {
var mergedTarget *descriptor.File
// try to find proto leader
Expand Down
Loading