You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protoc-gen-openapiv2: support overriding path parameter names (grpc-ecosystem#2562)
* Support overriding path parameter names.
* Support overriding path parameter names.
* Revert using annotations in `message.proto`
* Moved path_param_name to inner message as it is not defined in OpenAPIv2
* Added documentation for path_param_name
* Moved pathParamName to FieldConfiguration struct to follow same pattern as in JSONSchema.
* Fix tests.
* Remove fieldConfiguration from openapiSchemaObject
When defining HTTP bindings with path parameters that contain multiple path segments, as suggested by the [Google AIPs](https://google.aip.dev/), the path parameter names are numbered to avoid generating duplicate paths in the OpenAPI file.
409
+
410
+
For example, consider:
411
+
```protobuf
412
+
service LibraryService {
413
+
rpc GetShelf(GetShelfRequest) returns (Shelf) {
414
+
option (google.api.http) = {
415
+
get: "/v1/{name=shelves/*}"
416
+
};
417
+
}
418
+
rpc GetBook(GetBookRequest) returns (Book) {
419
+
option (google.api.http) = {
420
+
get: "/v1/{name=shelves/*/books/*}"
421
+
};
422
+
}
423
+
}
424
+
425
+
message GetShelfRequest {
426
+
string name = 1;
427
+
}
428
+
429
+
message GetBookRequest {
430
+
string name = 1;
431
+
}
432
+
```
433
+
434
+
This will generate the following paths:
435
+
- `/v1/{name}`
436
+
- `/v1/{name_1}`
437
+
438
+
To override the path parameter names, annotate the field used as path parameter:
439
+
```protobuf
440
+
message GetShelfRequest {
441
+
string name = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {field_configuration: {path_param_name: "shelfName"}}];
442
+
}
443
+
message GetBookRequest {
444
+
string name = 1 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {field_configuration: {path_param_name: "bookName"}}];
445
+
}
446
+
```
447
+
448
+
This will instead generate the following paths:
449
+
- `/v1/{shelfName}`
450
+
- `/v1/{bookName}`
451
+
406
452
### Output format
407
453
408
454
By default the output format is JSON, but it is possible to configure it using the `output_format` option. Allowed values are: `json`, `yaml`. The output format will also change the extension of the output files.
0 commit comments