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

Fix 2494 #3646

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func nestedQueryParams(message *descriptor.Message, field *descriptor.Field, pre
if pathParam.Target == field {
return nil, nil
}
// make sure if path parameter is of type one_of then other field should not be present as query parameters
if pathParam.Target.OneofIndex != nil && field.OneofIndex != nil && pathParam.Target.GetOneofIndex() == field.GetOneofIndex() {
return nil, nil
}
}
// make sure the parameter is not already listed as a body parameter
if body != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ proto_file: {
type: TYPE_STRING
json_name: "value"
}
oneof_decl: {
name: "primary_key"
}
field: {
name: "uuid"
number: 2
label: LABEL_OPTIONAL
type: TYPE_STRING
oneof_index: 0
json_name: "uuid"
}
field: {
name: "id"
number: 3
label: LABEL_OPTIONAL
type: TYPE_STRING
oneof_index: 0
json_name: "id"
}
}
service: {
name: "YourService"
Expand All @@ -21,6 +40,12 @@ proto_file: {
options: {
[google.api.http]: {
post: "/api/echo"
additional_bindings: {
get: "/api/echo/{value}" }
additional_bindings: {
get: "/api/echo/{uuid}" }
additional_bindings: {
get: "/api/echo/{id}" }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,75 @@ paths:
in: query
required: false
type: string
- name: uuid
in: query
required: false
type: string
- name: id
in: query
required: false
type: string
tags:
- YourService
/api/echo/{id}:
get:
operationId: YourService_Echo4
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/StringMessage'
parameters:
- name: id
in: path
required: true
type: string
- name: value
in: query
required: false
type: string
tags:
- YourService
/api/echo/{uuid}:
get:
operationId: YourService_Echo3
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/StringMessage'
parameters:
- name: uuid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this fix Id would also come up here, it's not now because uuid is of type one_of

in: path
required: true
type: string
- name: value
in: query
required: false
type: string
tags:
- YourService
/api/echo/{value}:
get:
operationId: YourService_Echo2
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/StringMessage'
parameters:
- name: value
in: path
required: true
type: string
- name: uuid
in: query
required: false
type: string
- name: id
in: query
required: false
type: string
tags:
- YourService
definitions:
Expand All @@ -30,3 +99,7 @@ definitions:
properties:
value:
type: string
uuid:
type: string
id:
type: string
Loading