Skip to content

Support message field options in generated documents #535

@toniwe

Description

@toniwe

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):

protoc-gen-doc/template.go

Lines 109 to 121 in df9dd40

func extractOptions(opts commonOptions) map[string]interface{} {
out := make(map[string]interface{})
if opts.GetDeprecated() {
out["deprecated"] = true
}
switch opts := opts.(type) {
case *descriptor.MethodOptions:
if opts != nil && opts.IdempotencyLevel != nil {
out["idempotency_level"] = opts.IdempotencyLevel.String()
}
}
return out
}

#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 #17 (comment)

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]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @toniwe

        Issue actions

          Support message field options in generated documents · Issue #535 · pseudomuto/protoc-gen-doc