diff --git a/cmd/protoc-gen-openapi/generator/generator.go b/cmd/protoc-gen-openapi/generator/generator.go index 3e5e4c28..cc9d1c02 100644 --- a/cmd/protoc-gen-openapi/generator/generator.go +++ b/cmd/protoc-gen-openapi/generator/generator.go @@ -32,6 +32,7 @@ import ( any_pb "google.golang.org/protobuf/types/known/anypb" wk "github.com/fern-api/protoc-gen-openapi/cmd/protoc-gen-openapi/generator/wellknown" + fernoptions "github.com/fern-api/protoc-gen-openapi/extensions/fern" v3 "github.com/fern-api/protoc-gen-openapi/openapiv3" ) @@ -761,6 +762,13 @@ func (g *OpenAPIv3Generator) addPathsToDocumentV3(d *v3.Document, services []*pr op, path2 := g.buildOperationV3( d, operationID, service.GoName, comment, defaultHost, path, body, inputMessage, outputMessage) + extFernSummary := proto.GetExtension(method.Desc.Options(), fernoptions.E_Summary) + if extFernSummary != nil { + if summary, ok := extFernSummary.(string); ok && summary != "" { + op.Summary = summary + } + } + // Merge any `Operation` annotations with the current extOperation := proto.GetExtension(method.Desc.Options(), v3.E_Operation) if extOperation != nil { @@ -1179,4 +1187,4 @@ func (g *OpenAPIv3Generator) addOneOfFieldsToSchema(d *v3.Document, oneofs []*pr }, ) } -} \ No newline at end of file +} diff --git a/extensions/fern/options.pb.go b/extensions/fern/options.pb.go new file mode 100644 index 00000000..9632b30e --- /dev/null +++ b/extensions/fern/options.pb.go @@ -0,0 +1,85 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.10 +// protoc v6.33.0 +// source: extensions/fern/options.proto + +package fern + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + descriptorpb "google.golang.org/protobuf/types/descriptorpb" + reflect "reflect" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +var file_extensions_fern_options_proto_extTypes = []protoimpl.ExtensionInfo{ + { + ExtendedType: (*descriptorpb.MethodOptions)(nil), + ExtensionType: (*string)(nil), + Field: 51001, + Name: "fern.summary", + Tag: "bytes,51001,opt,name=summary", + Filename: "extensions/fern/options.proto", + }, +} + +// Extension fields to descriptorpb.MethodOptions. +var ( + // Custom summary for the RPC method that will be used as the OpenAPI operation summary. + // This overrides any auto-generated summary. + // + // optional string summary = 51001; + E_Summary = &file_extensions_fern_options_proto_extTypes[0] +) + +var File_extensions_fern_options_proto protoreflect.FileDescriptor + +const file_extensions_fern_options_proto_rawDesc = "" + + "\n" + + "\x1dextensions/fern/options.proto\x12\x04fern\x1a google/protobuf/descriptor.proto::\n" + + "\asummary\x12\x1e.google.protobuf.MethodOptions\x18\xb9\x8e\x03 \x01(\tR\asummaryB8Z6github.com/fern-api/protoc-gen-openapi/extensions/fernb\x06proto3" + +var file_extensions_fern_options_proto_goTypes = []any{ + (*descriptorpb.MethodOptions)(nil), // 0: google.protobuf.MethodOptions +} +var file_extensions_fern_options_proto_depIdxs = []int32{ + 0, // 0: fern.summary:extendee -> google.protobuf.MethodOptions + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 0, // [0:1] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_extensions_fern_options_proto_init() } +func file_extensions_fern_options_proto_init() { + if File_extensions_fern_options_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_extensions_fern_options_proto_rawDesc), len(file_extensions_fern_options_proto_rawDesc)), + NumEnums: 0, + NumMessages: 0, + NumExtensions: 1, + NumServices: 0, + }, + GoTypes: file_extensions_fern_options_proto_goTypes, + DependencyIndexes: file_extensions_fern_options_proto_depIdxs, + ExtensionInfos: file_extensions_fern_options_proto_extTypes, + }.Build() + File_extensions_fern_options_proto = out.File + file_extensions_fern_options_proto_goTypes = nil + file_extensions_fern_options_proto_depIdxs = nil +} diff --git a/extensions/fern/options.proto b/extensions/fern/options.proto new file mode 100644 index 00000000..400ab8f8 --- /dev/null +++ b/extensions/fern/options.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +package fern; + +import "google/protobuf/descriptor.proto"; + +option go_package = "github.com/fern-api/protoc-gen-openapi/extensions/fern"; + +extend google.protobuf.MethodOptions { + // Custom summary for the RPC method that will be used as the OpenAPI operation summary. + // This overrides any auto-generated summary. + string summary = 51001; +}