Generating documentation from proto files
Kostiantyn Shchepanovskyi edited this page Sep 6, 2015
·
3 revisions
You can include comments that starts with triple slash (///
) into generated code.
In order to do this, custom code generator template should be used.
All comment lines from proto are stored to docs
field. Leading spaces are preserved.
This field can be used in a following way (StringTemplate v3):
docs(container) ::= <<
<if(container.docs)>
/**
<container.docs:{doc | *<doc>}; separator="\n">
*/
<endif>
>>
Then you can refer this template for all objects defined by proto:
- messages
- message fields
- enums
- enum constants
- services
- service (rpc) methods
Example: field getter
field_getters(field, options, message) ::= <<
<docs(container=field)>
<if(field.repeated)>
public List\<<map_primitive_wrapper.(field.javaType)>\> get<field.name; format="PC&&SINGULAR">List() {
return <var(val=field.name, fmt="CC", options=options)>;
}