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

feat(docs) prepare api docs generation #1741

Merged
merged 5 commits into from
Apr 7, 2021

Conversation

bartsmykla
Copy link
Contributor

Summary

Prerequisites (from repository root path)

cd api
make install/protoc-gen-validate

To mark a file as a file containing policy resource, you should import config.proto and provide option (doc.config) proto extension. For example by adding to file api/mesh/v1alpha1/health_check.proto lines below:

import "config.proto";

option (doc.config) = {
  type: Policy,
  name: "HealthCheck",
  file_name: "health-check"
};

after calling make generate/docs from api there should be generated file health-check.md in the same directory.

Id you want to change the output path for generated files, you can specify a variable called DOCS_OUTPUT_PATH. For example:

DOCS_OUTPUT_PATH=/tmp/kumadocs make generate/docs

it will generate markdown files in /tmp/kumadocs. The path can be absolute or relative

Every markdown file is generated from this template: https://github.com/kumahq/protoc-gen-kumadoc/blob/main/templates/policy.md.tpl and if you would like to test your own templates you should:

  1. clone protoc-gen-kumadoc repository

  2. make changes in template

  3. build plugin: go build . (use -o flag if you want to build the plugin in different output path)

  4. run make generate/docs with specified PLUGIN variable:

    PLUGIN=$(pwd)/protoc-gen-kumadoc make generate/docs

More configuration options for proto files can be found here: https://github.com/kumahq/protoc-gen-kumadoc/blob/main/proto/config.proto

  1. If you want to mark some field as required (all of them are marked as optional by default), you can use [(doc.required) = true]:

    message BackOff {
      google.protobuf.Duration base_interval = 1 [(doc.required) = true];
      google.protobuf.Duration max_interval = 2;
    }
  2. By default all proto "messages" in policy files are being generated as if there would be more than one policy in a file, so if you have more "messages" but only one is considered a real "policy", you can mark rest of them as hidden using option (doc.hide) = true;:

    message Foo {
      option (doc.hide) = true;
      ...
    }
    
    message Retry {
    ...

Signed-off-by: Bart Smykla <bartek@smykla.com>
@bartsmykla bartsmykla requested a review from a team as a code owner April 1, 2021 13:55
@nickolaev
Copy link
Contributor

Hmm, why not add the proto file changes in this PR too?

@Bradamant3
Copy link
Contributor

Can't speak to comment from @nickolaev but explanation of tool LGTM. This is awesome, can't wait to work with it when I'm back from time off!

Signed-off-by: Bart Smykla <bartek@smykla.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
@bartsmykla bartsmykla merged commit 9196f44 into kumahq:master Apr 7, 2021
@bartsmykla bartsmykla deleted the feat/docs-generation branch April 7, 2021 09:45
mergify bot pushed a commit that referenced this pull request May 6, 2021
* feat(docs) prepare api docs generation

Signed-off-by: Bart Smykla <bartek@smykla.com>

* feat(docs) mark policy proto files to gen. docs

Signed-off-by: Bart Smykla <bartek@smykla.com>
(cherry picked from commit 9196f44)

# Conflicts:
#	api/Makefile
bartsmykla added a commit that referenced this pull request May 6, 2021
* feat(docs) prepare api docs generation

Signed-off-by: Bart Smykla <bartek@smykla.com>

* feat(docs) mark policy proto files to gen. docs

Signed-off-by: Bart Smykla <bartek@smykla.com>
(cherry picked from commit 9196f44)
Signed-off-by: Bart Smykla <bartek@smykla.com>
bartsmykla added a commit that referenced this pull request May 6, 2021
* feat(docs) prepare api docs generation

Signed-off-by: Bart Smykla <bartek@smykla.com>

* feat(docs) mark policy proto files to gen. docs

Co-authored-by: Bart Smykla <bartek@smykla.com>
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

Successfully merging this pull request may close these issues.

None yet

4 participants