File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
content/programming-guides Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -230,6 +230,42 @@ service FooService {
230230
231231## Things to Avoid {#avoid}
232232
233+ ### Avoid confusing relative packages on field types {#confusing-relative-packages}
234+
235+ The .proto syntax allows you to reference types that are defined in a different
236+ package in a relative manner. Resolution will search up the parent packages to
237+ resolve a relative name. For example:
238+
239+ ```
240+ // File: a.proto
241+ package a.b;
242+ message C {}
243+ ```
244+
245+ ```
246+ // File: x.proto
247+ package a.x;
248+ message SomeMsg {
249+ // Since we are in a.x.SomeMsg, this name is searched for in this order:
250+ // .a.x.SomeMsg.b.C
251+ // .a.x.b.C
252+ // .a.b.C
253+ // .b.C
254+ b.C field3 = 1;
255+ }
256+ ```
257+
258+ Relying on the "relative to a parent package" functionality when referencing
259+ types defined in a different package is supported but can be confusing: in this
260+ example the spelling ` a.b.C ` should be used.
261+
262+ Naming other types in the current package (for example, sibling messages)
263+ without writing the package is idiomatic.
264+
265+ You can write a fully qualified name by using a leading period to avoid any
266+ ambiguity concerns, but is commonly omitted in most cases even if the package is
267+ fully written out.
268+
233269### Required Fields {#required}
234270
235271Required fields are a way to enforce that a given field must be set when parsing
You can’t perform that action at this time.
0 commit comments