Skip to content

Commit

Permalink
docs: generate swagger docs w/ bazel
Browse files Browse the repository at this point in the history
Also build in CI as well as `dev generate docs`.

Closes #77395.

Release note: None
  • Loading branch information
rickystewart committed Mar 8, 2022
1 parent da050a4 commit db58cf6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/generated/bazel_targets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ documentation. Lines not beginning with // should be ignored.
//docs/generated/settings:settings_for_tenants
//docs/generated/sql
//docs/generated/sql/bnf
//docs/generated/swagger
26 changes: 26 additions & 0 deletions docs/generated/swagger/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@io_bazel_rules_go//go:def.bzl", "go_path")

genrule(
name = "swagger",
srcs = [
":swagger_go_path",
],
outs = ["spec.json"],
cmd = """
GO_REL_PATH=`dirname $(location @go_sdk//:bin/go)`
GO_ABS_PATH=`cd $$GO_REL_PATH && pwd`
env PATH=$$GO_ABS_PATH HOME=$(GENDIR) GOPATH=$$(cd $(location :swagger_go_path) && pwd) GO111MODULE=off \
$(location @com_github_go_swagger_go_swagger//cmd/swagger) generate spec -w $(location :swagger_go_path)/src/github.com/cockroachdb/cockroach/pkg --scan-models -t bazel -o $@
""",
exec_tools = [
"@com_github_go_swagger_go_swagger//cmd/swagger",
"@go_sdk//:bin/go",
],
)

go_path(
name = "swagger_go_path",
deps = [
"//pkg/server",
],
)
1 change: 1 addition & 0 deletions pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var buildTargetMapping = map[string]string{
"short": "//pkg/cmd/cockroach-short:cockroach-short",
"staticcheck": "@co_honnef_go_tools//cmd/staticcheck:staticcheck",
"stress": stressTarget,
"swagger": "@com_github_go_swagger_go_swagger//cmd/swagger:swagger",
"workload": "//pkg/cmd/workload:workload",
}

Expand Down
1 change: 1 addition & 0 deletions pkg/gen/docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ DOCS_SRCS = [
"//docs/generated/sql:functions.md",
"//docs/generated/sql:operators.md",
"//docs/generated/sql:window_functions.md",
"//docs/generated/swagger:spec.json",
"//docs/generated:eventlog.md",
"//docs/generated:logformats.md",
"//docs/generated:logging.md",
Expand Down

0 comments on commit db58cf6

Please sign in to comment.