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
Alternative to the above, you can enable the `expand_slashed_path_patterns` compiler option to expand path parameters containing sub-path segments into the URI.
545
+
546
+
For example, consider:
547
+
```protobuf
548
+
rpc GetBook(GetBookRequest) returns (Book) {
549
+
option (google.api.http) = {
550
+
get: "/v1/{name=publishers/*/books/*}"
551
+
};
552
+
}
553
+
```
554
+
555
+
Where the `GetBook` has a path parameter `name` with a pattern `publishers/*/books/*`. When you enable the `expand_slashed_path_patterns=true` option the path pattern is expanded into the URI and each wildcard in the pattern is transformed into new path parameter. The generated schema for previous protobuf is:
556
+
557
+
```JSON
558
+
{
559
+
"/v1/publishers/{publisher}/books/{book}": {
560
+
"get": {
561
+
"parameters": [
562
+
{
563
+
"name": "publisher",
564
+
"in": "path",
565
+
"required": true,
566
+
"type": "string",
567
+
},
568
+
{
569
+
"name": "book",
570
+
"in": "path",
571
+
"required": true,
572
+
"type": "string",
573
+
}
574
+
]
575
+
}
576
+
}
577
+
}
578
+
```
579
+
580
+
The URI is now pretty descriptive and there are two path parameters `publisher` and `book` instead of one `name`. The name of the new parameters is derived from the path segment before the wildcard in the pattern.
581
+
582
+
Caveats:
583
+
584
+
- the fact that the original `name` parameter is missing might complicate the usage of the API if you intend to pass in the `name` parameters from the resources,
585
+
- when the `expand_slashed_path_patterns` compiler flag is enabled, the [`path_param_name`](#path-parameters) field annotation is ignored.
586
+
542
587
### Output format
543
588
544
589
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