diff --git a/examples/internal/clients/echo/api/swagger.yaml b/examples/internal/clients/echo/api/swagger.yaml index a7871cf2238..cb72b63ef62 100644 --- a/examples/internal/clients/echo/api/swagger.yaml +++ b/examples/internal/clients/echo/api/swagger.yaml @@ -411,26 +411,6 @@ paths: required: true type: "string" x-exportParamName: "Lang" - - name: "lineNum" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "LineNum" - x-optionalDataType: "String" - - name: "status.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "StatusProgress" - x-optionalDataType: "String" - - name: "status.note" - in: "query" - required: false - type: "string" - x-exportParamName: "StatusNote" - x-optionalDataType: "String" - name: "en" in: "query" required: false @@ -438,19 +418,6 @@ paths: format: "int64" x-exportParamName: "En" x-optionalDataType: "String" - - name: "no.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "NoProgress" - x-optionalDataType: "String" - - name: "no.note" - in: "query" - required: false - type: "string" - x-exportParamName: "NoNote" - x-optionalDataType: "String" - name: "resourceId" in: "query" required: false @@ -510,19 +477,6 @@ paths: format: "int64" x-exportParamName: "Num" x-optionalDataType: "String" - - name: "lang" - in: "query" - required: false - type: "string" - x-exportParamName: "Lang" - x-optionalDataType: "String" - - name: "status.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "StatusProgress" - x-optionalDataType: "String" - name: "en" in: "query" required: false @@ -530,13 +484,6 @@ paths: format: "int64" x-exportParamName: "En" x-optionalDataType: "String" - - name: "no.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "NoProgress" - x-optionalDataType: "String" - name: "resourceId" in: "query" required: false @@ -591,26 +538,6 @@ paths: format: "int64" x-exportParamName: "Num" x-optionalDataType: "String" - - name: "lineNum" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "LineNum" - x-optionalDataType: "String" - - name: "lang" - in: "query" - required: false - type: "string" - x-exportParamName: "Lang" - x-optionalDataType: "String" - - name: "status.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "StatusProgress" - x-optionalDataType: "String" - name: "en" in: "query" required: false @@ -618,13 +545,6 @@ paths: format: "int64" x-exportParamName: "En" x-optionalDataType: "String" - - name: "no.progress" - in: "query" - required: false - type: "string" - format: "int64" - x-exportParamName: "NoProgress" - x-optionalDataType: "String" - name: "resourceId" in: "query" required: false diff --git a/examples/internal/clients/echo/api_echo_service.go b/examples/internal/clients/echo/api_echo_service.go index c5807965d34..df685db7b47 100644 --- a/examples/internal/clients/echo/api_echo_service.go +++ b/examples/internal/clients/echo/api_echo_service.go @@ -351,12 +351,7 @@ The message posted as the id parameter will also be returned. * @param num * @param lang * @param optional nil or *EchoServiceEcho3Opts - Optional Parameters: - * @param "LineNum" (optional.String) - - * @param "StatusProgress" (optional.String) - - * @param "StatusNote" (optional.String) - * @param "En" (optional.String) - - * @param "NoProgress" (optional.String) - - * @param "NoNote" (optional.String) - * @param "ResourceId" (optional.String) - * @param "NIdNId" (optional.String) - * @param "NIdVal" (optional.String) - @@ -365,12 +360,7 @@ The message posted as the id parameter will also be returned. */ type EchoServiceEcho3Opts struct { - LineNum optional.String - StatusProgress optional.String - StatusNote optional.String En optional.String - NoProgress optional.String - NoNote optional.String ResourceId optional.String NIdNId optional.String NIdVal optional.String @@ -395,24 +385,9 @@ func (a *EchoServiceApiService) EchoServiceEcho3(ctx context.Context, id string, localVarQueryParams := url.Values{} localVarFormParams := url.Values{} - if localVarOptionals != nil && localVarOptionals.LineNum.IsSet() { - localVarQueryParams.Add("lineNum", parameterToString(localVarOptionals.LineNum.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.StatusProgress.IsSet() { - localVarQueryParams.Add("status.progress", parameterToString(localVarOptionals.StatusProgress.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.StatusNote.IsSet() { - localVarQueryParams.Add("status.note", parameterToString(localVarOptionals.StatusNote.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.En.IsSet() { localVarQueryParams.Add("en", parameterToString(localVarOptionals.En.Value(), "")) } - if localVarOptionals != nil && localVarOptionals.NoProgress.IsSet() { - localVarQueryParams.Add("no.progress", parameterToString(localVarOptionals.NoProgress.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.NoNote.IsSet() { - localVarQueryParams.Add("no.note", parameterToString(localVarOptionals.NoNote.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.ResourceId.IsSet() { localVarQueryParams.Add("resourceId", parameterToString(localVarOptionals.ResourceId.Value(), "")) } @@ -506,10 +481,7 @@ The message posted as the id parameter will also be returned. * @param statusNote * @param optional nil or *EchoServiceEcho4Opts - Optional Parameters: * @param "Num" (optional.String) - - * @param "Lang" (optional.String) - - * @param "StatusProgress" (optional.String) - * @param "En" (optional.String) - - * @param "NoProgress" (optional.String) - * @param "ResourceId" (optional.String) - * @param "NIdNId" (optional.String) - * @param "NIdVal" (optional.String) - @@ -519,10 +491,7 @@ The message posted as the id parameter will also be returned. type EchoServiceEcho4Opts struct { Num optional.String - Lang optional.String - StatusProgress optional.String En optional.String - NoProgress optional.String ResourceId optional.String NIdNId optional.String NIdVal optional.String @@ -550,18 +519,9 @@ func (a *EchoServiceApiService) EchoServiceEcho4(ctx context.Context, id string, if localVarOptionals != nil && localVarOptionals.Num.IsSet() { localVarQueryParams.Add("num", parameterToString(localVarOptionals.Num.Value(), "")) } - if localVarOptionals != nil && localVarOptionals.Lang.IsSet() { - localVarQueryParams.Add("lang", parameterToString(localVarOptionals.Lang.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.StatusProgress.IsSet() { - localVarQueryParams.Add("status.progress", parameterToString(localVarOptionals.StatusProgress.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.En.IsSet() { localVarQueryParams.Add("en", parameterToString(localVarOptionals.En.Value(), "")) } - if localVarOptionals != nil && localVarOptionals.NoProgress.IsSet() { - localVarQueryParams.Add("no.progress", parameterToString(localVarOptionals.NoProgress.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.ResourceId.IsSet() { localVarQueryParams.Add("resourceId", parameterToString(localVarOptionals.ResourceId.Value(), "")) } @@ -654,11 +614,7 @@ The message posted as the id parameter will also be returned. * @param optional nil or *EchoServiceEcho5Opts - Optional Parameters: * @param "Id" (optional.String) - Id represents the message identifier. * @param "Num" (optional.String) - - * @param "LineNum" (optional.String) - - * @param "Lang" (optional.String) - - * @param "StatusProgress" (optional.String) - * @param "En" (optional.String) - - * @param "NoProgress" (optional.String) - * @param "ResourceId" (optional.String) - * @param "NIdNId" (optional.String) - * @param "NIdVal" (optional.String) - @@ -669,11 +625,7 @@ The message posted as the id parameter will also be returned. type EchoServiceEcho5Opts struct { Id optional.String Num optional.String - LineNum optional.String - Lang optional.String - StatusProgress optional.String En optional.String - NoProgress optional.String ResourceId optional.String NIdNId optional.String NIdVal optional.String @@ -702,21 +654,9 @@ func (a *EchoServiceApiService) EchoServiceEcho5(ctx context.Context, noNote str if localVarOptionals != nil && localVarOptionals.Num.IsSet() { localVarQueryParams.Add("num", parameterToString(localVarOptionals.Num.Value(), "")) } - if localVarOptionals != nil && localVarOptionals.LineNum.IsSet() { - localVarQueryParams.Add("lineNum", parameterToString(localVarOptionals.LineNum.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.Lang.IsSet() { - localVarQueryParams.Add("lang", parameterToString(localVarOptionals.Lang.Value(), "")) - } - if localVarOptionals != nil && localVarOptionals.StatusProgress.IsSet() { - localVarQueryParams.Add("status.progress", parameterToString(localVarOptionals.StatusProgress.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.En.IsSet() { localVarQueryParams.Add("en", parameterToString(localVarOptionals.En.Value(), "")) } - if localVarOptionals != nil && localVarOptionals.NoProgress.IsSet() { - localVarQueryParams.Add("no.progress", parameterToString(localVarOptionals.NoProgress.Value(), "")) - } if localVarOptionals != nil && localVarOptionals.ResourceId.IsSet() { localVarQueryParams.Add("resourceId", parameterToString(localVarOptionals.ResourceId.Value(), "")) } diff --git a/examples/internal/proto/examplepb/echo_service.swagger.json b/examples/internal/proto/examplepb/echo_service.swagger.json index 4270e770ab2..5c590bf0c88 100644 --- a/examples/internal/proto/examplepb/echo_service.swagger.json +++ b/examples/internal/proto/examplepb/echo_service.swagger.json @@ -473,26 +473,6 @@ "required": true, "type": "string" }, - { - "name": "lineNum", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, - { - "name": "status.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, - { - "name": "status.note", - "in": "query", - "required": false, - "type": "string" - }, { "name": "en", "in": "query", @@ -500,19 +480,6 @@ "type": "string", "format": "int64" }, - { - "name": "no.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, - { - "name": "no.note", - "in": "query", - "required": false, - "type": "string" - }, { "name": "resourceId", "in": "query", @@ -584,19 +551,6 @@ "type": "string", "format": "int64" }, - { - "name": "lang", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "status.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, { "name": "en", "in": "query", @@ -604,13 +558,6 @@ "type": "string", "format": "int64" }, - { - "name": "no.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, { "name": "resourceId", "in": "query", @@ -675,26 +622,6 @@ "type": "string", "format": "int64" }, - { - "name": "lineNum", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, - { - "name": "lang", - "in": "query", - "required": false, - "type": "string" - }, - { - "name": "status.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, { "name": "en", "in": "query", @@ -702,13 +629,6 @@ "type": "string", "format": "int64" }, - { - "name": "no.progress", - "in": "query", - "required": false, - "type": "string", - "format": "int64" - }, { "name": "resourceId", "in": "query", diff --git a/protoc-gen-openapiv2/internal/genopenapi/template.go b/protoc-gen-openapiv2/internal/genopenapi/template.go index 1856255fd99..12e079b0b06 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -273,6 +273,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 { diff --git a/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext b/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext index 63a641be2b9..8513d55c023 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext +++ b/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.prototext @@ -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" @@ -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}" } } } } diff --git a/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml b/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml index 89b65a9007f..8cf57b8e3a4 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml +++ b/protoc-gen-openapiv2/internal/genopenapi/testdata/generator/path_item_object.swagger.yaml @@ -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: @@ -30,3 +99,7 @@ definitions: properties: value: type: string + uuid: + type: string + id: + type: string