From c388afd792b937dcf278b7c9dc5ddc7f257091e9 Mon Sep 17 00:00:00 2001 From: Yusuke Tsutsumi Date: Sat, 30 Sep 2023 22:02:58 -0700 Subject: [PATCH] feat: adding property support Adding the ability to set properties in the resource message, wiring them into the generated resource. --- examples/bookstore.yaml | 8 + examples/bookstore.yaml.output.proto | 10 +- schema/resourcedefinition.pb.go | 239 +++++++++++++++++++-------- schema/resourcedefinition.proto | 19 ++- writer/proto/resource.go | 13 +- 5 files changed, 208 insertions(+), 81 deletions(-) diff --git a/examples/bookstore.yaml b/examples/bookstore.yaml index 38d6fd8..43e1c67 100644 --- a/examples/bookstore.yaml +++ b/examples/bookstore.yaml @@ -1,6 +1,10 @@ name: "bookstore.example.com" resources: - kind: "Book" + properties: + isbn: + type: STRING + number: 1 parents: - "bookstore.example.com/Publisher" methods: @@ -14,6 +18,10 @@ resources: read: {} list: {} - kind: "Author" + properties: + name: + type: STRING + number: 1 parents: - "Publisher" methods: diff --git a/examples/bookstore.yaml.output.proto b/examples/bookstore.yaml.output.proto index e481235..3d520e5 100644 --- a/examples/bookstore.yaml.output.proto +++ b/examples/bookstore.yaml.output.proto @@ -7,7 +7,9 @@ import "google/protobuf/empty.proto"; option go_package = "/bookstore"; message Author { - string path = 1; + string path = 10000; + + string name = 1; } message ReadAuthorRequest { @@ -15,7 +17,9 @@ message ReadAuthorRequest { } message Book { - string path = 1; + string path = 10000; + + string isbn = 1; } message CreateBookRequest { @@ -47,7 +51,7 @@ message ListBookResponse { } message Publisher { - string path = 1; + string path = 10000; } message ReadPublisherRequest { diff --git a/schema/resourcedefinition.pb.go b/schema/resourcedefinition.pb.go index 7ad189c..b131788 100644 --- a/schema/resourcedefinition.pb.go +++ b/schema/resourcedefinition.pb.go @@ -7,8 +7,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 -// protoc v4.24.2 +// protoc-gen-go v1.31.0 +// protoc v3.6.1 // source: schema/resourcedefinition.proto package schema @@ -27,6 +27,52 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type Type int32 + +const ( + Type_UNSPECIFIED Type = 0 + Type_STRING Type = 1 +) + +// Enum value maps for Type. +var ( + Type_name = map[int32]string{ + 0: "UNSPECIFIED", + 1: "STRING", + } + Type_value = map[string]int32{ + "UNSPECIFIED": 0, + "STRING": 1, + } +) + +func (x Type) Enum() *Type { + p := new(Type) + *p = x + return p +} + +func (x Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Type) Descriptor() protoreflect.EnumDescriptor { + return file_schema_resourcedefinition_proto_enumTypes[0].Descriptor() +} + +func (Type) Type() protoreflect.EnumType { + return &file_schema_resourcedefinition_proto_enumTypes[0] +} + +func (x Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Type.Descriptor instead. +func (Type) EnumDescriptor() ([]byte, []int) { + return file_schema_resourcedefinition_proto_rawDescGZIP(), []int{0} +} + type Service struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -94,8 +140,10 @@ type Resource struct { 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 + 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"` // method support - Methods *Methods `protobuf:"bytes,4,opt,name=methods,proto3" json:"methods,omitempty"` + Methods *Methods `protobuf:"bytes,5,opt,name=methods,proto3" json:"methods,omitempty"` } func (x *Resource) Reset() { @@ -151,6 +199,13 @@ func (x *Resource) GetParents() []string { return nil } +func (x *Resource) GetProperties() map[string]*Property { + if x != nil { + return x.Properties + } + return nil +} + func (x *Resource) GetMethods() *Methods { if x != nil { return x.Methods @@ -241,6 +296,11 @@ type Property struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Type Type `protobuf:"varint,1,opt,name=type,proto3,enum=Type" json:"type,omitempty"` + // field number used for protobuf or other systems where fields must + // be explicitly enumerated. + Number int32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` } func (x *Property) Reset() { @@ -275,6 +335,20 @@ func (*Property) Descriptor() ([]byte, []int) { return file_schema_resourcedefinition_proto_rawDescGZIP(), []int{3} } +func (x *Property) GetType() Type { + if x != nil { + return x.Type + } + return Type_UNSPECIFIED +} + +func (x *Property) GetNumber() int32 { + if x != nil { + return x.Number + } + return 0 +} + type Methods_CreateMethod struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -284,7 +358,7 @@ type Methods_CreateMethod struct { func (x *Methods_CreateMethod) Reset() { *x = Methods_CreateMethod{} if protoimpl.UnsafeEnabled { - mi := &file_schema_resourcedefinition_proto_msgTypes[4] + mi := &file_schema_resourcedefinition_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -297,7 +371,7 @@ func (x *Methods_CreateMethod) String() string { func (*Methods_CreateMethod) ProtoMessage() {} func (x *Methods_CreateMethod) ProtoReflect() protoreflect.Message { - mi := &file_schema_resourcedefinition_proto_msgTypes[4] + mi := &file_schema_resourcedefinition_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -322,7 +396,7 @@ type Methods_ReadMethod struct { func (x *Methods_ReadMethod) Reset() { *x = Methods_ReadMethod{} if protoimpl.UnsafeEnabled { - mi := &file_schema_resourcedefinition_proto_msgTypes[5] + mi := &file_schema_resourcedefinition_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -335,7 +409,7 @@ func (x *Methods_ReadMethod) String() string { func (*Methods_ReadMethod) ProtoMessage() {} func (x *Methods_ReadMethod) ProtoReflect() protoreflect.Message { - mi := &file_schema_resourcedefinition_proto_msgTypes[5] + mi := &file_schema_resourcedefinition_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -360,7 +434,7 @@ type Methods_UpdateMethod struct { func (x *Methods_UpdateMethod) Reset() { *x = Methods_UpdateMethod{} if protoimpl.UnsafeEnabled { - mi := &file_schema_resourcedefinition_proto_msgTypes[6] + mi := &file_schema_resourcedefinition_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -373,7 +447,7 @@ func (x *Methods_UpdateMethod) String() string { func (*Methods_UpdateMethod) ProtoMessage() {} func (x *Methods_UpdateMethod) ProtoReflect() protoreflect.Message { - mi := &file_schema_resourcedefinition_proto_msgTypes[6] + mi := &file_schema_resourcedefinition_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -398,7 +472,7 @@ type Methods_DeleteMethod struct { func (x *Methods_DeleteMethod) Reset() { *x = Methods_DeleteMethod{} if protoimpl.UnsafeEnabled { - mi := &file_schema_resourcedefinition_proto_msgTypes[7] + mi := &file_schema_resourcedefinition_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -411,7 +485,7 @@ func (x *Methods_DeleteMethod) String() string { func (*Methods_DeleteMethod) ProtoMessage() {} func (x *Methods_DeleteMethod) ProtoReflect() protoreflect.Message { - mi := &file_schema_resourcedefinition_proto_msgTypes[7] + mi := &file_schema_resourcedefinition_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -436,7 +510,7 @@ type Methods_ListMethod struct { func (x *Methods_ListMethod) Reset() { *x = Methods_ListMethod{} if protoimpl.UnsafeEnabled { - mi := &file_schema_resourcedefinition_proto_msgTypes[8] + mi := &file_schema_resourcedefinition_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -449,7 +523,7 @@ func (x *Methods_ListMethod) String() string { func (*Methods_ListMethod) ProtoMessage() {} func (x *Methods_ListMethod) ProtoReflect() protoreflect.Message { - mi := &file_schema_resourcedefinition_proto_msgTypes[8] + mi := &file_schema_resourcedefinition_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -474,36 +548,50 @@ var file_schema_resourcedefinition_proto_rawDesc = []byte{ 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, 0x74, 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, 0x22, 0x0a, 0x07, 0x6d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, - 0xb4, 0x02, 0x0a, 0x07, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x12, 0x2d, 0x0a, 0x06, 0x63, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, - 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, - 0x6f, 0x64, 0x52, 0x06, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x27, 0x0a, 0x04, 0x72, 0x65, - 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, - 0x64, 0x73, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x04, 0x72, - 0x65, 0x61, 0x64, 0x12, 0x2d, 0x0a, 0x06, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x06, 0x75, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x12, 0x2d, 0x0a, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x12, 0x27, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x13, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, - 0x74, 0x68, 0x6f, 0x64, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x1a, 0x0e, 0x0a, 0x0c, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0c, 0x0a, 0x0a, 0x52, 0x65, - 0x61, 0x64, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0e, 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0e, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0c, 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, - 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 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, + 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x22, 0xf9, 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, 0x12, 0x22, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x73, 0x52, 0x07, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 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, 0xb4, 0x02, 0x0a, 0x07, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x73, 0x12, 0x2d, 0x0a, 0x06, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x06, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x12, 0x27, 0x0a, 0x04, 0x72, 0x65, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, + 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x52, 0x04, 0x72, 0x65, 0x61, 0x64, 0x12, 0x2d, 0x0a, 0x06, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x52, 0x06, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x2d, 0x0a, 0x06, 0x64, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, + 0x64, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, + 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x27, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x2e, + 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, + 0x1a, 0x0e, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, + 0x1a, 0x0c, 0x0a, 0x0a, 0x52, 0x65, 0x61, 0x64, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0e, + 0x0a, 0x0c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0e, + 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x1a, 0x0c, + 0x0a, 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x3d, 0x0a, 0x08, + 0x50, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x74, 0x79, 0x12, 0x19, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x05, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x2a, 0x23, 0x0a, 0x04, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, + 0x42, 0x09, 0x5a, 0x07, 0x2f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -518,31 +606,37 @@ func file_schema_resourcedefinition_proto_rawDescGZIP() []byte { return file_schema_resourcedefinition_proto_rawDescData } -var file_schema_resourcedefinition_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_schema_resourcedefinition_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_schema_resourcedefinition_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_schema_resourcedefinition_proto_goTypes = []interface{}{ - (*Service)(nil), // 0: Service - (*Resource)(nil), // 1: Resource - (*Methods)(nil), // 2: Methods - (*Property)(nil), // 3: Property - (*Methods_CreateMethod)(nil), // 4: Methods.CreateMethod - (*Methods_ReadMethod)(nil), // 5: Methods.ReadMethod - (*Methods_UpdateMethod)(nil), // 6: Methods.UpdateMethod - (*Methods_DeleteMethod)(nil), // 7: Methods.DeleteMethod - (*Methods_ListMethod)(nil), // 8: Methods.ListMethod + (Type)(0), // 0: Type + (*Service)(nil), // 1: Service + (*Resource)(nil), // 2: Resource + (*Methods)(nil), // 3: Methods + (*Property)(nil), // 4: Property + nil, // 5: Resource.PropertiesEntry + (*Methods_CreateMethod)(nil), // 6: Methods.CreateMethod + (*Methods_ReadMethod)(nil), // 7: Methods.ReadMethod + (*Methods_UpdateMethod)(nil), // 8: Methods.UpdateMethod + (*Methods_DeleteMethod)(nil), // 9: Methods.DeleteMethod + (*Methods_ListMethod)(nil), // 10: Methods.ListMethod } var file_schema_resourcedefinition_proto_depIdxs = []int32{ - 1, // 0: Service.resources:type_name -> Resource - 2, // 1: Resource.methods:type_name -> Methods - 4, // 2: Methods.create:type_name -> Methods.CreateMethod - 5, // 3: Methods.read:type_name -> Methods.ReadMethod - 6, // 4: Methods.update:type_name -> Methods.UpdateMethod - 7, // 5: Methods.delete:type_name -> Methods.DeleteMethod - 8, // 6: Methods.list:type_name -> Methods.ListMethod - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 2, // 0: Service.resources:type_name -> Resource + 5, // 1: Resource.properties:type_name -> Resource.PropertiesEntry + 3, // 2: Resource.methods:type_name -> Methods + 6, // 3: Methods.create:type_name -> Methods.CreateMethod + 7, // 4: Methods.read:type_name -> Methods.ReadMethod + 8, // 5: Methods.update:type_name -> Methods.UpdateMethod + 9, // 6: Methods.delete:type_name -> Methods.DeleteMethod + 10, // 7: Methods.list:type_name -> Methods.ListMethod + 0, // 8: Property.type:type_name -> Type + 4, // 9: Resource.PropertiesEntry.value:type_name -> Property + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name } func init() { file_schema_resourcedefinition_proto_init() } @@ -599,7 +693,7 @@ func file_schema_resourcedefinition_proto_init() { return nil } } - file_schema_resourcedefinition_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Methods_CreateMethod); i { case 0: return &v.state @@ -611,7 +705,7 @@ func file_schema_resourcedefinition_proto_init() { return nil } } - file_schema_resourcedefinition_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Methods_ReadMethod); i { case 0: return &v.state @@ -623,7 +717,7 @@ func file_schema_resourcedefinition_proto_init() { return nil } } - file_schema_resourcedefinition_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Methods_UpdateMethod); i { case 0: return &v.state @@ -635,7 +729,7 @@ func file_schema_resourcedefinition_proto_init() { return nil } } - file_schema_resourcedefinition_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Methods_DeleteMethod); i { case 0: return &v.state @@ -647,7 +741,7 @@ func file_schema_resourcedefinition_proto_init() { return nil } } - file_schema_resourcedefinition_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_schema_resourcedefinition_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Methods_ListMethod); i { case 0: return &v.state @@ -665,13 +759,14 @@ func file_schema_resourcedefinition_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_schema_resourcedefinition_proto_rawDesc, - NumEnums: 0, - NumMessages: 9, + NumEnums: 1, + NumMessages: 10, NumExtensions: 0, NumServices: 0, }, GoTypes: file_schema_resourcedefinition_proto_goTypes, DependencyIndexes: file_schema_resourcedefinition_proto_depIdxs, + EnumInfos: file_schema_resourcedefinition_proto_enumTypes, MessageInfos: file_schema_resourcedefinition_proto_msgTypes, }.Build() File_schema_resourcedefinition_proto = out.File diff --git a/schema/resourcedefinition.proto b/schema/resourcedefinition.proto index bdd2f8b..5bb3a28 100644 --- a/schema/resourcedefinition.proto +++ b/schema/resourcedefinition.proto @@ -20,11 +20,10 @@ message Resource { string plural = 2; // The list of parent resources, referred to via the kind. repeated string parents = 3; - + // Properties + map properties = 4; // method support - Methods methods = 4; - // TODO figure out properties. - // map properties = 4; + Methods methods = 5; } message Methods { @@ -41,4 +40,14 @@ message Methods { ListMethod list = 5; } -message Property {} \ No newline at end of file +enum Type { + UNSPECIFIED = 0; + STRING = 1; +} + +message Property { + Type type = 1; + // field number used for protobuf or other systems where fields must + // be explicitly enumerated. + int32 number = 2; +} \ No newline at end of file diff --git a/writer/proto/resource.go b/writer/proto/resource.go index e27d4c3..f9b294d 100644 --- a/writer/proto/resource.go +++ b/writer/proto/resource.go @@ -18,6 +18,7 @@ import ( "strings" "github.com/aep-dev/aepc/parser" + "github.com/aep-dev/aepc/schema" "github.com/jhump/protoreflect/desc" "github.com/jhump/protoreflect/desc/builder" "google.golang.org/genproto/googleapis/api/annotations" @@ -70,9 +71,19 @@ func AddResource(r *parser.ParsedResource, fb *builder.FileBuilder, sb *builder. // GenerateResourceMesssage adds the resource message. func GeneratedResourceMessage(r *parser.ParsedResource) (*builder.MessageBuilder, error) { mb := builder.NewMessage(r.Kind) + // standard fields start at 10k, in the range until 11k. mb.AddField( - builder.NewField(FIELD_NAME_PATH, builder.FieldTypeString()).SetNumber(1), + builder.NewField(FIELD_NAME_PATH, builder.FieldTypeString()).SetNumber(10000), ) + // standard fields are added afterward. + for n, p := range r.Properties { + typ := builder.FieldTypeBool() + switch p.Type { + case schema.Type_STRING: + typ = builder.FieldTypeString() + } + mb.AddField(builder.NewField(n, typ).SetNumber(p.Number)) + } mb.SetOptions( &descriptorpb.MessageOptions{}, // annotations.ResourceDescriptor{