Documentation ¶
Overview ¶
Package gendoc is a protoc plugin for generating documentation from your proto files.
Typically this will not be used as a library, though nothing prevents that. Normally it'll be invoked by passing `--doc_out` and `--doc_opt` values to protoc.
Example: generate HTML documentation
protoc --doc_out=. --doc_opt=html,index.html protos/*.proto
Example: exclude patterns
protoc --doc_out=. --doc_opt=html,index.html:google/*,somedir/* protos/*.proto
Example: use a custom template
protoc --doc_out=. --doc_opt=custom.tmpl,docs.txt protos/*.proto
For more details, check out the README at https://github.com/pseudomuto/protoc-gen-doc
Index ¶
- Constants
- func NoBrFilter(content string) string
- func PFilter(content string) template.HTML
- func ParaFilter(content string) string
- func RenderTemplate(kind RenderType, template *Template, inputTemplate string) ([]byte, error)
- type Enum
- type EnumValue
- type File
- type FileExtension
- type Message
- type MessageExtension
- type MessageField
- type Plugin
- type PluginOptions
- type Processor
- type RenderType
- type ScalarValue
- type Service
- type ServiceMethod
- type Template
Constants ¶
const VERSION = "1.1.0"
VERSION is the version of protoc-gen-doc being used.
Variables ¶
This section is empty.
Functions ¶
func NoBrFilter ¶
NoBrFilter removes single CR and LF from content.
func ParaFilter ¶
ParaFilter splits the content by new lines and wraps each one in a <para> tag.
func RenderTemplate ¶
func RenderTemplate(kind RenderType, template *Template, inputTemplate string) ([]byte, error)
RenderTemplate renders the template based on the render type. It supports overriding the default input templates by supplying a non-empty string as the last parameter.
Example: generating an HTML template (assuming you've got a Template object)
data, err := RenderTemplate(RenderTypeHTML, &template, "")
Example: generating a custom template (assuming you've got a Template object)
data, err := RenderTemplate(RenderTypeHTML, &template, "{{range .Files}}{{.Name}}{{end}}")
Types ¶
type Enum ¶
type Enum struct { Name string `json:"name"` LongName string `json:"longName"` FullName string `json:"fullName"` Description string `json:"description"` Values []*EnumValue `json:"values"` }
Enum contains details about enumerations. These can be either top level enums, or nested (defined within a message).
type EnumValue ¶
type EnumValue struct { Name string `json:"name"` Number string `json:"number"` Description string `json:"description"` }
EnumValue contains details about an individual value within an enumeration.
type File ¶
type File struct { Name string `json:"name"` Description string `json:"description"` Package string `json:"package"` HasEnums bool `json:"hasEnums"` HasExtensions bool `json:"hasExtensions"` HasMessages bool `json:"hasMessages"` HasServices bool `json:"hasServices"` Enums orderedEnums `json:"enums"` Extensions orderedExtensions `json:"extensions"` Messages orderedMessages `json:"messages"` Services orderedServices `json:"services"` }
File wraps all the relevant parsed info about a proto file. File objects guarantee that their top-level enums, extensions, messages, and services are sorted alphabetically based on their "long name". Other values (enum values, fields, service methods) will be in the order that they're defined within their respective proto files.
In the case of proto3 files, HasExtensions will always be false, and Extensions will be empty.
type FileExtension ¶
type FileExtension struct { Name string `json:"name"` LongName string `json:"longName"` FullName string `json:"fullName"` Description string `json:"description"` Label string `json:"label"` Type string `json:"type"` LongType string `json:"longType"` FullType string `json:"fullType"` Number int `json:"number"` DefaultValue string `json:"defaultValue"` ContainingType string `json:"containingType"` ContainingLongType string `json:"containingLongType"` ContainingFullType string `json:"containingFullType"` }
FileExtension contains details about top-level extensions within a proto(2) file.
type Message ¶
type Message struct { Name string `json:"name"` LongName string `json:"longName"` FullName string `json:"fullName"` Description string `json:"description"` HasExtensions bool `json:"hasExtensions"` HasFields bool `json:"hasFields"` Extensions []*MessageExtension `json:"extensions"` Fields []*MessageField `json:"fields"` }
Message contains details about a protobuf message.
In the case of proto3 files, HasExtensions will always be false, and Extensions will be empty.
type MessageExtension ¶
type MessageExtension struct { FileExtension ScopeType string `json:"scopeType"` ScopeLongType string `json:"scopeLongType"` ScopeFullType string `json:"scopeFullType"` }
MessageExtension contains details about message-scoped extensions in proto(2) files.
type MessageField ¶
type MessageField struct { Name string `json:"name"` Description string `json:"description"` Label string `json:"label"` Type string `json:"type"` LongType string `json:"longType"` FullType string `json:"fullType"` DefaultValue string `json:"defaultValue"` }
MessageField contains details about an individual field within a message.
In the case of proto3 files, DefaultValue will always be empty. Similarly, label will be empty unless the field is repeated (in which case it'll be "repeated").
type Plugin ¶ added in v1.1.0
type Plugin struct{}
Plugin describes a protoc code generate plugin. It's an implementation of Plugin from github.com/pseudomuto/protokit
func (*Plugin) Generate ¶ added in v1.1.0
func (p *Plugin) Generate(r *plugin_go.CodeGeneratorRequest) (*plugin_go.CodeGeneratorResponse, error)
Generate compiles the documentation and generates the CodeGeneratorResponse to send back to protoc. It does this by rendering a template based on the options parsed from the CodeGeneratorRequest.
type PluginOptions ¶
type PluginOptions struct { Type RenderType TemplateFile string OutputFile string ExcludePatterns []*regexp.Regexp }
PluginOptions encapsulates options for the plugin. The type of renderer, template file, and the name of the output file are included.
func ParseOptions ¶
func ParseOptions(req *plugin_go.CodeGeneratorRequest) (*PluginOptions, error)
ParseOptions parses plugin options from a CodeGeneratorRequest. It does this by splitting the `Parameter` field from the request object and parsing out the type of renderer to use and the name of the file to be generated.
The parameter (`--doc_opt`) must be of the format <TYPE|TEMPLATE_FILE>,<OUTPUT_FILE>:<EXCLUDE_PATTERN>,<EXCLUDE_PATTERN>*. The file will be written to the directory specified with the `--doc_out` argument to protoc.
type Processor ¶
Processor is an interface that is satisfied by all built-in processors (text, html, and json).
type RenderType ¶
type RenderType int8
RenderType is an "enum" for which type of renderer to use.
const ( RenderTypeDocBook RenderType RenderTypeHTML RenderTypeJSON RenderTypeMarkdown )
Available render types.
func NewRenderType ¶
func NewRenderType(renderType string) (RenderType, error)
NewRenderType creates a RenderType from the supplied string. If the type is not known, (0, error) is returned. It is assumed (by the plugin) that invalid render type simply means that the path to a custom template was supplied.
type ScalarValue ¶
type ScalarValue struct { ProtoType string `json:"protoType"` Notes string `json:"notes"` CppType string `json:"cppType"` CSharp string `json:"csType"` GoType string `json:"goType"` JavaType string `json:"javaType"` PhpType string `json:"phpType"` PythonType string `json:"pythonType"` RubyType string `json:"rubyType"` }
ScalarValue contains information about scalar value types in protobuf. The common use case for this type is to know which language specific type maps to the protobuf type.
For example, the protobuf type `int64` maps to `long` in C#, and `Bignum` in Ruby. For the full list, take a look at https://developers.google.com/protocol-buffers/docs/proto3#scalar
type Service ¶
type Service struct { Name string `json:"name"` LongName string `json:"longName"` FullName string `json:"fullName"` Description string `json:"description"` Methods []*ServiceMethod `json:"methods"` }
Service contains details about a service definition within a proto file.
type ServiceMethod ¶
type ServiceMethod struct { Name string `json:"name"` Description string `json:"description"` RequestType string `json:"requestType"` RequestLongType string `json:"requestLongType"` RequestFullType string `json:"requestFullType"` ResponseType string `json:"responseType"` ResponseLongType string `json:"responseLongType"` ResponseFullType string `json:"responseFullType"` }
ServiceMethod contains details about an individual method within a service.
type Template ¶
type Template struct { // The files that were parsed Files []*File `json:"files"` // Details about the scalar values and their respective types in supported languages. Scalars []*ScalarValue `json:"scalarValueTypes"` }
Template is a type for encapsulating all the parsed files, messages, fields, enums, services, extensions, etc. into an object that will be supplied to a go template.
func NewTemplate ¶
func NewTemplate(descs []*protokit.FileDescriptor) *Template
NewTemplate creates a Template object from a set of descriptors.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
protoc-gen-doc
protoc-gen-doc is used to generate documentation from comments in your proto files.
|
protoc-gen-doc is used to generate documentation from comments in your proto files. |
This application will take a set of files in a directory and generate an "embedded" resource file containing the compressed contents of those files and related metadata.
|
This application will take a set of files in a directory and generate an "embedded" resource file containing the compressed contents of those files and related metadata. |