-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
openapiv2: Field options are not properly rendered for repeated fields #2531
Comments
Hi! I went and looked at the OpenAPIv2 spec and it seems you can specify the field properties both at the top level and inside the The easiest way to get started would be to add a new test to https://github.com/grpc-ecosystem/grpc-gateway/blob/master/protoc-gen-openapiv2/internal/genopenapi/template_test.go that would have the expected behavior. Having had a quick glance at the code, I think you'll need to make the changes here:
|
/assign @johanbrandhorst i am willing to contribute on this kindly assign it to me |
Hi @lakshkeswani, please have at it! |
We're dealing with similar issue. Our proto file: import "google/protobuf/field_mask.proto";
message SomeMessage {
google.protobuf.FieldMask update_mask = 10;
} (Here's the definition of FieldMask:) // google/protobuf/field_mask.proto
message FieldMask {
// The set of field mask paths.
repeated string paths = 1;
} is generated into openapiv2 spec as: "parameters": [
{
"name": "updateMask",
"in": "query",
"type": "string"
}
] The issue is that FieldMask should be generated into OpenAPI as a |
This sounds like a separate issue, could you create a separate issue and share your RPC definition too please? |
@johanbrandhorst I have created a separate issue #2580 with reproducible example. |
(#2742) * added product_id * updated updateswaggerObjectFromJSONSchema to resolve issue #2531 * added test cases in schemaoffield for issue #2531 * updated openapiItemsObject type to openapiSchemaObject for issue #2531 * genrated files after adding product id * updates * formated file * regenrated files * formated the file * Update examples/internal/proto/examplepb/a_bit_of_everything.proto Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> * regenrated files Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This change prevents setting
|
I'm not sure what you're asking exactly? I'm not an expert on the OpenAPI spec. Do you have an example protobuf file you're using? |
Let's use the same proto definition as an example: message Order {
repeated string product_ids = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
max_length: 10
}];
} Suppose we have an order containing multiple product IDs. We want to limit the maximum number of product IDs to 10. I initially thought the above annotation would achieve this, but based on the changes mentioned in the issue, it appears that this annotation actually limits the length of each product ID string (e.g., "PROD123") to 10 characters, not the total number of product IDs to 10. Is this interpretation correct? If so, could you please advise on how to limit the number of items in a repeated field in the OpenAPI v2 specification? |
I believe your interpretation is right. To my knowledge there is no way to do what you want with OpenAPI. Perhaps you want something like https://github.com/bufbuild/protoc-gen-validate? |
OpenAPI supports it. It's called "minItems" and "maxItems". See https://stackoverflow.com/questions/57035988/how-to-limit-my-swagger-definition-array-to-be-either-0-or-3 for example. However, there's no way that we can generate |
I need to generate swagger json using proto annotations.
generated schema should look like this
and the annotation added was something like this
But the problem is above annotation is generating schema like this
which is not correct. We could not find the relevant example in a_bit_of_everything.proto.
Please help in adding the annotations.
The text was updated successfully, but these errors were encountered: