I'm sending the following POST request to my gRPC application:
curl \
--request POST \
--header 'Content-Type: application/json' \
--data-raw '{
"mandatory-key1": "value1",
"mandatory-key2": {
"arbitrary-optional-key1": [
"b",
"c"
],
"arbitrary-optional-key2": [
"e"
]
}
}' \
'http://localhost:11000/MyEndpoint'
The value associated with mandatory-key-1
must be a non-empty string.
The value associated with mandatory-key-2
must be a map where all keys are strings and all values are lists of strings.
Now I have to model this request's data structure in the gRPC proto file.
I am thinking of doing something like this:
message MyRequestData {
// pairs represents that map that the user will send in to the MyEndpoint.
map<string, string> pairs = 1;
}
But this specification is not general enough. I need to know how to write this specification correctly.
Question 1: How can I write this specification so it accepts strings in the values and also lists of strings?
Question 2: How can I do validation such that I ensure pairs
has keys mandatory-key1
and mandatory-key2
and nothing else?
Question 3: How can I do validation such that I ensure:
pairs
has keysmandatory-key1
andmandatory-key2
and nothing else?pairs[mandatory-key1"]
has value which is a non-empty string?pairs["mandatory-key2"]
has value which is a map of <strings, list of non-empty strings>?