pseudomuto / protoc-gen-doc

Documentation generator plugin for Google Protocol Buffers
MIT License
2.66k stars 463 forks source link

Support message field options in generated documents #535

Open toniwe opened 6 months ago

toniwe commented 6 months ago

Hi, thanks for providing this plugin! Currently, I see no way to include field options (custom or standard ones) in the generated documents.

Briefly looking at the code, there only seem to be two options checked (deprecated and idempotency_level): https://github.com/pseudomuto/protoc-gen-doc/blob/df9dd4078971bb01d06bcd88130a7b5309348be0/template.go#L109-L121

https://github.com/pseudomuto/protoc-gen-doc/issues/425 might be somewhat similar, but this also includes standard options in proto3. json_name would be such an option (see https://protobuf.dev/programming-guides/proto3/#json ) which was already mentioned in a closed issue https://github.com/pseudomuto/protoc-gen-doc/issues/17#issuecomment-282540156

Is there any way to include custom field options or official ones such as json_name in the current version 1.5.1? Is this feature planned or already worked on by any chance?

Quick reproduction example (I used the gradle plugin variant with a custom template file):

syntax = "proto3";

import "google/protobuf/descriptor.proto";

extend google.protobuf.FieldOptions {
  optional bool myFlag = 50001;
}

message MyMessage {
  string test = 1 [json_name = "TEST"];
  string deprecatedTest = 2 [deprecated = true];
  string customTest = 3 [(myFlag) = true];
  string mixedTest = 4 [json_name = "TEST_MIXED", deprecated = true, (myFlag) = true];
}

The template:

{{range .Files}}
{{range .Messages}}
{{range .Fields}}

Options of field {{.Name}}: {{.Options}}

{{end}}
{{end}}
{{end}}

Output:

Options of field test: map[]
Options of field deprecatedTest: map[deprecated:true]
Options of field customTest: map[]
Options of field mixedTest: map[deprecated:true]

While i would expect something like:

Options of field test: map[json_name:TEST]
Options of field deprecatedTest: map[deprecated:true]
Options of field customTest: map[myFlag:true]
Options of field mixedTest: map[json_name:TEST_MIXED,deprecated:true,myFlag:true]