From d9cd1c4f49c44632377c0b4f15f6e69521bfc2a5 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Thu, 21 Sep 2023 22:56:55 -0700 Subject: [PATCH] minor fixes - adding 'parent' concept in the resource model - fixing protoc docs --- DEVELOPMENT.md | 2 +- examples/bookstore.proto | 6 +- examples/bookstore.yaml | 7 +- examples/bookstore.yaml.output.proto | 22 +++++ schema/resourcedefinition.pb.go | 143 +++++++++++++++------------ schema/resourcedefinition.proto | 10 +- writer/proto/proto.go | 22 +++-- 7 files changed, 138 insertions(+), 74 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7990a5a..bc37192 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -5,5 +5,5 @@ The standard GoLang toolchain is used, with the addition of protobuf for compiling the resource definition. -1. `protoc ./aepc/schema/resourcedefinition.proto --go_opt paths=source_relative --go_out=.` +1. `protoc ./schema/resourcedefinition.proto --go_opt paths=source_relative --go_out=.` 2. `go build main.go` \ No newline at end of file diff --git a/examples/bookstore.proto b/examples/bookstore.proto index 1614c65..b34fd42 100644 --- a/examples/bookstore.proto +++ b/examples/bookstore.proto @@ -1,8 +1,12 @@ +// NOTE: since we are missing some proto annotations that +// must be added, the proto representation is outdated. See bookstore.yaml syntax = "proto3"; package tutorial; option go_package = "proto"; -service Bookstore {} +// bookstore.examples.com +service Bookstore { +} message Book { diff --git a/examples/bookstore.yaml b/examples/bookstore.yaml index 5cbe308..19a7072 100644 --- a/examples/bookstore.yaml +++ b/examples/bookstore.yaml @@ -1,3 +1,6 @@ -name: Bookstore +name: bookstore.example.com resources: - - kind: Book \ No newline at end of file + - kind: Book + parents: + - "bookstore.example.com/Publisher" + - kind: Publisher \ No newline at end of file diff --git a/examples/bookstore.yaml.output.proto b/examples/bookstore.yaml.output.proto index bee8dc1..b35618d 100644 --- a/examples/bookstore.yaml.output.proto +++ b/examples/bookstore.yaml.output.proto @@ -18,6 +18,20 @@ message ReadBookRequest { string path = 1; } +message Publisher { + string path = 1; +} + +message CreatePublisherRequest { + string id = 1; + + Publisher resource = 2; +} + +message ReadPublisherRequest { + string path = 1; +} + service Bookstore { rpc CreateBook ( CreateBookRequest ) returns ( Book ) { option (google.api.http) = { post: "/book" }; @@ -26,4 +40,12 @@ service Bookstore { rpc ReadBook ( ReadBookRequest ) returns ( Book ) { option (google.api.http) = { get: "/{path=book/*}" }; } + + rpc CreatePublisher ( CreatePublisherRequest ) returns ( Publisher ) { + option (google.api.http) = { post: "/publisher" }; + } + + rpc ReadPublisher ( ReadPublisherRequest ) returns ( Publisher ) { + option (google.api.http) = { get: "/{path=publisher/*}" }; + } } diff --git a/schema/resourcedefinition.pb.go b/schema/resourcedefinition.pb.go index 84b3068..f3c74b6 100644 --- a/schema/resourcedefinition.pb.go +++ b/schema/resourcedefinition.pb.go @@ -7,9 +7,9 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 -// protoc v4.24.2 -// source: aepc/schema/resourcedefinition.proto +// protoc-gen-go v1.31.0 +// protoc v4.24.3 +// source: schema/resourcedefinition.proto package schema @@ -39,7 +39,7 @@ type Service struct { func (x *Service) Reset() { *x = Service{} if protoimpl.UnsafeEnabled { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[0] + mi := &file_schema_resourcedefinition_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -52,7 +52,7 @@ func (x *Service) String() string { func (*Service) ProtoMessage() {} func (x *Service) ProtoReflect() protoreflect.Message { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[0] + mi := &file_schema_resourcedefinition_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -65,7 +65,7 @@ func (x *Service) ProtoReflect() protoreflect.Message { // Deprecated: Use Service.ProtoReflect.Descriptor instead. func (*Service) Descriptor() ([]byte, []int) { - return file_aepc_schema_resourcedefinition_proto_rawDescGZIP(), []int{0} + return file_schema_resourcedefinition_proto_rawDescGZIP(), []int{0} } func (x *Service) GetName() string { @@ -87,15 +87,20 @@ type Resource struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Kind is the type of the resource - Kind string `protobuf:"bytes,1,opt,name=kind,proto3" json:"kind,omitempty"` - Properties map[string]*Property `protobuf:"bytes,2,rep,name=properties,proto3" json:"properties,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // The type of the resource. Used to programmatically + // refer to and identify the resource. + Kind string `protobuf:"bytes,1,opt,name=kind,proto3" json:"kind,omitempty"` + // The plural of the resource. Used in documentation. + Plural string `protobuf:"bytes,2,opt,name=plural,proto3" json:"plural,omitempty"` + // The list of parent resources, referred to via the kind. + Parents []string `protobuf:"bytes,3,rep,name=parents,proto3" json:"parents,omitempty"` + Properties map[string]*Property `protobuf:"bytes,4,rep,name=properties,proto3" json:"properties,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *Resource) Reset() { *x = Resource{} if protoimpl.UnsafeEnabled { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[1] + mi := &file_schema_resourcedefinition_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -108,7 +113,7 @@ func (x *Resource) String() string { func (*Resource) ProtoMessage() {} func (x *Resource) ProtoReflect() protoreflect.Message { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[1] + mi := &file_schema_resourcedefinition_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -121,7 +126,7 @@ func (x *Resource) ProtoReflect() protoreflect.Message { // Deprecated: Use Resource.ProtoReflect.Descriptor instead. func (*Resource) Descriptor() ([]byte, []int) { - return file_aepc_schema_resourcedefinition_proto_rawDescGZIP(), []int{1} + return file_schema_resourcedefinition_proto_rawDescGZIP(), []int{1} } func (x *Resource) GetKind() string { @@ -131,6 +136,20 @@ func (x *Resource) GetKind() string { return "" } +func (x *Resource) GetPlural() string { + if x != nil { + return x.Plural + } + return "" +} + +func (x *Resource) GetParents() []string { + if x != nil { + return x.Parents + } + return nil +} + func (x *Resource) GetProperties() map[string]*Property { if x != nil { return x.Properties @@ -147,7 +166,7 @@ type Property struct { func (x *Property) Reset() { *x = Property{} if protoimpl.UnsafeEnabled { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[2] + mi := &file_schema_resourcedefinition_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -160,7 +179,7 @@ func (x *Property) String() string { func (*Property) ProtoMessage() {} func (x *Property) ProtoReflect() protoreflect.Message { - mi := &file_aepc_schema_resourcedefinition_proto_msgTypes[2] + mi := &file_schema_resourcedefinition_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -173,54 +192,56 @@ func (x *Property) ProtoReflect() protoreflect.Message { // Deprecated: Use Property.ProtoReflect.Descriptor instead. func (*Property) Descriptor() ([]byte, []int) { - return file_aepc_schema_resourcedefinition_proto_rawDescGZIP(), []int{2} + return file_schema_resourcedefinition_proto_rawDescGZIP(), []int{2} } -var File_aepc_schema_resourcedefinition_proto protoreflect.FileDescriptor - -var file_aepc_schema_resourcedefinition_proto_rawDesc = []byte{ - 0x0a, 0x24, 0x61, 0x65, 0x70, 0x63, 0x2f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2f, 0x72, 0x65, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x46, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x52, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x22, 0xa3, - 0x01, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6b, - 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, - 0x39, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x50, - 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, - 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x48, 0x0a, 0x0f, 0x50, 0x72, - 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x1f, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, - 0x2e, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x3a, 0x02, 0x38, 0x01, 0x22, 0x0a, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, - 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, +var File_schema_resourcedefinition_proto protoreflect.FileDescriptor + +var file_schema_resourcedefinition_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, + 0x65, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x22, 0x46, 0x0a, 0x07, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x27, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x09, + 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x22, 0xd5, 0x01, 0x0a, 0x08, 0x52, 0x65, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x6c, + 0x75, 0x72, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6c, 0x75, 0x72, + 0x61, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x39, 0x0a, 0x0a, + 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x70, + 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x70, 0x72, 0x6f, + 0x70, 0x65, 0x72, 0x74, 0x69, 0x65, 0x73, 0x1a, 0x48, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x70, 0x65, + 0x72, 0x74, 0x69, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x72, + 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x22, 0x0a, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x42, 0x09, 0x5a, + 0x07, 0x2f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_aepc_schema_resourcedefinition_proto_rawDescOnce sync.Once - file_aepc_schema_resourcedefinition_proto_rawDescData = file_aepc_schema_resourcedefinition_proto_rawDesc + file_schema_resourcedefinition_proto_rawDescOnce sync.Once + file_schema_resourcedefinition_proto_rawDescData = file_schema_resourcedefinition_proto_rawDesc ) -func file_aepc_schema_resourcedefinition_proto_rawDescGZIP() []byte { - file_aepc_schema_resourcedefinition_proto_rawDescOnce.Do(func() { - file_aepc_schema_resourcedefinition_proto_rawDescData = protoimpl.X.CompressGZIP(file_aepc_schema_resourcedefinition_proto_rawDescData) +func file_schema_resourcedefinition_proto_rawDescGZIP() []byte { + file_schema_resourcedefinition_proto_rawDescOnce.Do(func() { + file_schema_resourcedefinition_proto_rawDescData = protoimpl.X.CompressGZIP(file_schema_resourcedefinition_proto_rawDescData) }) - return file_aepc_schema_resourcedefinition_proto_rawDescData + return file_schema_resourcedefinition_proto_rawDescData } -var file_aepc_schema_resourcedefinition_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_aepc_schema_resourcedefinition_proto_goTypes = []interface{}{ +var file_schema_resourcedefinition_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_schema_resourcedefinition_proto_goTypes = []interface{}{ (*Service)(nil), // 0: Service (*Resource)(nil), // 1: Resource (*Property)(nil), // 2: Property nil, // 3: Resource.PropertiesEntry } -var file_aepc_schema_resourcedefinition_proto_depIdxs = []int32{ +var file_schema_resourcedefinition_proto_depIdxs = []int32{ 1, // 0: Service.resources:type_name -> Resource 3, // 1: Resource.properties:type_name -> Resource.PropertiesEntry 2, // 2: Resource.PropertiesEntry.value:type_name -> Property @@ -231,13 +252,13 @@ var file_aepc_schema_resourcedefinition_proto_depIdxs = []int32{ 0, // [0:3] is the sub-list for field type_name } -func init() { file_aepc_schema_resourcedefinition_proto_init() } -func file_aepc_schema_resourcedefinition_proto_init() { - if File_aepc_schema_resourcedefinition_proto != nil { +func init() { file_schema_resourcedefinition_proto_init() } +func file_schema_resourcedefinition_proto_init() { + if File_schema_resourcedefinition_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_aepc_schema_resourcedefinition_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Service); i { case 0: return &v.state @@ -249,7 +270,7 @@ func file_aepc_schema_resourcedefinition_proto_init() { return nil } } - file_aepc_schema_resourcedefinition_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Resource); i { case 0: return &v.state @@ -261,7 +282,7 @@ func file_aepc_schema_resourcedefinition_proto_init() { return nil } } - file_aepc_schema_resourcedefinition_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Property); i { case 0: return &v.state @@ -278,18 +299,18 @@ func file_aepc_schema_resourcedefinition_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_aepc_schema_resourcedefinition_proto_rawDesc, + RawDescriptor: file_schema_resourcedefinition_proto_rawDesc, NumEnums: 0, NumMessages: 4, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_aepc_schema_resourcedefinition_proto_goTypes, - DependencyIndexes: file_aepc_schema_resourcedefinition_proto_depIdxs, - MessageInfos: file_aepc_schema_resourcedefinition_proto_msgTypes, + GoTypes: file_schema_resourcedefinition_proto_goTypes, + DependencyIndexes: file_schema_resourcedefinition_proto_depIdxs, + MessageInfos: file_schema_resourcedefinition_proto_msgTypes, }.Build() - File_aepc_schema_resourcedefinition_proto = out.File - file_aepc_schema_resourcedefinition_proto_rawDesc = nil - file_aepc_schema_resourcedefinition_proto_goTypes = nil - file_aepc_schema_resourcedefinition_proto_depIdxs = nil + File_schema_resourcedefinition_proto = out.File + file_schema_resourcedefinition_proto_rawDesc = nil + file_schema_resourcedefinition_proto_goTypes = nil + file_schema_resourcedefinition_proto_depIdxs = nil } diff --git a/schema/resourcedefinition.proto b/schema/resourcedefinition.proto index bf0bccd..94d7160 100644 --- a/schema/resourcedefinition.proto +++ b/schema/resourcedefinition.proto @@ -13,10 +13,14 @@ message Service { } message Resource { - // Kind is the type of the resource + // The type of the resource. Used to programmatically + // refer to and identify the resource. string kind = 1; - repeated string parents = 2; - map properties = 3; + // The plural of the resource. Used in documentation. + string plural = 2; + // The list of parent resources, referred to via the kind. + repeated string parents = 3; + map properties = 4; // TODO: add method support // repeated Method methods = 3; } diff --git a/writer/proto/proto.go b/writer/proto/proto.go index cfb3ac1..2a47dc9 100644 --- a/writer/proto/proto.go +++ b/writer/proto/proto.go @@ -21,25 +21,30 @@ import ( "github.com/aep-dev/aepc/schema" "github.com/jhump/protoreflect/desc/builder" "github.com/jhump/protoreflect/desc/protoprint" + "golang.org/x/text/cases" + "golang.org/x/text/language" "google.golang.org/protobuf/types/descriptorpb" ) +var capitalizer cases.Caser + +func init() { + capitalizer = cases.Title(language.AmericanEnglish) +} + func WriteServiceToProto(s *schema.Service) ([]byte, error) { fb := builder.NewFile("test.proto") fb.IsProto3 = true fb.SetComments(builder.Comments{ LeadingComment: "this file is autogenerated by aepc", }) - serviceNameAsLower := fmt.Sprintf("/%s", strings.ToLower(s.Name)) + pServiceName := toProtoServiceName(s.Name) + serviceNameAsLower := fmt.Sprintf("/%s", strings.ToLower(pServiceName)) fo := &descriptorpb.FileOptions{ GoPackage: &serviceNameAsLower, } fb.SetOptions(fo) - sb := builder.NewService(s.Name) - // so := &descriptorpb.ServiceOptions{ - // go_ - // } - // sb.SetOptions(options *descriptorpb.ServiceOptions) + sb := builder.NewService(pServiceName) fb.AddService(sb) for _, r := range s.Resources { err := AddResource(r, fb, sb) @@ -59,3 +64,8 @@ func WriteServiceToProto(s *schema.Service) ([]byte, error) { } return output.Bytes(), nil } + +func toProtoServiceName(serviceName string) string { + parts := strings.SplitN(serviceName, ".", 2) + return capitalizer.String(parts[0]) +}