Александр Иванов
11/06/2024, 3:06 PM"request": {
"method": "POST",
"urlPath": "myurl",
"bodyPatterns": [
{
"matchesJsonPath": "$.customer_id"
}
]
},Lee Turner
11/06/2024, 3:08 PMgRPC requests or is grps something specific?Александр Иванов
11/06/2024, 3:08 PMАлександр Иванов
11/06/2024, 3:12 PMgrpcurl -plaintext -d '{
"customer_id": "123"
}' \
-proto customer_service.proto \
localhost:8080 myurl/GetContactsLee Turner
11/06/2024, 3:16 PMequalToJson just to see if that works ? You will need to provide the whole request:
"bodyPatterns" : [{
"equalToJson" : "{ \"customer_id\": \"123\" }"
}]Александр Иванов
11/06/2024, 3:19 PM{
"request": {
"method": "POST",
"urlPath": "/myurl/GetContacts",
"bodyPatterns": [
{
"equalToJson": "{ \"customer_id\": \"123\" }"
}
]
},
"response": {
"status": 200,
"body": "{\"phone\": {\"contact_id\": 1, \"value\": \"<tel:123-456-7890|123-456-7890>\"}, \"phone_reserve\": {\"contact_id\": 2, \"value\": \"<tel:098-765-4321|098-765-4321>\"}, \"email\": {\"contact_id\": 3, \"value\": \"<mailto:example@example.com|example@example.com>\"}, \"email_reserve\": {\"contact_id\": 4, \"value\": \"<mailto:reserve@example.com|reserve@example.com>\"}}",
"transformers": [
"response-template"
]
}
}Lee Turner
11/06/2024, 3:21 PMАлександр Иванов
11/06/2024, 3:27 PMgrpcurl -plaintext -d '{
"customer_id": "123"
}' \
-proto customer_service.proto \
localhost:8080 myurl/GetContacts
{
"phone": {
"contactId": "1",
"value": "<tel:123-456-7890|123-456-7890>"
},
"phoneReserve": {
"contactId": "2",
"value": "<tel:098-765-4321|098-765-4321>"
},
"email": {
"contactId": "3",
"value": "<mailto:example@example.com|example@example.com>"
},
"emailReserve": {
"contactId": "4",
"value": "<mailto:reserve@example.com|reserve@example.com>"
}
}Lee Turner
11/06/2024, 3:52 PMLee Turner
11/06/2024, 3:55 PMАлександр Иванов
11/06/2024, 4:07 PMАлександр Иванов
11/06/2024, 4:07 PMLee Turner
11/06/2024, 4:15 PMLee Turner
11/06/2024, 4:15 PMGetContactsResponse defined?Александр Иванов
11/06/2024, 4:19 PMLee Turner
11/06/2024, 4:53 PMcustomer_id as an int64 but in your grpcurl request you are sending it as a string. Can you try making these consistent and try againАлександр Иванов
11/06/2024, 4:58 PMАлександр Иванов
11/06/2024, 5:00 PMАлександр Иванов
11/06/2024, 5:07 PMLee Turner
11/06/2024, 5:16 PMgrpcurl you can use - grpcurl -plaintext localhost:8080 listLee Turner
11/06/2024, 5:35 PMphone_reserve is changed to phoneReserve.
I think the same is happening when you add a body pattern matcher. It is changing the customer_id to customerId before doing the match. To get this to work you will need to update your matcher:
"bodyPatterns": [
{
"equalToJson" : "{ \"customerId\": 123 }"
}
]Lee Turner
11/06/2024, 5:42 PMLee Turner
11/06/2024, 6:01 PMprotoc compiler that is performing this switch so when WireMock reads the descriptor file it generates json in camel case which makes matching problematic if you specify the non camel case json.
In my simple example I have running locally I have added these json_name items to each field and that now works as expected.
syntax = "proto3";
package myUrl;
message GetContactsRequest {
int32 customer_id = 1 [json_name = "customer_id"];
}
message GetContactsResponse {
ContactDetails phone = 1 [json_name = "phone"];
ContactDetails phone_reserve = 2 [json_name = "phone_reserve"];
ContactDetails email = 3 [json_name = "email"];
ContactDetails email_reserve = 4 [json_name = "email_reserve"];
}
message ContactDetails {
string contact_id = 1 [json_name = "contact_id"];
string value = 2 [json_name = "value"];
}
service ContactsService {
rpc getContacts(GetContactsRequest) returns (GetContactsResponse);
}Lee Turner
11/06/2024, 6:02 PMequalsToJson matcher and it seems to be working as expected.Александр Иванов
11/06/2024, 8:32 PMLee Turner
11/06/2024, 9:02 PMLee Turner
11/06/2024, 9:02 PM