-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protoc-gen-apidocs: Separate hugo-specific output
- Loading branch information
Showing
2 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
{{/*************************************************************** | ||
Markdown template for protoc-gen-apidocs | ||
|
||
This template is rendered once per incoming .proto file and | ||
defines the resulting output documentation. | ||
|
||
This file is organized into blocks via the go template "define" | ||
function and they are executed with the "template" function. | ||
***************************************************************/}} | ||
|
||
{{/*************************************************************** | ||
Main output block | ||
***************************************************************/}} | ||
{{define "output" -}} | ||
|
||
--- | ||
title: {{ .Desc.Package }} | ||
description: API Specification for the {{ .Desc.Package }} package. | ||
--- | ||
|
||
<a name="{{.Desc.Path |base | anchor}}"></a><p align="right"><a href="#top">Top</a></p> | ||
|
||
<!-- begin services --> | ||
{{range .Services}} | ||
{{template "service" .}} | ||
{{end}} | ||
<!-- begin services --> | ||
|
||
{{ range .Messages }} | ||
{{template "message" .}} | ||
{{end}} <!-- end messages --> | ||
|
||
<!-- begin file-level enums --> | ||
{{range .Enums}} | ||
{{template "enum" .}} | ||
{{end}} <!-- end file-level enums --> | ||
|
||
<!-- begin file-level extensions --> | ||
{{if .Extensions}} | ||
<a name="{{.Desc.Path |base | anchor}}-extensions"></a> | ||
|
||
### Extensions | ||
| Extension | Type | Extension Point | Number | Description | | ||
| --------- | ---- | ---- | ------ | ----------- | | ||
{{range .Extensions -}} | ||
| {{.Desc.Name}} | {{.Desc.FullName}} | {{ .Extendee | message_type }} | {{.Desc.Number}} | {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr}} | | ||
{{end}} | ||
{{end}} <!-- end file-level extensions --> | ||
|
||
{{end}} | ||
|
||
|
||
{{/*************************************************************** | ||
Service template | ||
***************************************************************/}} | ||
{{define "service"}} | ||
<a name="{{.Desc.FullName | anchor}}"></a> | ||
|
||
### {{.Desc.Name}} | ||
|
||
{{.Comments.Leading | description}} | ||
{{.Comments.Trailing | description}} | ||
|
||
| Method Name | Request Type | Response Type | Description | | ||
| ----------- | ------------ | ------------- | ------------| | ||
{{range .Methods -}} | ||
| {{.Desc.Name}} | [{{ .Input | message_type }}](#{{ .Input | full_message_type | anchor }}) | [{{ .Output | message_type }}](#{{ .Output | full_message_type | anchor }}){{if .Desc.IsStreamingServer}} stream{{end}} | {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr}} | | ||
{{end}} | ||
{{end}} | ||
|
||
|
||
|
||
{{/*************************************************************** | ||
Message template | ||
***************************************************************/}} | ||
{{define "message"}} | ||
<a name="{{.Desc.FullName | anchor}}"></a> | ||
|
||
### {{.Desc.Name}} | ||
|
||
{{.Comments.Leading | description}} | ||
{{.Comments.Trailing | description}} | ||
|
||
{{if .Fields}} | ||
| Field | Type | Description | | ||
| ----- | ---- | ----------- | | ||
{{range .Fields}}{{ if (not .Desc.ContainingOneof) }}{{template "field" .}}{{end}}{{end}} | ||
{{- end -}} | ||
{{range .Oneofs}}{{template "oneof" .}}{{end}} | ||
|
||
{{if .Extensions}} | ||
| Extension | Type | Base | Number | Description | | ||
| --------- | ---- | ---- | ------ | ----------- | | ||
{{range .Extensions -}} | ||
| {{.Desc.Name}} | {{.Desc | long_name}} | {{.Parent | message_type}} | {{.Desc.Number}} | {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr}} | | ||
{{end}} | ||
{{end}} | ||
|
||
{{ range .Messages }} | ||
{{template "message" .}} | ||
{{end}} <!-- end nested messages --> | ||
|
||
{{range .Enums}} | ||
{{template "enum" .}} | ||
{{end}} <!-- end nested enums --> | ||
|
||
{{end}} | ||
|
||
{{/*************************************************************** | ||
Field template | ||
***************************************************************/}} | ||
{{define "field" -}} | ||
| {{.Desc.Name}}{{ if .Desc.IsList }}[]{{ end }} | | ||
{{- if (or (is_primitive .) (is_google_type .)) -}} | ||
{{ field_type . }} | ||
{{- else -}} | ||
[{{ .| field_type }}]({{ hugo_type_link . }}) | ||
{{- end -}} | ||
| {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr }} | | ||
{{end}} | ||
|
||
{{/*************************************************************** | ||
Oneof template | ||
This is kind of gross since GFM doesn't support colspan. | ||
***************************************************************/}} | ||
{{define "oneof" -}} | ||
|<tr><td colspan=2>Union field `{{ .Desc.Name }}`. {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr }} `{{ .Desc.Name }}` can be only one of the following:</td></tr>| | ||
{{range .Fields}}{{template "field" .}}{{end}} | ||
{{end}} | ||
|
||
{{/*************************************************************** | ||
Enum template | ||
***************************************************************/}} | ||
{{define "enum" }} | ||
<a name="{{.Desc.FullName | anchor}}"></a> | ||
|
||
### {{.Desc | long_name}} | ||
{{.Comments.Leading | description}} | ||
{{.Comments.Trailing | description}} | ||
|
||
| Name | Number | Description | | ||
| ---- | ------ | ----------- | | ||
{{range .Values -}} | ||
| {{.Desc.Name}} | {{.Desc.Number}} | {{ .Comments.Leading | description | nobr}} {{ .Comments.Trailing | description | nobr}} | | ||
{{end}} | ||
{{end}} |