grpc-gateway
grpc-gateway copied to clipboard
Items type for google.protobuf.ListValue
🐛 Bug Report
If we use google.protobuf.ListValue, the generated swagger spec specifies items type as object:
"listvalueField": {
"type": "array",
"items": {
"type": "object"
}
},
Swagger-ui considers it an error, if we pass an array, e.g. of strings:
propKeysystemTagserrorindex0errorParameter string value must be valid JSON
The generated json spec contains:
"listvalueField": {
"type": "array",
"items": {
"type": "object"
}
},
To Reproduce
- Create a proto file:
syntax = "proto3";
package my_service;
option go_package = "./pb";
import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
message UpdateItem {
message Request {
google.protobuf.ListValue listvalue_field = 1;
}
}
service MyService {
rpc UpdateA(UpdateA.Request) returns (google.protobuf.Empty) {
option (google.api.http) = {
patch: "/v1/item"
body: "*"
};
}
- Generate swagger spec with protoc.
Expected behavior
There should be a choice to specify the type for items.
Actual Behavior
The items type is taken from wktSchemas: https://github.com/grpc-ecosystem/grpc-gateway/blob/v2.16.0/protoc-gen-openapiv2/internal/genopenapi/template.go#L98-L104
Your Environment
OSX Ventura 13.4.1, Go 1.20, [email protected]
I might be misunderstanding, but the schema for ListValue is based on the defined JSON representation, which states that it is a JSON array. Theoretically, it could be an array of any JSON value, but because we don't know, we choose the most generic one, object. We have to choose something, so what do you suggest? There's no option to specify a specific type (if you want an array of strings, use repeated string value = 1
).
@skunkie recently I made it possible to specify format of items
https://github.com/grpc-ecosystem/grpc-gateway/issues/3403
I might be misunderstanding, but the schema for ListValue is based on the defined JSON representation, which states that it is a JSON array. Theoretically, it could be an array of any JSON value, but because we don't know, we choose the most generic one, object. We have to choose something, so what do you suggest? There's no option to specify a specific type (if you want an array of strings, use
repeated string value = 1
).
ListValue helps distinguish between nil (the JSON key is not passed) and an empty array (the JSON key is passed with an empty content), while repeated string value = 1
always returns nil.
As for the option, we could add it to JSONSchema.
@skunkie recently I made it possible to specify format of items
#3403
Does it make sense for uuid format only?
@johanbrandhorst, @far4599 any updates or comments?