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

Items type for google.protobuf.ListValue #3414

Open
skunkie opened this issue Jul 21, 2023 · 5 comments
Open

Items type for google.protobuf.ListValue #3414

skunkie opened this issue Jul 21, 2023 · 5 comments

Comments

@skunkie
Copy link

skunkie commented Jul 21, 2023

🐛 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

  1. 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: "*"
    };
}
  1. 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]

@johanbrandhorst
Copy link
Collaborator

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).

@far4599
Copy link
Contributor

far4599 commented Jul 23, 2023

@skunkie recently I made it possible to specify format of items

#3403

@skunkie
Copy link
Author

skunkie commented Jul 24, 2023

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
Copy link
Author

skunkie commented Jul 24, 2023

@skunkie recently I made it possible to specify format of items

#3403

Does it make sense for uuid format only?

@skunkie
Copy link
Author

skunkie commented Aug 15, 2023

@johanbrandhorst, @far4599 any updates or comments?

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

No branches or pull requests

3 participants