Skip to content

Commit b1ee40f

Browse files
committed
fix: added fix for grpc-ecosystem#2494
1 parent 6b200c1 commit b1ee40f

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

protoc-gen-openapiv2/internal/genopenapi/template.go

+4
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ func nestedQueryParams(message *descriptor.Message, field *descriptor.Field, pre
249249
if pathParam.Target == field {
250250
return nil, nil
251251
}
252+
// make sure if path parameter is of type one_of then other field should not be present as query parameters
253+
if pathParam.Target.OneofIndex != nil && field.OneofIndex != nil && pathParam.Target.GetOneofIndex() == field.GetOneofIndex() {
254+
return nil, nil
255+
}
252256
}
253257
// make sure the parameter is not already listed as a body parameter
254258
if body != nil {

protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext

+25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ proto_file: {
1111
type: TYPE_STRING
1212
json_name: "value"
1313
}
14+
oneof_decl: {
15+
name: "primary_key"
16+
}
17+
field: {
18+
name: "uuid"
19+
number: 2
20+
label: LABEL_OPTIONAL
21+
type: TYPE_STRING
22+
oneof_index: 0
23+
json_name: "uuid"
24+
}
25+
field: {
26+
name: "id"
27+
number: 3
28+
label: LABEL_OPTIONAL
29+
type: TYPE_STRING
30+
oneof_index: 0
31+
json_name: "id"
32+
}
1433
}
1534
service: {
1635
name: "YourService"
@@ -21,6 +40,12 @@ proto_file: {
2140
options: {
2241
[google.api.http]: {
2342
post: "/api/echo"
43+
additional_bindings: {
44+
get: "/api/echo/{value}" }
45+
additional_bindings: {
46+
get: "/api/echo/{uuid}" }
47+
additional_bindings: {
48+
get: "/api/echo/{id}" }
2449
}
2550
}
2651
}

protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml

+73
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,75 @@ paths:
2222
in: query
2323
required: false
2424
type: string
25+
- name: uuid
26+
in: query
27+
required: false
28+
type: string
29+
- name: id
30+
in: query
31+
required: false
32+
type: string
33+
tags:
34+
- YourService
35+
/api/echo/{id}:
36+
get:
37+
operationId: YourService_Echo4
38+
responses:
39+
"200":
40+
description: A successful response.
41+
schema:
42+
$ref: '#/definitions/StringMessage'
43+
parameters:
44+
- name: id
45+
in: path
46+
required: true
47+
type: string
48+
- name: value
49+
in: query
50+
required: false
51+
type: string
52+
tags:
53+
- YourService
54+
/api/echo/{uuid}:
55+
get:
56+
operationId: YourService_Echo3
57+
responses:
58+
"200":
59+
description: A successful response.
60+
schema:
61+
$ref: '#/definitions/StringMessage'
62+
parameters:
63+
- name: uuid
64+
in: path
65+
required: true
66+
type: string
67+
- name: value
68+
in: query
69+
required: false
70+
type: string
71+
tags:
72+
- YourService
73+
/api/echo/{value}:
74+
get:
75+
operationId: YourService_Echo2
76+
responses:
77+
"200":
78+
description: A successful response.
79+
schema:
80+
$ref: '#/definitions/StringMessage'
81+
parameters:
82+
- name: value
83+
in: path
84+
required: true
85+
type: string
86+
- name: uuid
87+
in: query
88+
required: false
89+
type: string
90+
- name: id
91+
in: query
92+
required: false
93+
type: string
2594
tags:
2695
- YourService
2796
definitions:
@@ -30,3 +99,7 @@ definitions:
3099
properties:
31100
value:
32101
type: string
102+
uuid:
103+
type: string
104+
id:
105+
type: string

0 commit comments

Comments
 (0)