All Projects β†’ pseudomuto β†’ Protoc Gen Doc

pseudomuto / Protoc Gen Doc

Licence: mit
Documentation generator plugin for Google Protocol Buffers

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to Protoc Gen Doc

protocell
Conjures up convenient OCaml types and serialization functions based on protobuf definition files
Stars: ✭ 18 (-99%)
Mutual labels:  protobuf, protoc
Protoc Gen Gotemplate
πŸ“‚ generic protocol generator based on golang's text/template (grpc/protobuf)
Stars: ✭ 284 (-84.15%)
Mutual labels:  protobuf, protoc
protopatch
protoc-gen-go patch utility
Stars: ✭ 58 (-96.76%)
Mutual labels:  protobuf, protoc
makego
Makefile setup for our Golang projects.
Stars: ✭ 65 (-96.37%)
Mutual labels:  protobuf, protoc
Protodot
transforming your .proto files into .dot files (and .svg, .png if you happen to have graphviz installed)
Stars: ✭ 107 (-94.03%)
Mutual labels:  protobuf, protoc
gosproto
εŸΊδΊŽδΊ‘ι£Žηš„sprotoδΊŒθΏ›εˆΆζ ‡ε‡†δΈŠηš„ζθΏ°ζ–‡δ»ΆεŠδ»£η η”Ÿζˆε·₯ε…·
Stars: ✭ 52 (-97.1%)
Mutual labels:  protobuf, protoc
protoc-gen-kit
Protoc compiler for Go kit code
Stars: ✭ 17 (-99.05%)
Mutual labels:  protobuf, protoc
go2gql
graphql-go schema generator by proto files
Stars: ✭ 33 (-98.16%)
Mutual labels:  protobuf, protoc
Prototool
Your Swiss Army Knife for Protocol Buffers
Stars: ✭ 4,932 (+175.22%)
Mutual labels:  protobuf, protoc
Protobuf
A pure Elixir implementation of Google Protobuf
Stars: ✭ 442 (-75.33%)
Mutual labels:  protobuf, protoc
proto2gql
The project has been migrated to https://github.com/EGT-Ukraine/go2gql.
Stars: ✭ 21 (-98.83%)
Mutual labels:  protobuf, protoc
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+2818.81%)
Mutual labels:  protobuf, protoc
powerproto
πŸŽ‰ An awesome version control tool for protoc and its related plugins.
Stars: ✭ 161 (-91.02%)
Mutual labels:  protobuf, protoc
protobuf-d
Protocol Buffers Compiler Plugin and Support Library for D
Stars: ✭ 32 (-98.21%)
Mutual labels:  protobuf, protoc
protobuf-maven-plugin
Maven Plugin that executes the Protocol Buffers (protoc) compiler
Stars: ✭ 204 (-88.62%)
Mutual labels:  protobuf, protoc
docker-protobuf
An all-inclusive protoc Docker image
Stars: ✭ 105 (-94.14%)
Mutual labels:  protobuf, protoc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (-88.5%)
Mutual labels:  protobuf, protoc
protokit
A starter kit for building protoc plugins. Rather than write your own, you can just use an existing one.
Stars: ✭ 69 (-96.15%)
Mutual labels:  protobuf, protoc
Protolock
Protocol Buffer companion tool. Track your .proto files and prevent changes to messages and services which impact API compatibility.
Stars: ✭ 394 (-78.01%)
Mutual labels:  protobuf, protoc
Protobuf Swift
Google ProtocolBuffers for Apple Swift
Stars: ✭ 925 (-48.38%)
Mutual labels:  protobuf, protoc

protoc-gen-doc

CI Status codecov GoDoc Go Report Card

This is a documentation generator plugin for the Google Protocol Buffers compiler (protoc). The plugin can generate HTML, JSON, DocBook and Markdown documentation from comments in your .proto files.

It supports proto2 and proto3, and can handle having both in the same context (see examples for proof).

Installation

There is a Docker image available (docker pull pseudomuto/protoc-gen-doc) that has everything you need to generate documentation from your protos.

If you'd like to install this locally, you can go get it.

go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

Invoking the Plugin

The plugin is invoked by passing the --doc_out, and --doc_opt options to the protoc compiler. The option has the following format:

--doc_opt=<FORMAT>|<TEMPLATE_FILENAME>,<OUT_FILENAME>[,default|source_relative]

The format may be one of the built-in ones ( docbook, html, markdown or json) or the name of a file containing a custom Go template.

If the source_relative flag is specified, the output file is written in the same relative directory as the input file.

Using the Docker Image (Recommended)

The docker image has two volumes: /out and /protos which are the directory to write the documentation to and the directory containing your proto files.

You could generate HTML docs for the examples by running the following:

docker run --rm \
  -v $(pwd)/examples/doc:/out \
  -v $(pwd)/examples/proto:/protos \
  pseudomuto/protoc-gen-doc

By default HTML documentation is generated in /out/index.html for all .proto files in the /protos volume. This can be changed by passing the --doc_opt parameter to the container.

For example, to generate Markdown for all the examples:

docker run --rm \
  -v $(pwd)/examples/doc:/out \
  -v $(pwd)/examples/proto:/protos \
  pseudomuto/protoc-gen-doc --doc_opt=markdown,docs.md

You can also generate documentation for a single file. This can be done by passing the file(s) to the command:

docker run --rm \
  -v $(pwd)/examples/doc:/out \
  -v $(pwd)/examples/proto:/protos \
  pseudomuto/protoc-gen-doc --doc_opt=markdown,docs.md /protos/Booking.proto [OPTIONALLY LIST MORE FILES]

You can also exclude proto files that match specific path expressions. This is done by passing a second option delimited by :. For example, you can pass any number of comma separated patterns as the second option:

docker run --rm \
  -v $(pwd)/examples/doc:/out \
  -v $(pwd)/examples/proto:/protos \
  pseudomuto/protoc-gen-doc --doc_opt=:google/*,somepath/*

Remember: Paths should be from within the container, not the host!

NOTE: Due to the way wildcard expansion works with docker you cannot use a wildcard path (e.g. protos/*.proto) in the file list. To get around this, if no files are passed, the container will generate docs for protos/*.proto, which can be changed by mounting different volumes.

Simple Usage

For example, to generate HTML documentation for all .proto files in the proto directory into doc/index.html, type:

protoc --doc_out=./doc --doc_opt=html,index.html proto/*.proto

The plugin executable must be in PATH for this to work.

Using a precompiled binary

Alternatively, you can specify a pre-built/not in PATH binary using the --plugin option.

protoc \
  --plugin=protoc-gen-doc=./protoc-gen-doc \
  --doc_out=./doc \
  --doc_opt=html,index.html \
  proto/*.proto

With a Custom Template

If you'd like to use your own template, simply use the path to the template file rather than the type.

protoc --doc_out=./doc --doc_opt=/path/to/template.tmpl,index.txt proto/*.proto

For information about the available template arguments and functions, see Custom Templates. If you just want to customize the look of the HTML output, put your CSS in stylesheet.css next to the output file and it will be picked up.

Writing Documentation

Messages, Fields, Services (and their methods), Enums (and their values), Extensions, and Files can be documented. Generally speaking, comments come in 2 forms: leading and trailing.

Leading comments

Leading comments can be used everywhere.

/**
 * This is a leading comment for a message
*/
message SomeMessage {
  // this is another leading comment
  string value = 1;
}

NOTE: File level comments should be leading comments on the syntax directive.

Trailing comments

Fields, Service Methods, Enum Values and Extensions support trailing comments.

enum MyEnum {
  DEFAULT = 0; // the default value
  OTHER   = 1; // the other value
}

Excluding comments

If you want to have some comment in your proto files, but don't want them to be part of the docs, you can simply prefix the comment with @exclude.

Example: include only the comment for the id field

/**
 * @exclude
 * This comment won't be rendered
 */
message ExcludedMessage {
  string id   = 1; // the id of this message.
  string name = 2; // @exclude the name of this message

  /* @exclude the value of this message. */
  int32 value = 3;
}

Check out the example protos to see all the options.

Output Example

With the input .proto files

the plugin gives the output

Check out the examples task in the Makefile to see how these were generated.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].