Ballerina-lang: Annotation support for Struct fields

Created on 11 Jan 2018  ·  5Comments  ·  Source: ballerina-platform/ballerina-lang

Description:
Ballerina grammar doesn't support defining annotation for struct fields like below,
bal struct HelloResponse { @grpc:protobuf(fieldType="string”,index=1,name=”message") string message; }
When we are defining custom types using structs, we may need to define additional properties for the field.
e.g: when we define grpc service in ballerina, we need to define field index in message type. If Ballerina supports field annotation, we can define field index as an annotation.

Steps to reproduce:
This is an improvement.

Affected Versions:
N/A

OS, DB, other environment details and versions:

Related Issues (optional):

4349

Suggested Labels (optional):
improvement

Suggested Assignees (optional):
@hasithaa

TeaCompilerFE TypImprovement

Most helpful comment

@daneshk @wggihan @pamod
Do we need to support this for both records and objects. ? Either case, this is deviating from Ballerina-Language-Specification-WD-2018-07-12. Shall we discuss this in the dev group?

All 5 comments

I just ran into this, and I would qualify this as higher precedence than improvement. This is a compatibility-breaking feature.

For example:
I created a record with 4 fields, which then generates a protobuf file. Another team in my org is now using that protobuf file to build their service. Both our services go to production.
Now, I add a field to my record but I add it _above_ the other fields. This will actually _renumber_ the protobuf field indexes below the newly added field. This will _break_ all clients. It's far too easy for someone to accidentally break compatibility without knowing it because of the implicit magic happening from the record structure to protobuf conversion.

This also goes to adoption. You're not going to get people to buy into your automagic code-first protobuf generation if it's this easy to accidentally break the contract between service and client.

@autodidaddict Totally agreed with your point. We are also looking to support contract first approach where we define the proto contract first and generate service skeleton. So that we can support backward compatibility. I started discussion [1] in google group. and created separate ticket #8954 to address it.

  1. https://groups.google.com/forum/#!topic/ballerina-dev/FYJf6zhKtmA

@daneshk @wggihan @pamod
Do we need to support this for both records and objects. ? Either case, this is deviating from Ballerina-Language-Specification-WD-2018-07-12. Shall we discuss this in the dev group?

This was fixed in #21529. Hence closing this.

Was this page helpful?
0 / 5 - 0 ratings