Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support message field options in generated documents #535

Open
toniwe opened this issue May 21, 2024 · 0 comments
Open

Support message field options in generated documents #535

toniwe opened this issue May 21, 2024 · 0 comments

Comments

@toniwe
Copy link

toniwe commented May 21, 2024

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant