Skip to content

Commit

Permalink
fix: added fix for grpc-ecosystem#2494
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-raj-ev committed Oct 6, 2023
1 parent 6b200c1 commit b1ee40f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
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
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

0 comments on commit b1ee40f

Please sign in to comment.