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

protoc-gen-openapiv2: Fix so that FieldMasks descriptions are correctly generated #1558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/internal/clients/abe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ go_library(
"model_nested_deep_enum.go",
"model_pathenum_path_enum.go",
"model_protobuf_any.go",
"model_protobuf_field_mask.go",
"model_rpc_status.go",
"model_sub_string_message.go",
"response.go",
Expand Down
100 changes: 10 additions & 90 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1838,15 +1838,15 @@ paths:
schema:
$ref: "#/definitions/examplepbABitOfEverything"
x-exportParamName: "Body"
- name: "updateMask.paths"
- name: "updateMask"
in: "query"
description: "The set of field mask paths."
description: "The paths to update."
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
x-exportParamName: "UpdateMaskPaths"
x-exportParamName: "UpdateMask"
responses:
200:
description: "A successful response."
Expand Down Expand Up @@ -1884,15 +1884,15 @@ paths:
schema:
$ref: "#/definitions/examplepbABitOfEverything"
x-exportParamName: "Body"
- name: "updateMask.paths"
- name: "updateMask"
in: "query"
description: "The set of field mask paths."
description: "The paths to update."
required: false
type: "array"
items:
type: "string"
collectionFormat: "multi"
x-exportParamName: "UpdateMaskPaths"
x-exportParamName: "UpdateMask"
responses:
200:
description: "A successful response."
Expand Down Expand Up @@ -2551,7 +2551,10 @@ definitions:
abe:
$ref: "#/definitions/examplepbABitOfEverything"
updateMask:
$ref: "#/definitions/protobufFieldMask"
type: "array"
description: "The paths to update."
items:
type: "string"
title: "UpdateV2Request request for update includes the message and the update\
\ mask"
pathenumPathEnum:
Expand Down Expand Up @@ -2618,89 +2621,6 @@ definitions:
\ custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\
\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n\
\ \"value\": \"1.212s\"\n }"
protobufFieldMask:
type: "object"
properties:
paths:
type: "array"
description: "The set of field mask paths."
items:
type: "string"
title: "`FieldMask` represents a set of symbolic field paths, for example:"
description: "paths: \"f.a\"\n paths: \"f.b.d\"\n\nHere `f` represents a field\
\ in some root message, `a` and `b`\nfields in the message found in `f`, and\
\ `d` a field found in the\nmessage in `f.b`.\n\nField masks are used to specify\
\ a subset of fields that should be\nreturned by a get operation or modified\
\ by an update operation.\nField masks also have a custom JSON encoding (see\
\ below).\n\n# Field Masks in Projections\n\nWhen used in the context of a projection,\
\ a response message or\nsub-message is filtered by the API to only contain\
\ those fields as\nspecified in the mask. For example, if the mask in the previous\n\
example is applied to a response message as follows:\n\n f {\n a : 22\n\
\ b {\n d : 1\n x : 2\n }\n y : 13\n }\n \
\ z: 8\n\nThe result will not contain specific values for fields x,y and z\n\
(their value will be set to the default, and omitted in proto text\noutput):\n\
\n\n f {\n a : 22\n b {\n d : 1\n }\n }\n\nA repeated\
\ field is not allowed except at the last position of a\npaths string.\n\nIf\
\ a FieldMask object is not present in a get operation, the\noperation applies\
\ to all fields (as if a FieldMask of all fields\nhad been specified).\n\nNote\
\ that a field mask does not necessarily apply to the\ntop-level response message.\
\ In case of a REST get operation, the\nfield mask applies directly to the response,\
\ but in case of a REST\nlist operation, the mask instead applies to each individual\
\ message\nin the returned resource list. In case of a REST custom method,\n\
other definitions may be used. Where the mask applies will be\nclearly documented\
\ together with its declaration in the API. In\nany case, the effect on the\
\ returned resource/resources is required\nbehavior for APIs.\n\n# Field Masks\
\ in Update Operations\n\nA field mask in update operations specifies which\
\ fields of the\ntargeted resource are going to be updated. The API is required\n\
to only change the values of the fields as specified in the mask\nand leave\
\ the others untouched. If a resource is passed in to\ndescribe the updated\
\ values, the API ignores the values of all\nfields not covered by the mask.\n\
\nIf a repeated field is specified for an update operation, new values will\n\
be appended to the existing repeated field in the target resource. Note that\n\
a repeated field is only allowed in the last position of a `paths` string.\n\
\nIf a sub-message is specified in the last position of the field mask for an\n\
update operation, then new value will be merged into the existing sub-message\n\
in the target resource.\n\nFor example, given the target message:\n\n f {\n\
\ b {\n d: 1\n x: 2\n }\n c: [1]\n }\n\nAnd\
\ an update message:\n\n f {\n b {\n d: 10\n }\n c:\
\ [2]\n }\n\nthen if the field mask is:\n\n paths: [\"f.b\", \"f.c\"]\n\n\
then the result will be:\n\n f {\n b {\n d: 10\n x: 2\n\
\ }\n c: [1, 2]\n }\n\nAn implementation may provide options to\
\ override this default behavior for\nrepeated and message fields.\n\nIn order\
\ to reset a field's value to the default, the field must\nbe in the mask and\
\ set to the default value in the provided resource.\nHence, in order to reset\
\ all fields of a resource, provide a default\ninstance of the resource and\
\ set all fields in the mask, or do\nnot provide a mask as described below.\n\
\nIf a field mask is not present on update, the operation applies to\nall fields\
\ (as if a field mask of all fields has been specified).\nNote that in the presence\
\ of schema evolution, this may mean that\nfields the client does not know and\
\ has therefore not filled into\nthe request will be reset to their default.\
\ If this is unwanted\nbehavior, a specific service may require a client to\
\ always specify\na field mask, producing an error if not.\n\nAs with get operations,\
\ the location of the resource which\ndescribes the updated values in the request\
\ message depends on the\noperation kind. In any case, the effect of the field\
\ mask is\nrequired to be honored by the API.\n\n## Considerations for HTTP\
\ REST\n\nThe HTTP kind of an update operation which uses a field mask must\n\
be set to PATCH instead of PUT in order to satisfy HTTP semantics\n(PUT must\
\ only be used for full updates).\n\n# JSON Encoding of Field Masks\n\nIn JSON,\
\ a field mask is encoded as a single string where paths are\nseparated by a\
\ comma. Fields name in each path are converted\nto/from lower-camel naming\
\ conventions.\n\nAs an example, consider the following message declarations:\n\
\n message Profile {\n User user = 1;\n Photo photo = 2;\n }\n\
\ message User {\n string display_name = 1;\n string address =\
\ 2;\n }\n\nIn proto a field mask for `Profile` may look as such:\n\n \
\ mask {\n paths: \"user.display_name\"\n paths: \"photo\"\n }\n\
\nIn JSON, the same mask is represented as below:\n\n {\n mask: \"user.displayName,photo\"\
\n }\n\n# Field Masks and Oneof Fields\n\nField masks treat fields in oneofs\
\ just as regular fields. Consider the\nfollowing message:\n\n message SampleMessage\
\ {\n oneof test_oneof {\n string name = 4;\n SubMessage\
\ sub_message = 9;\n }\n }\n\nThe field mask can be:\n\n mask {\n\
\ paths: \"name\"\n }\n\nOr:\n\n mask {\n paths: \"sub_message\"\
\n }\n\nNote that oneof type names (\"test_oneof\" in this case) cannot be\
\ used in\npaths.\n\n## Field Mask Verification\n\nThe implementation of any\
\ API method which has a FieldMask type field in the\nrequest should verify\
\ the included field paths, and return an\n`INVALID_ARGUMENT` error if any path\
\ is unmappable."
rpcStatus:
type: "object"
properties:
Expand Down
16 changes: 8 additions & 8 deletions examples/internal/clients/abe/api_a_bit_of_everything_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3266,13 +3266,13 @@ ABitOfEverythingServiceApiService
* @param abeUuid
* @param body
* @param optional nil or *ABitOfEverythingServiceUpdateV2Opts - Optional Parameters:
* @param "UpdateMaskPaths" (optional.Interface of []string) - The set of field mask paths.
* @param "UpdateMask" (optional.Interface of []string) - The paths to update.

@return interface{}
*/

type ABitOfEverythingServiceUpdateV2Opts struct {
UpdateMaskPaths optional.Interface
UpdateMask optional.Interface
}

func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV2(ctx context.Context, abeUuid string, body ExamplepbABitOfEverything, localVarOptionals *ABitOfEverythingServiceUpdateV2Opts) (interface{}, *http.Response, error) {
Expand All @@ -3292,8 +3292,8 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV2(ctx
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}

if localVarOptionals != nil && localVarOptionals.UpdateMaskPaths.IsSet() {
localVarQueryParams.Add("updateMask.paths", parameterToString(localVarOptionals.UpdateMaskPaths.Value(), "multi"))
if localVarOptionals != nil && localVarOptionals.UpdateMask.IsSet() {
localVarQueryParams.Add("updateMask", parameterToString(localVarOptionals.UpdateMask.Value(), "multi"))
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json", "application/x-foo-mime"}
Expand Down Expand Up @@ -3424,13 +3424,13 @@ ABitOfEverythingServiceApiService
* @param abeUuid
* @param body
* @param optional nil or *ABitOfEverythingServiceUpdateV22Opts - Optional Parameters:
* @param "UpdateMaskPaths" (optional.Interface of []string) - The set of field mask paths.
* @param "UpdateMask" (optional.Interface of []string) - The paths to update.

@return interface{}
*/

type ABitOfEverythingServiceUpdateV22Opts struct {
UpdateMaskPaths optional.Interface
UpdateMask optional.Interface
}

func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV22(ctx context.Context, abeUuid string, body ExamplepbABitOfEverything, localVarOptionals *ABitOfEverythingServiceUpdateV22Opts) (interface{}, *http.Response, error) {
Expand All @@ -3450,8 +3450,8 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceUpdateV22(ctx
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}

if localVarOptionals != nil && localVarOptionals.UpdateMaskPaths.IsSet() {
localVarQueryParams.Add("updateMask.paths", parameterToString(localVarOptionals.UpdateMaskPaths.Value(), "multi"))
if localVarOptionals != nil && localVarOptionals.UpdateMask.IsSet() {
localVarQueryParams.Add("updateMask", parameterToString(localVarOptionals.UpdateMask.Value(), "multi"))
}
// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json", "application/x-foo-mime"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ package abe

type ExamplepbUpdateV2Request struct {
Abe *ExamplepbABitOfEverything `json:"abe,omitempty"`
UpdateMask *ProtobufFieldMask `json:"updateMask,omitempty"`
// The paths to update.
UpdateMask []string `json:"updateMask,omitempty"`
}
17 changes: 0 additions & 17 deletions examples/internal/clients/abe/model_protobuf_field_mask.go

This file was deleted.

3 changes: 2 additions & 1 deletion examples/internal/proto/examplepb/a_bit_of_everything.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ enum NumericEnum {
// UpdateV2Request request for update includes the message and the update mask
message UpdateV2Request {
ABitOfEverything abe = 1;
// The paths to update.
google.protobuf.FieldMask update_mask = 2;
}

Expand Down
Loading