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

Backport PR #2741 to release/v1.7 for change symlink API documents #2776

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ PROTOS_V1 := $(eval PROTOS_V1 := $(filter apis/proto/v1/%.proto,$(PROTOS)))$(PRO
PBGOS = $(PROTOS:apis/proto/%.proto=apis/grpc/%.pb.go)
SWAGGERS = $(PROTOS:apis/proto/%.proto=apis/swagger/%.swagger.json)
PBDOCS = $(ROOTDIR)/apis/docs/v1/docs.md
PROTO_VALD_APIS := $(eval PROTO_VALD_APIS := $(filter $(ROOTDIR)/apis/proto/v1/vald/%.proto,$(PROTOS)))$(PROTO_VALD_APIS)
PROTO_VALD_API_DOCS := $(PROTO_VALD_APIS:$(ROOTDIR)/apis/proto/v1/vald/%.proto=$(ROOTDIR)/apis/docs/v1/%.md)
PROTO_MIRROR_APIS := $(eval PROTO_MIRROR_APIS := $(filter $(ROOTDIR)/apis/proto/v1/mirror/%.proto,$(PROTOS)))$(PROTO_MIRROR_APIS)
PROTO_MIRROR_API_DOCS := $(PROTO_MIRROR_APIS:$(ROOTDIR)/apis/proto/v1/mirror/%.proto=$(ROOTDIR)/apis/docs/v1/%.md)

LDFLAGS = -static -fPIC -pthread -std=gnu++23 -lstdc++ -lm -z relro -z now -flto=auto -march=native -mtune=native -fno-plt -Ofast -fvisibility=hidden -ffp-contract=fast -fomit-frame-pointer -fmerge-all-constants -funroll-loops -falign-functions=32 -ffunction-sections -fdata-sections

Expand Down
8 changes: 8 additions & 0 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,11 @@ define gen-deadlink-checker
$$BIN_PATH -path $3 -ignore-path $4 -format $5 $1; \
rm -rf $$BIN_PATH
endef

define gen-api-document
buf generate --template=apis/docs/buf.gen.tmpl.yaml --path $2
cat apis/docs/v1/payload.md.tmpl apis/docs/v1/_doc.md.tmpl > apis/docs/v1/doc.md.tmpl; \
buf generate --template=apis/docs/buf.gen.doc.yaml --path $2; \
mv $(ROOTDIR)/apis/docs/v1/doc.md $1; \
rm apis/docs/v1/*doc.md.tmpl
endef
31 changes: 28 additions & 3 deletions Makefile.d/proto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
## build protobufs
proto/all: \
proto/deps \
proto/gen
proto/gen/code \
proto/gen/api/docs

.PHONY: proto/clean
## clean proto artifacts
Expand All @@ -34,30 +35,54 @@ proto/paths/print:
.PHONY: proto/deps
## install protobuf dependencies
proto/deps: \
$(GOBIN)/buf
$(GOBIN)/buf \
$(GOBIN)/protoc-gen-doc

.PHONY: proto/clean/deps
## uninstall all protobuf dependencies
proto/clean/deps:
rm -rf $(GOBIN)/buf
rm -rf $(GOBIN)/protoc-gen-doc

$(GOBIN)/buf:
$(call go-install, github.com/bufbuild/buf/cmd/buf)

$(GOBIN)/protoc-gen-doc:
$(call go-install, github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc)

$(ROOTDIR)/apis/proto/v1/rpc/errdetails/error_details.proto:
curl -fsSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/error_details.proto -o $(ROOTDIR)/apis/proto/v1/rpc/errdetails/error_details.proto
sed -i -e "s/package google.rpc/package rpc.v1/" $(ROOTDIR)/apis/proto/v1/rpc/errdetails/error_details.proto
sed -i -e "s%google.golang.org/genproto/googleapis/rpc/errdetails;errdetails%$(GOPKG)/apis/grpc/v1/rpc/errdetails%" $(ROOTDIR)/apis/proto/v1/rpc/errdetails/error_details.proto
sed -i -e "s/com.google.rpc/org.vdaas.vald.api.v1.rpc/" $(ROOTDIR)/apis/proto/v1/rpc/errdetails/error_details.proto

proto/gen: \
proto/gen/code: \
$(PROTOS) \
proto/deps
@$(call green, "generating pb.go and swagger.json files and documents for API v1...")
buf format -w
buf generate
make proto/replace

proto/gen/api/docs: \
proto/gen/api/docs/payload \
$(PROTO_VALD_API_DOCS) \
$(PROTO_MIRROR_API_DOCS)

proto/gen/api/docs/payload: $(ROOTDIR)/apis/docs/v1/payload.md.tmpl

$(ROOTDIR)/apis/docs/v1/payload.md.tmpl: $(ROOTDIR)/apis/proto/v1/payload/payload.proto $(ROOTDIR)/apis/docs/v1/payload.tmpl
@$(call green,"generating payload v1...")
buf generate --template=apis/docs/buf.gen.payload.yaml

$(ROOTDIR)/apis/docs/v1/%.md: $(ROOTDIR)/apis/proto/v1/vald/%.proto $(ROOTDIR)/apis/docs/v1/payload.md.tmpl $(ROOTDIR)/apis/docs/v1/doc.tmpl
@$(call green,"generating documents for API v1...")
@$(call gen-api-document,$@,$(subst $(ROOTDIR)/,,$<))

$(ROOTDIR)/apis/docs/v1/mirror.md: $(ROOTDIR)/apis/proto/v1/mirror/mirror.proto $(ROOTDIR)/apis/docs/v1/payload.md.tmpl $(ROOTDIR)/apis/docs/v1/doc.tmpl
@$(call green,"generating documents for API v1...")
@$(call gen-api-document,$@,$(subst $(ROOTDIR)/,,$<))

proto/replace:
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs -P$(CORES) sed -i -E "s%google.golang.org/grpc/codes%$(GOPKG)/internal/net/grpc/codes%g"
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs -P$(CORES) sed -i -E "s%google.golang.org/grpc/status%$(GOPKG)/internal/net/grpc/status%g"
Expand Down
27 changes: 27 additions & 0 deletions apis/docs/buf.gen.doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version: v2
managed:
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
override:
- file_option: go_package_prefix
value: github.com/vdaas/vald/apis/grpc
plugins:
- local: protoc-gen-doc
out: apis/docs/v1
opt: apis/docs/v1/doc.md.tmpl,doc.md
29 changes: 29 additions & 0 deletions apis/docs/buf.gen.payload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version: v2
managed:
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
override:
- file_option: go_package_prefix
value: github.com/vdaas/vald/apis/grpc
plugins:
- local: protoc-gen-doc
out: apis/docs/v1
opt: apis/docs/v1/payload.tmpl,payload.md.tmpl
inputs:
- proto_file: apis/proto/v1/payload/payload.proto
27 changes: 27 additions & 0 deletions apis/docs/buf.gen.tmpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <vald@vdaas.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version: v2
managed:
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
override:
- file_option: go_package_prefix
value: github.com/vdaas/vald/apis/grpc
plugins:
- local: protoc-gen-doc
out: apis/docs/v1
opt: apis/docs/v1/doc.tmpl,_doc.md.tmpl
66 changes: 66 additions & 0 deletions apis/docs/v1/doc.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- range .Files -}}
{{- range .Services -}}
{{- $descs := dict -}}
{{- range $desc := (splitList "---\n" .Description) -}}
{{- $lines := splitList "\n" $desc -}}
{{- $_ := set $descs (first $lines) (join "\n" (rest $lines)) -}}
{{- end -}}
# Vald {{ .Name }} APIs

## Overview

{{ if hasKey $descs "Overview" }}{{ $descs.Overview | trim }}{{ end }}

```rpc
service {{.Name}} {

{{ range .Methods }} rpc {{ .Name }}({{ .RequestFullType }}) returns ({{ .ResponseFullType }}) {}
{{ end }}
}
```

{{ range .Methods }}

{{- $descs := dict -}}
{{- range $desc := (splitList "---\n" .Description) -}}
{{- $lines := splitList "\n" $desc -}}
{{- $_ := set $descs (first $lines) (join "\n" (rest $lines)) -}}
{{- end -}}
## {{ .Name }} RPC

{{ if hasKey $descs "Overview" }}{{ $descs.Overview | trim }}{{ end }}

### Input

- the scheme of `{{ .RequestFullType }}`

```rpc
{{ printf "{{- template \"scheme:%s\" }}\n" .RequestFullType }}
```
{{ printf "{{ template \"field:%s\" }}" .RequestFullType }}
### Output

- the scheme of `{{ .ResponseFullType }}`

```rpc
{{ printf "{{- template \"scheme:%s\" }}\n" .ResponseFullType }}
```
{{ printf "{{ template \"field:%s\" }}" .ResponseFullType }}
{{ if hasKey $descs "Status Code" }}
### Status Code

| code | description |
| :--: | :---------------- |
{{ pluck "Status Code" $descs | first | trim }}

Please refer to [Response Status Code](../status.md) for more details.
{{ end }}
{{ if hasKey $descs "Troubleshooting" }}
### Troubleshooting

{{ pluck "Troubleshooting" $descs | first | trim }}
{{ end }}

{{- end -}}
{{- end -}}
{{- end -}}
Loading
Loading