diff --git a/template.go b/template.go index 9edaac7..6d64740 100644 --- a/template.go +++ b/template.go @@ -38,6 +38,7 @@ func NewTemplate(descs []*protokit.FileDescriptor) *Template { Messages: make(orderedMessages, 0, len(f.Messages)), Services: make(orderedServices, 0, len(f.Services)), Options: mergeOptions(extractOptions(f.GetOptions()), extensions.Transform(f.OptionExtensions)), + Syntax: f.GetSyntax(), } for _, e := range f.Enums { @@ -141,6 +142,8 @@ type File struct { Services orderedServices `json:"services"` Options map[string]interface{} `json:"options,omitempty"` + + Syntax string `json:"syntax,omitempty"` } // Option returns the named option. @@ -236,6 +239,8 @@ type MessageField struct { DefaultValue string `json:"defaultValue"` Options map[string]interface{} `json:"options,omitempty"` + + Number int `json:"number,omitempty"` } // Option returns the named option. @@ -482,6 +487,7 @@ func parseMessageField(pf *protokit.FieldDescriptor, oneofDecls []*descriptor.On DefaultValue: pf.GetDefaultValue(), Options: mergeOptions(extractOptions(pf.GetOptions()), extensions.Transform(pf.OptionExtensions)), IsOneof: pf.OneofIndex != nil, + Number: int(pf.GetNumber()), } if m.IsOneof { diff --git a/template_test.go b/template_test.go index 717919b..b2a67f7 100644 --- a/template_test.go +++ b/template_test.go @@ -138,6 +138,7 @@ func TestFileProperties(t *testing.T) { require.True(t, bookingFile.HasServices) require.NotEmpty(t, bookingFile.Options) require.True(t, *bookingFile.Option(E_ExtendFile.Name).(*bool)) + require.Equal(t, "", bookingFile.Syntax) } func TestFileEnumProperties(t *testing.T) { @@ -254,6 +255,7 @@ func TestFieldProperties(t *testing.T) { require.False(t, field.IsOneof) require.NotEmpty(t, field.Options) require.True(t, *field.Option(E_ExtendField.Name).(*bool)) + require.Equal(t, 1, field.Number) field = findField("status_code", msg) require.Equal(t, "status_code", field.Name) @@ -264,6 +266,7 @@ func TestFieldProperties(t *testing.T) { require.Equal(t, "com.example.BookingStatus.StatusCode", field.FullType) require.Empty(t, field.DefaultValue) require.False(t, field.IsOneof) + require.Equal(t, 3, field.Number) field = findField("category", findMessage("Vehicle", vehicleFile)) require.Equal(t, "category", field.Name) @@ -274,6 +277,7 @@ func TestFieldProperties(t *testing.T) { require.Equal(t, "com.example.Vehicle.Category", field.FullType) require.Empty(t, field.DefaultValue) require.False(t, field.IsOneof) + require.Equal(t, 5, field.Number) field = findField("properties", findMessage("Vehicle", vehicleFile)) require.Equal(t, "properties", field.Name) @@ -284,6 +288,7 @@ func TestFieldProperties(t *testing.T) { require.Empty(t, field.DefaultValue) require.True(t, field.IsMap) require.False(t, field.IsOneof) + require.Equal(t, 7, field.Number) field = findField("rates", findMessage("Vehicle", vehicleFile)) require.Equal(t, "rates", field.Name) @@ -293,6 +298,7 @@ func TestFieldProperties(t *testing.T) { require.Equal(t, "sint32", field.FullType) require.False(t, field.IsMap) require.False(t, field.IsOneof) + require.Equal(t, 6, field.Number) field = findField("kilometers", findMessage("Vehicle", vehicleFile)) require.Equal(t, "kilometers", field.Name) @@ -303,6 +309,7 @@ func TestFieldProperties(t *testing.T) { require.False(t, field.IsMap) require.True(t, field.IsOneof) require.Equal(t, "travel", field.OneofDecl) + require.Equal(t, 8, field.Number) field = findField("human_name", findMessage("Vehicle", vehicleFile)) require.Equal(t, "human_name", field.Name) @@ -313,6 +320,7 @@ func TestFieldProperties(t *testing.T) { require.False(t, field.IsMap) require.True(t, field.IsOneof) require.Equal(t, "drivers", field.OneofDecl) + require.Equal(t, 11, field.Number) } func TestFieldPropertiesProto3(t *testing.T) { @@ -327,6 +335,7 @@ func TestFieldPropertiesProto3(t *testing.T) { require.Equal(t, "string", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 1, field.Number) field = findField("model_code", msg) require.Equal(t, "model_code", field.Name) @@ -337,6 +346,7 @@ func TestFieldPropertiesProto3(t *testing.T) { require.Equal(t, "string", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 2, field.Number) field = findField("daily_hire_rate_dollars", msg) require.Equal(t, "daily_hire_rate_dollars", field.Name) @@ -347,6 +357,7 @@ func TestFieldPropertiesProto3(t *testing.T) { require.Equal(t, "sint32", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 4, field.Number) } func TestFieldPropertiesProto3Optional(t *testing.T) { @@ -361,6 +372,7 @@ func TestFieldPropertiesProto3Optional(t *testing.T) { require.Equal(t, "string", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 1, field.Number) field = findField("name", msg) require.Equal(t, "name", field.Name) @@ -371,6 +383,7 @@ func TestFieldPropertiesProto3Optional(t *testing.T) { require.Equal(t, "string", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 2, field.Number) field = findField("ingredients", msg) require.Equal(t, "ingredients", field.Name) @@ -381,6 +394,7 @@ func TestFieldPropertiesProto3Optional(t *testing.T) { require.Equal(t, "string", field.FullType) require.Empty(t, field.DefaultValue) require.Empty(t, field.Options) + require.Equal(t, 3, field.Number) } func TestServiceProperties(t *testing.T) {