Skip to content

Commit 0bbdda9

Browse files
adambabikadamb-scylladb
authored andcommitted
internal/descriptor: forbid proto3 optional fields from URL path
1 parent e5848b7 commit 0bbdda9

File tree

11 files changed

+483
-469
lines changed

11 files changed

+483
-469
lines changed

examples/internal/clients/abe/api/swagger.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ paths:
13841384
description: "Find out more about GetQuery"
13851385
url: "https://github.com/grpc-ecosystem/grpc-gateway"
13861386
deprecated: true
1387-
? /v1/example/a_bit_of_everything/{floatValue}/{doubleValue}/{int64Value}/separator/{uint64Value}/{int32Value}/{fixed64Value}/{fixed32Value}/{boolValue}/{stringValue}/{uint32Value}/{sfixed32Value}/{sfixed64Value}/{sint32Value}/{sint64Value}/{nonConventionalNameValue}/{enumValue}/{pathEnumValue}/{nestedPathEnumValue}/{enumValueAnnotation}/{optionalStringValue}
1387+
? /v1/example/a_bit_of_everything/{floatValue}/{doubleValue}/{int64Value}/separator/{uint64Value}/{int32Value}/{fixed64Value}/{fixed32Value}/{boolValue}/{stringValue}/{uint32Value}/{sfixed32Value}/{sfixed64Value}/{sint32Value}/{sint64Value}/{nonConventionalNameValue}/{enumValue}/{pathEnumValue}/{nestedPathEnumValue}/{enumValueAnnotation}
13881388
: post:
13891389
tags:
13901390
- "ABitOfEverythingService"
@@ -1514,11 +1514,6 @@ paths:
15141514
- "ZERO"
15151515
- "ONE"
15161516
x-exportParamName: "EnumValueAnnotation"
1517-
- name: "optionalStringValue"
1518-
in: "path"
1519-
required: true
1520-
type: "string"
1521-
x-exportParamName: "OptionalStringValue"
15221517
responses:
15231518
200:
15241519
description: "A successful response."

examples/internal/clients/abe/api_a_bit_of_everything_service.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,10 @@ This API creates a new ABitOfEverything
13431343
* @param pathEnumValue
13441344
* @param nestedPathEnumValue
13451345
* @param enumValueAnnotation Numeric enum description.
1346-
* @param optionalStringValue
13471346
13481347
@return ExamplepbABitOfEverything
13491348
*/
1350-
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreate(ctx context.Context, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string, enumValue string, pathEnumValue string, nestedPathEnumValue string, enumValueAnnotation string, optionalStringValue string) (ExamplepbABitOfEverything, *http.Response, error) {
1349+
func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreate(ctx context.Context, floatValue float32, doubleValue float64, int64Value string, uint64Value string, int32Value int32, fixed64Value string, fixed32Value int64, boolValue bool, stringValue string, uint32Value int64, sfixed32Value int32, sfixed64Value string, sint32Value int32, sint64Value string, nonConventionalNameValue string, enumValue string, pathEnumValue string, nestedPathEnumValue string, enumValueAnnotation string) (ExamplepbABitOfEverything, *http.Response, error) {
13511350
var (
13521351
localVarHttpMethod = strings.ToUpper("Post")
13531352
localVarPostBody interface{}
@@ -1357,7 +1356,7 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreate(ctx co
13571356
)
13581357

13591358
// create path and map variables
1360-
localVarPath := a.client.cfg.BasePath + "/v1/example/a_bit_of_everything/{floatValue}/{doubleValue}/{int64Value}/separator/{uint64Value}/{int32Value}/{fixed64Value}/{fixed32Value}/{boolValue}/{stringValue}/{uint32Value}/{sfixed32Value}/{sfixed64Value}/{sint32Value}/{sint64Value}/{nonConventionalNameValue}/{enumValue}/{pathEnumValue}/{nestedPathEnumValue}/{enumValueAnnotation}/{optionalStringValue}"
1359+
localVarPath := a.client.cfg.BasePath + "/v1/example/a_bit_of_everything/{floatValue}/{doubleValue}/{int64Value}/separator/{uint64Value}/{int32Value}/{fixed64Value}/{fixed32Value}/{boolValue}/{stringValue}/{uint32Value}/{sfixed32Value}/{sfixed64Value}/{sint32Value}/{sint64Value}/{nonConventionalNameValue}/{enumValue}/{pathEnumValue}/{nestedPathEnumValue}/{enumValueAnnotation}"
13611360
localVarPath = strings.Replace(localVarPath, "{"+"floatValue"+"}", fmt.Sprintf("%v", floatValue), -1)
13621361
localVarPath = strings.Replace(localVarPath, "{"+"doubleValue"+"}", fmt.Sprintf("%v", doubleValue), -1)
13631362
localVarPath = strings.Replace(localVarPath, "{"+"int64Value"+"}", fmt.Sprintf("%v", int64Value), -1)
@@ -1377,7 +1376,6 @@ func (a *ABitOfEverythingServiceApiService) ABitOfEverythingServiceCreate(ctx co
13771376
localVarPath = strings.Replace(localVarPath, "{"+"pathEnumValue"+"}", fmt.Sprintf("%v", pathEnumValue), -1)
13781377
localVarPath = strings.Replace(localVarPath, "{"+"nestedPathEnumValue"+"}", fmt.Sprintf("%v", nestedPathEnumValue), -1)
13791378
localVarPath = strings.Replace(localVarPath, "{"+"enumValueAnnotation"+"}", fmt.Sprintf("%v", enumValueAnnotation), -1)
1380-
localVarPath = strings.Replace(localVarPath, "{"+"optionalStringValue"+"}", fmt.Sprintf("%v", optionalStringValue), -1)
13811379

13821380
localVarHeaderParams := make(map[string]string)
13831381
localVarQueryParams := url.Values{}

examples/internal/integration/client_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func testABEClientCreate(t *testing.T, cl *abe.APIClient) {
109109
want.PathEnumValue.String(),
110110
want.NestedPathEnumValue.String(),
111111
want.EnumValueAnnotation.String(),
112-
want.OptionalStringValue,
113112
)
114113
if err != nil {
115114
t.Fatalf("cl.Create(%#v) failed with %v; want success", want, err)

examples/internal/integration/integration_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ func TestABE(t *testing.T) {
349349
}
350350

351351
func testABECreate(t *testing.T, port int) {
352-
optionalStrVal := "optional-str"
353352
want := &examplepb.ABitOfEverything{
354353
FloatValue: 1.5,
355354
DoubleValue: 2.5,
@@ -370,9 +369,8 @@ func testABECreate(t *testing.T, port int) {
370369
PathEnumValue: pathenum.PathEnum_DEF,
371370
NestedPathEnumValue: pathenum.MessagePathEnum_JKL,
372371
EnumValueAnnotation: examplepb.NumericEnum_ONE,
373-
OptionalStringValue: &optionalStrVal,
374372
}
375-
apiURL := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s/%s/%s/%s/%s/%s", port, want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue, want.EnumValue, want.PathEnumValue, want.NestedPathEnumValue, want.EnumValueAnnotation, *want.OptionalStringValue)
373+
apiURL := fmt.Sprintf("http://localhost:%d/v1/example/a_bit_of_everything/%f/%f/%d/separator/%d/%d/%d/%d/%v/%s/%d/%d/%d/%d/%d/%s/%s/%s/%s/%s", port, want.FloatValue, want.DoubleValue, want.Int64Value, want.Uint64Value, want.Int32Value, want.Fixed64Value, want.Fixed32Value, want.BoolValue, want.StringValue, want.Uint32Value, want.Sfixed32Value, want.Sfixed64Value, want.Sint32Value, want.Sint64Value, want.NonConventionalNameValue, want.EnumValue, want.PathEnumValue, want.NestedPathEnumValue, want.EnumValueAnnotation)
376374

377375
resp, err := http.Post(apiURL, "application/json", strings.NewReader("{}"))
378376
if err != nil {

0 commit comments

Comments
 (0)