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

Fix: Keep original name of field #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tigh-latte
Copy link

@tigh-latte tigh-latte commented Jun 4, 2021

Currently, if I have the following .proto file:

// The request message containing the user's name.
message HelloRequest {
  string my_name = 1;
}

And the following stub:

{
    "service": "helloworld.Greeter",
    "method": "SayHello",
    "in": {
        "equals": {
            "my_name": "hi"
        }
    },
    "out": {
        "data": {
            "message": "lemon"
        }
    }
}

And I were to make the following request:

grpc -plaintext -d @ 0.0.0.0:22222 helloworld.Greeter/SayHello <<! | jq
{
	"my_name": "hi"
}
!

The mock server would fail to match the stub to the request, because once data is parsed into its internal map m, it's converted to camelCase and instead searches for "myName": "hi". The GRPC services I work with have snake cased fields, so when mocking, the the in's must be camel, and the outs must be snake.

I propose doing this, having a jsonpb marshaller which marshels the keynames down to the original name defined in the .proto file, to allow the above scenario to pass.

@tigh-latte tigh-latte changed the title Fix: Keep field keys original name Fix: Keep original name of field Jun 4, 2021
@theflyingcodr
Copy link

Hi, will this be merged?

@tigh-latte
Copy link
Author

I've another PR to open for this branch too to add header support @theflyingcodr , since the container you guys use has both of these changes implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants