Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect stub generated for message with Any type field in gRPC tool #2750

Closed
madhukaw opened this issue Mar 1, 2022 · 6 comments · Fixed by ballerina-platform/module-ballerina-grpc#739
Assignees
Labels
module/grpc Points/1 Team/PCM Protocol connector packages related issues Type/Bug

Comments

@madhukaw
Copy link
Contributor

madhukaw commented Mar 1, 2022

Description:
Try to build the stub file for the following proto definition.

syntax = "proto3";

import "google/protobuf/any.proto";

message AnyTypeRequest {
    string name = 1;
    google.protobuf.Any details = 2;
};

The following is the generated stub file.

public type AnyTypeRequest record {|
    string name = "";
    'any:Any details = ();
|};

const string ROOT_DESCRIPTOR_ANY2 = "0A0A616E79322E70726F746F1A19676F6F676C652F70726F746F6275662F616E792E70726F746F22540A0E416E79547970655265717565737412120A046E616D6518012001280952046E616D65122E0A0764657461696C7318022001280B32142E676F6F676C652E70726F746F6275662E416E79520764657461696C73620670726F746F33";

public isolated function getDescriptorMapAny2() returns map<string> {
    return {"any2.proto": "0A0A616E79322E70726F746F1A19676F6F676C652F70726F746F6275662F616E792E70726F746F22540A0E416E79547970655265717565737412120A046E616D6518012001280952046E616D65122E0A0764657461696C7318022001280B32142E676F6F676C652E70726F746F6275662E416E79520764657461696C73620670726F746F33", "google/protobuf/any.proto": "0A19676F6F676C652F70726F746F6275662F616E792E70726F746F120F676F6F676C652E70726F746F62756622360A03416E7912190A08747970655F75726C18012001280952077479706555726C12140A0576616C756518022001280C520576616C7565424F0A13636F6D2E676F6F676C652E70726F746F6275664208416E7950726F746F50015A057479706573A20203475042AA021E476F6F676C652E50726F746F6275662E57656C6C4B6E6F776E5479706573620670726F746F33"};
}

There are 2 issues here.

  1. The ballerina/protobuf.types.'any import is missing.
  2. The AnyTypeRequest record definition throws a compilation error: ERROR [sample.bal:(9:24,9:26)] incompatible types: expected 'ballerina/protobuf.types.any:1.2.0:Any', found '()'

Affected Versions:
SLGA

@madhukaw
Copy link
Contributor Author

madhukaw commented Mar 1, 2022

IMO, the default value in the record should be changed as follows according to the Any type definition[1].

public type AnyTypeArrayRequest record {|
    string name = "";
    'any:Any details = {typeUrl: "", value: ()};
|};

[1] https://github.com/ballerina-platform/module-ballerina-protobuf/blob/main/ballerina/modules/types.any/any.bal#L37

@BuddhiWathsala @daneshk WDYT

@daneshk
Copy link
Member

daneshk commented Mar 1, 2022

Just thinking, if we can set default values when defining the Any type record in the protobuf module. Here we can just say

public type Any record {|
    string typeUrl = "";
    ValueType value = ();
|};
public type AnyTypeArrayRequest record {|
    string name = "";
    'any:Any details = {};
|};

@madhukaw
Copy link
Contributor Author

madhukaw commented Mar 1, 2022

Just thinking, if we can set default values when defining the Any type record in the protobuf module. Here we can just say

public type Any record {|
    string typeUrl = "";
    ValueType value = ();
|};
public type AnyTypeArrayRequest record {|
    string name = "";
    'any:Any details = {};
|};

+1, That would be better.

@BuddhiWathsala
Copy link
Contributor

Yes, that approach is much cleaner.

@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@madhukaw
Copy link
Contributor Author

madhukaw commented Mar 16, 2022

Closed since this task is completed in ballerina-platform/module-ballerina-grpc#739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/grpc Points/1 Team/PCM Protocol connector packages related issues Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants