Skip to content

Commit

Permalink
*: Add go-swagger as dependency, generate spec from server files
Browse files Browse the repository at this point in the history
This change adds a dependency on `go-swagger/go-swagger`, and
uses it as part of `make generate` to regenerate the swagger
spec in `docs/generated/swagger/spec.json`, whenever
one of the APIv2 files in `pkg/server/` are changed.

The spec, once generated, can be served as docs using
the command:

    bin/swagger serve -p 8080 ./docs/generated/swagger/spec.json

Release note (build change): Adds go-swagger dependency, updates
Makefile to call it to rebuild spec in docs/generated/swagger/
which will eventually be used for API docs.
  • Loading branch information
itsbilal committed Mar 24, 2021
1 parent 0450da3 commit 66acfc5
Show file tree
Hide file tree
Showing 13 changed files with 2,018 additions and 108 deletions.
509 changes: 429 additions & 80 deletions DEPS.bzl

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ bin/.bootstrap: $(GITHOOKS) vendor/modules.txt | bin/.submodules-initialized
github.com/cockroachdb/gostdlib/x/tools/cmd/goimports \
github.com/cockroachdb/stress \
github.com/goware/modvendor \
github.com/go-swagger/go-swagger/cmd/swagger \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/kevinburke/go-bindata/go-bindata \
github.com/kisielk/errcheck \
Expand Down Expand Up @@ -827,6 +828,9 @@ WKTPARSER_TARGETS = \

PROTOBUF_TARGETS := bin/.go_protobuf_sources bin/.gw_protobuf_sources

SWAGGER_TARGETS := \
docs/generated/swagger/spec.json

DOCGEN_TARGETS := \
bin/.docgen_bnfs \
bin/.docgen_functions \
Expand Down Expand Up @@ -1155,7 +1159,7 @@ dupl: bin/.bootstrap

.PHONY: generate
generate: ## Regenerate generated code.
generate: protobuf $(DOCGEN_TARGETS) $(OPTGEN_TARGETS) $(LOG_TARGETS) $(SQLPARSER_TARGETS) $(WKTPARSER_TARGETS) $(SETTINGS_DOC_PAGES) bin/langgen bin/terraformgen
generate: protobuf $(DOCGEN_TARGETS) $(OPTGEN_TARGETS) $(LOG_TARGETS) $(SQLPARSER_TARGETS) $(WKTPARSER_TARGETS) $(SETTINGS_DOC_PAGES) $(SWAGGER_TARGETS) bin/langgen bin/terraformgen
$(GO) generate $(GOFLAGS) $(GOMODVENDORFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' $(PKG)
$(MAKE) execgen

Expand Down Expand Up @@ -1595,6 +1599,8 @@ docs/generated/logging.md: pkg/util/log/gen/main.go pkg/util/log/logpb/log.proto
$(GO) run $(GOMODVENDORFLAGS) $^ logging.md $@.tmp || { rm -f $@.tmp; exit 1; }
mv -f $@.tmp $@

docs/generated/swagger/spec.json: pkg/server/api*.go bin/.bootstrap

pkg/util/log/severity/severity_generated.go: pkg/util/log/gen/main.go pkg/util/log/logpb/log.proto
$(GO) run $(GOMODVENDORFLAGS) $^ severity.go $@.tmp || { rm -f $@.tmp; exit 1; }
mv -f $@.tmp $@
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ go_repository(
patches = [
"@cockroach//build/patches:com_github_golang_protobuf.patch",
],
sum = "h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=",
version = "v1.4.2",
sum = "h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=",
version = "v1.4.3",
)

go_repository(
name = "org_golang_google_genproto",
build_file_proto_mode = "disable_global",
importpath = "google.golang.org/genproto",
sum = "h1:jB9+PJSvu5tBfmJHy/OVapFdjDF3WvpkqRhxqrmzoEU=",
version = "v0.0.0-20200218151345-dad8c97a84f5",
sum = "h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8=",
version = "v0.0.0-20200825200019-8632dd797987",
)

# Load the go dependencies and invoke them.
Expand Down
1 change: 1 addition & 0 deletions build/variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ define VALID_VARS
STYLINT
SUBTESTS
SUFFIX
SWAGGER_TARGETS
TAGS
TAR
TARGET
Expand Down
1 change: 1 addition & 0 deletions docs/generated/swagger/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains spec files generated by go-swagger.
Loading

0 comments on commit 66acfc5

Please sign in to comment.