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

Make apitodoc support Ptrs and update docs #288

Merged
merged 3 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/apitodoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func iterate(output io.Writer, data interface{}, indent int) {
if dataType == reflect.Slice || dataType == reflect.Map {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some commented out statements in this function (lines 33, 44). Should these be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't write them. But, it seems that line 33 is used in the commented out debug code in lines 36 and 41.
I don't see the point of line 44. I'll remove it.

// DEBUG code: fmt.Fprintf(output, "%s %s <-- %s \n",strings.Repeat(" ",4*indent),dataTypeName,dataType )
zeroElement := reflect.Zero(reflect.ValueOf(data).Type().Elem()).Interface()
iterate(output, zeroElement, indent+1)
iterate(output, zeroElement, newIndent)
return
} else if dataType == reflect.Struct {
// DEBUG code: fmt.Fprintf(output,"%s %s <-- %s \n",strings.Repeat(" ",4*indent),dataTypeName,dataType )
Expand All @@ -52,7 +52,7 @@ func iterate(output io.Writer, data interface{}, indent int) {
enumType := api.GetEnumReflectionTypeByFieldName(fieldEnumTag)
zeroElement := reflect.Zero(enumType).Interface()
fmt.Fprintf(output, "%s %s: (enum) %s\n", strings.Repeat(" ", 4*newIndent), fieldName, fieldDocTag)
iterate(output, zeroElement, indent+1)
iterate(output, zeroElement, newIndent)
continue
}
if fieldDocTag != "" {
Expand All @@ -69,6 +69,12 @@ func iterate(output io.Writer, data interface{}, indent int) {
}
}
return
} else if dataType == reflect.Ptr {
elemType := reflect.TypeOf(data).Elem()
zeroElement := reflect.Zero(elemType).Interface()
// Since we only "converted" Ptr to Struct and the actual output is done in the next iteration, we call
// iterate() with the same `indent` as the current level
iterate(output, zeroElement, indent)
}
}

Expand Down
13 changes: 7 additions & 6 deletions cmd/apitodoc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
)

type DocTags struct {
Title string `yaml:"title" doc:"##title"`
Field string `yaml:"field" doc:"field"`
Slice []string `yaml:"slice" doc:"slice"`
Map map[string]string `yaml:"map" doc:"map"`
Sub DocSubTags `yaml:"sub" doc:"sub"`
Title string `yaml:"title" doc:"##title"`
Field string `yaml:"field" doc:"field"`
Slice []string `yaml:"slice" doc:"slice"`
Map map[string]string `yaml:"map" doc:"map"`
Sub DocSubTags `yaml:"sub" doc:"sub"`
SubPtr *DocSubTags `yaml:"subPtr" doc:"subPtr"`
}

type DocSubTags struct {
Expand All @@ -38,7 +39,7 @@ type DocSubTags struct {

func Test_iterate(t *testing.T) {
output := new(bytes.Buffer)
expected := "\n##title\n<pre>\n title:\n</pre> field: field\n slice: slice\n map: map\n sub: sub\n subField: subField\n"
expected := "\n##title\n<pre>\n title:\n</pre> field: field\n slice: slice\n map: map\n sub: sub\n subField: subField\n subPtr: subPtr\n subField: subField\n"
iterate(output, DocTags{}, 0)
require.Equal(t, expected, output.String())
}
Expand Down
13 changes: 10 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ Following is the supported API format for prometheus encode:
prefix: prefix added to each metric name
expiryTime: seconds of no-flow to wait before deleting prometheus data item
tls: TLS configuration for the prometheus endpoint
enable: set to true to enable tls for the prometheus endpoint
certFile: path to the certificate file
keyFile: path to the key file
certPath: path to the certificate file
keyPath: path to the key file
</pre>
## Kafka encode API
Following is the supported API format for kafka encode:
Expand All @@ -42,6 +41,10 @@ Following is the supported API format for kafka encode:
batchBytes: limit the maximum size of a request in bytes before being sent to a partition
batchSize: limit on how many messages will be buffered before being sent to a partition
tls: TLS client configuration (optional)
insecureSkipVerify: skip client verifying the server's certificate chain and host name
caCertPath: path to the CA certificate
userCertPath: path to the user certificate
userKeyPath: path to the user private key
</pre>
## Ingest collector API
Following is the supported API format for the NetFlow / IPFIX collector:
Expand Down Expand Up @@ -71,6 +74,10 @@ Following is the supported API format for the kafka ingest:
batchMaxLen: the number of accumulated flows before being forwarded for processing
commitInterval: the interval (in milliseconds) at which offsets are committed to the broker. If 0, commits will be handled synchronously.
tls: TLS client configuration (optional)
insecureSkipVerify: skip client verifying the server's certificate chain and host name
caCertPath: path to the CA certificate
userCertPath: path to the user certificate
userKeyPath: path to the user private key
</pre>
## Ingest GRPC from Network Observability eBPF Agent
Following is the supported API format for the Network Observability eBPF ingest:
Expand Down