Skip to content

Commit 2b6cab6

Browse files
bmperreajohanbrandhorst
authored andcommitted
Use collectionFormat multi for query params of repeated fields (#902)
* Use collectionFormat multi for query params of repeated fields Fixes #756 . Also formats protoc-gen-swagger/genswagger/template_test.go according to go fmt.
1 parent 9bb0d96 commit 2b6cab6

File tree

7 files changed

+147
-90
lines changed

7 files changed

+147
-90
lines changed

examples/clients/abe/a_bit_of_everything_service_api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,20 @@ func (a ABitOfEverythingServiceApi) GetQuery(uuid string, floatValue float32, si
595595
localVarQueryParams.Add("sfixed64_value", a.Configuration.APIClient.ParameterToString(sfixed64Value, ""))
596596
localVarQueryParams.Add("sint32_value", a.Configuration.APIClient.ParameterToString(sint32Value, ""))
597597
localVarQueryParams.Add("sint64_value", a.Configuration.APIClient.ParameterToString(sint64Value, ""))
598-
var repeatedStringValueCollectionFormat = "csv"
598+
var repeatedStringValueCollectionFormat = "multi"
599599
localVarQueryParams.Add("repeated_string_value", a.Configuration.APIClient.ParameterToString(repeatedStringValue, repeatedStringValueCollectionFormat))
600600

601601
localVarQueryParams.Add("oneof_string", a.Configuration.APIClient.ParameterToString(oneofString, ""))
602602
localVarQueryParams.Add("nonConventionalNameValue", a.Configuration.APIClient.ParameterToString(nonConventionalNameValue, ""))
603603
localVarQueryParams.Add("timestamp_value", a.Configuration.APIClient.ParameterToString(timestampValue, ""))
604-
var repeatedEnumValueCollectionFormat = "csv"
604+
var repeatedEnumValueCollectionFormat = "multi"
605605
localVarQueryParams.Add("repeated_enum_value", a.Configuration.APIClient.ParameterToString(repeatedEnumValue, repeatedEnumValueCollectionFormat))
606606

607-
var repeatedEnumAnnotationCollectionFormat = "csv"
607+
var repeatedEnumAnnotationCollectionFormat = "multi"
608608
localVarQueryParams.Add("repeated_enum_annotation", a.Configuration.APIClient.ParameterToString(repeatedEnumAnnotation, repeatedEnumAnnotationCollectionFormat))
609609

610610
localVarQueryParams.Add("enum_value_annotation", a.Configuration.APIClient.ParameterToString(enumValueAnnotation, ""))
611-
var repeatedStringAnnotationCollectionFormat = "csv"
611+
var repeatedStringAnnotationCollectionFormat = "multi"
612612
localVarQueryParams.Add("repeated_string_annotation", a.Configuration.APIClient.ParameterToString(repeatedStringAnnotation, repeatedStringAnnotationCollectionFormat))
613613

614614
localVarQueryParams.Add("nested_annotation.name", a.Configuration.APIClient.ParameterToString(nestedAnnotationName, ""))

examples/proto/examplepb/a_bit_of_everything.swagger.json

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@
328328
"type": "array",
329329
"items": {
330330
"type": "string"
331-
}
331+
},
332+
"collectionFormat": "multi"
332333
},
333334
{
334335
"name": "oneof_string",
@@ -361,7 +362,8 @@
361362
"ZERO",
362363
"ONE"
363364
]
364-
}
365+
},
366+
"collectionFormat": "multi"
365367
},
366368
{
367369
"name": "repeated_enum_annotation",
@@ -375,7 +377,8 @@
375377
"ZERO",
376378
"ONE"
377379
]
378-
}
380+
},
381+
"collectionFormat": "multi"
379382
},
380383
{
381384
"name": "enum_value_annotation",
@@ -397,7 +400,8 @@
397400
"type": "array",
398401
"items": {
399402
"type": "string"
400-
}
403+
},
404+
"collectionFormat": "multi"
401405
},
402406
{
403407
"name": "nested_annotation.name",
@@ -1526,7 +1530,8 @@
15261530
"type": "array",
15271531
"items": {
15281532
"$ref": "#/definitions/ABitOfEverythingNested"
1529-
}
1533+
},
1534+
"collectionFormat": "multi"
15301535
},
15311536
"float_value": {
15321537
"type": "number",
@@ -1605,7 +1610,8 @@
16051610
"type": "array",
16061611
"items": {
16071612
"type": "string"
1608-
}
1613+
},
1614+
"collectionFormat": "multi"
16091615
},
16101616
"oneof_empty": {
16111617
"properties": {}
@@ -1643,15 +1649,17 @@
16431649
"items": {
16441650
"$ref": "#/definitions/examplepbNumericEnum"
16451651
},
1646-
"title": "repeated enum value. it is comma-separated in query"
1652+
"title": "repeated enum value. it is comma-separated in query",
1653+
"collectionFormat": "multi"
16471654
},
16481655
"repeated_enum_annotation": {
16491656
"type": "array",
16501657
"items": {
16511658
"$ref": "#/definitions/examplepbNumericEnum"
16521659
},
16531660
"description": "Repeated numeric enum description.",
1654-
"title": "Repeated numeric enum title"
1661+
"title": "Repeated numeric enum title",
1662+
"collectionFormat": "multi"
16551663
},
16561664
"enum_value_annotation": {
16571665
"$ref": "#/definitions/examplepbNumericEnum",
@@ -1664,15 +1672,17 @@
16641672
"type": "string"
16651673
},
16661674
"description": "Repeated string description.",
1667-
"title": "Repeated string title"
1675+
"title": "Repeated string title",
1676+
"collectionFormat": "multi"
16681677
},
16691678
"repeated_nested_annotation": {
16701679
"type": "array",
16711680
"items": {
16721681
"$ref": "#/definitions/ABitOfEverythingNested"
16731682
},
16741683
"description": "Repeated nested object description.",
1675-
"title": "Repeated nested object title"
1684+
"title": "Repeated nested object title",
1685+
"collectionFormat": "multi"
16761686
},
16771687
"nested_annotation": {
16781688
"$ref": "#/definitions/ABitOfEverythingNested",
@@ -1714,110 +1724,126 @@
17141724
"type": "number",
17151725
"format": "float"
17161726
},
1717-
"title": "repeated values. they are comma-separated in path"
1727+
"title": "repeated values. they are comma-separated in path",
1728+
"collectionFormat": "multi"
17181729
},
17191730
"path_repeated_double_value": {
17201731
"type": "array",
17211732
"items": {
17221733
"type": "number",
17231734
"format": "double"
1724-
}
1735+
},
1736+
"collectionFormat": "multi"
17251737
},
17261738
"path_repeated_int64_value": {
17271739
"type": "array",
17281740
"items": {
17291741
"type": "string",
17301742
"format": "int64"
1731-
}
1743+
},
1744+
"collectionFormat": "multi"
17321745
},
17331746
"path_repeated_uint64_value": {
17341747
"type": "array",
17351748
"items": {
17361749
"type": "string",
17371750
"format": "uint64"
1738-
}
1751+
},
1752+
"collectionFormat": "multi"
17391753
},
17401754
"path_repeated_int32_value": {
17411755
"type": "array",
17421756
"items": {
17431757
"type": "integer",
17441758
"format": "int32"
1745-
}
1759+
},
1760+
"collectionFormat": "multi"
17461761
},
17471762
"path_repeated_fixed64_value": {
17481763
"type": "array",
17491764
"items": {
17501765
"type": "string",
17511766
"format": "uint64"
1752-
}
1767+
},
1768+
"collectionFormat": "multi"
17531769
},
17541770
"path_repeated_fixed32_value": {
17551771
"type": "array",
17561772
"items": {
17571773
"type": "integer",
17581774
"format": "int64"
1759-
}
1775+
},
1776+
"collectionFormat": "multi"
17601777
},
17611778
"path_repeated_bool_value": {
17621779
"type": "array",
17631780
"items": {
17641781
"type": "boolean",
17651782
"format": "boolean"
1766-
}
1783+
},
1784+
"collectionFormat": "multi"
17671785
},
17681786
"path_repeated_string_value": {
17691787
"type": "array",
17701788
"items": {
17711789
"type": "string"
1772-
}
1790+
},
1791+
"collectionFormat": "multi"
17731792
},
17741793
"path_repeated_bytes_value": {
17751794
"type": "array",
17761795
"items": {
17771796
"type": "string",
17781797
"format": "byte"
1779-
}
1798+
},
1799+
"collectionFormat": "multi"
17801800
},
17811801
"path_repeated_uint32_value": {
17821802
"type": "array",
17831803
"items": {
17841804
"type": "integer",
17851805
"format": "int64"
1786-
}
1806+
},
1807+
"collectionFormat": "multi"
17871808
},
17881809
"path_repeated_enum_value": {
17891810
"type": "array",
17901811
"items": {
17911812
"$ref": "#/definitions/examplepbNumericEnum"
1792-
}
1813+
},
1814+
"collectionFormat": "multi"
17931815
},
17941816
"path_repeated_sfixed32_value": {
17951817
"type": "array",
17961818
"items": {
17971819
"type": "integer",
17981820
"format": "int32"
1799-
}
1821+
},
1822+
"collectionFormat": "multi"
18001823
},
18011824
"path_repeated_sfixed64_value": {
18021825
"type": "array",
18031826
"items": {
18041827
"type": "string",
18051828
"format": "int64"
1806-
}
1829+
},
1830+
"collectionFormat": "multi"
18071831
},
18081832
"path_repeated_sint32_value": {
18091833
"type": "array",
18101834
"items": {
18111835
"type": "integer",
18121836
"format": "int32"
1813-
}
1837+
},
1838+
"collectionFormat": "multi"
18141839
},
18151840
"path_repeated_sint64_value": {
18161841
"type": "array",
18171842
"items": {
18181843
"type": "string",
18191844
"format": "int64"
1820-
}
1845+
},
1846+
"collectionFormat": "multi"
18211847
}
18221848
},
18231849
"title": "ABitOfEverythingRepeated is used to validate repeated path parameter functionality"
@@ -1867,7 +1893,8 @@
18671893
"items": {
18681894
"type": "string"
18691895
},
1870-
"description": "The set of field mask paths."
1896+
"description": "The set of field mask paths.",
1897+
"collectionFormat": "multi"
18711898
}
18721899
},
18731900
"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\nexample 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,\nother 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\nto 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\nbe appended to the existing repeated field in the target resource. Note that\na 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\nupdate operation, then new value will be merged into the existing sub-message\nin 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\nthen 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\nbe 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 duplicated or unmappable.",

examples/proto/examplepb/response_body_service.swagger.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"type": "array",
2626
"items": {
2727
"$ref": "#/definitions/examplepbRepeatedResponseBodyOutResponse"
28-
}
28+
},
29+
"collectionFormat": "multi"
2930
}
3031
}
3132
},
@@ -76,7 +77,8 @@
7677
"type": "array",
7778
"items": {
7879
"type": "string"
79-
}
80+
},
81+
"collectionFormat": "multi"
8082
}
8183
}
8284
},
@@ -112,7 +114,8 @@
112114
"type": "array",
113115
"items": {
114116
"$ref": "#/definitions/examplepbRepeatedResponseBodyOutResponse"
115-
}
117+
},
118+
"collectionFormat": "multi"
116119
}
117120
}
118121
},
@@ -134,7 +137,8 @@
134137
"type": "array",
135138
"items": {
136139
"type": "string"
137-
}
140+
},
141+
"collectionFormat": "multi"
138142
}
139143
}
140144
},

examples/proto/examplepb/stream.swagger.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
"type": "array",
144144
"items": {
145145
"$ref": "#/definitions/ABitOfEverythingNested"
146-
}
146+
},
147+
"collectionFormat": "multi"
147148
},
148149
"float_value": {
149150
"type": "number",
@@ -222,7 +223,8 @@
222223
"type": "array",
223224
"items": {
224225
"type": "string"
225-
}
226+
},
227+
"collectionFormat": "multi"
226228
},
227229
"oneof_empty": {
228230
"properties": {}
@@ -260,15 +262,17 @@
260262
"items": {
261263
"$ref": "#/definitions/examplepbNumericEnum"
262264
},
263-
"title": "repeated enum value. it is comma-separated in query"
265+
"title": "repeated enum value. it is comma-separated in query",
266+
"collectionFormat": "multi"
264267
},
265268
"repeated_enum_annotation": {
266269
"type": "array",
267270
"items": {
268271
"$ref": "#/definitions/examplepbNumericEnum"
269272
},
270273
"description": "Repeated numeric enum description.",
271-
"title": "Repeated numeric enum title"
274+
"title": "Repeated numeric enum title",
275+
"collectionFormat": "multi"
272276
},
273277
"enum_value_annotation": {
274278
"$ref": "#/definitions/examplepbNumericEnum",
@@ -281,15 +285,17 @@
281285
"type": "string"
282286
},
283287
"description": "Repeated string description.",
284-
"title": "Repeated string title"
288+
"title": "Repeated string title",
289+
"collectionFormat": "multi"
285290
},
286291
"repeated_nested_annotation": {
287292
"type": "array",
288293
"items": {
289294
"$ref": "#/definitions/ABitOfEverythingNested"
290295
},
291296
"description": "Repeated nested object description.",
292-
"title": "Repeated nested object title"
297+
"title": "Repeated nested object title",
298+
"collectionFormat": "multi"
293299
},
294300
"nested_annotation": {
295301
"$ref": "#/definitions/ABitOfEverythingNested",
@@ -362,7 +368,8 @@
362368
"type": "array",
363369
"items": {
364370
"$ref": "#/definitions/protobufAny"
365-
}
371+
},
372+
"collectionFormat": "multi"
366373
}
367374
}
368375
},

0 commit comments

Comments
 (0)