Skip to content

Commit

Permalink
feat: gen swagger doc
Browse files Browse the repository at this point in the history
+ refactor make generate for go
  • Loading branch information
moul committed Sep 27, 2019
1 parent ca84e31 commit c70a7b4
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 129 deletions.
13 changes: 6 additions & 7 deletions .circleci/config.yml
Expand Up @@ -35,15 +35,14 @@ jobs:
- docker/build:
image: berty/berty
go-generate:
working_directory: /go/src/berty.tech/go
working_directory: /go/src/berty.tech
docker:
- image: bertytech/protoc:16
- image: bertytech/protoc:17
steps:
- checkout:
path: /go/src/berty.tech
- run: go mod vendor
- run: rm -f gen.sum && make generate_local
- run: make tidy
- checkout
- run: find . -name gen.sum -delete
- run: cd go && make generate_local && make tidy
- run: cd docs && make generate_local
- run: |
git status | cat
git diff -w | cat
Expand Down
4 changes: 4 additions & 0 deletions .gitattributes
Expand Up @@ -5,6 +5,10 @@
vendor/* linguist-vendored
*/vendor/* linguist-vendored
client/common/openssl/built/* linguist-vendored
gen.sum linguist-generated
go.mod linguist-generated
go.sum linguist-generated
*.swagger.json linguist-generated
*.gen.go linguist-generated
*.gen.yml linguist-generated
*.gen.graphql linguist-generated
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
gen.sum.tmp
# berty package
/crew/
/depviz/
Expand Down
16 changes: 16 additions & 0 deletions Makefile
@@ -0,0 +1,16 @@
.PHONY: all
all: generate test

.PHONY: test
test:
cd go; make test

.PHONY: generate
generate:
cd go; make generate
cd docs; make generate

.PHONY: clean
clean:
cd go; make clean
cd docs; make clean
7 changes: 2 additions & 5 deletions api/bertyprotocol.proto
Expand Up @@ -2,14 +2,11 @@ syntax = "proto3";

option go_package = "berty.tech/go/pkg/bertyprotocol";

import "google/api/annotations.proto";
import "google/protobuf/descriptor.proto";

// type Client struct

// c, err := ClientNew(&Config{})

service ClientManager {
rpc CurrentDeviceExportData (CurrentDeviceExportDataRequest) returns (CurrentDeviceExportDataReply);
rpc CurrentDeviceExportData (CurrentDeviceExportDataRequest) returns (CurrentDeviceExportDataReply) { option (google.api.http) = {post: "/current-device/export-data"}; };
rpc CurrentDeviceGetConfiguration (CurrentDeviceGetConfigurationRequest) returns (CurrentDeviceGetConfigurationReply);
}

Expand Down
34 changes: 34 additions & 0 deletions docs/Makefile
@@ -0,0 +1,34 @@
##
## Code gen
##

PROTOS_SRC := $(wildcard ../api/*.proto) $(wildcard ../api/internal/*.proto)
GEN_SRC := $(PROTOS_SRC) Makefile
GEN_SUM := gen.sum

.PHONY: clean
clean:
rm -f gen.sum $(wildcard *.swagger.json) $(wildcard *.swagger.yaml)

.PHONY: generate
generate: gen.sum
$(GEN_SUM): $(GEN_SRC)
shasum $(GEN_SRC) | sort > $(GEN_SUM).tmp
diff -q $(GEN_SUM).tmp $(GEN_SUM) || ( \
set -e; \
(set -e; cd ../go && GO111MODULE=on go mod vendor); \
docker run \
--user=`id -u` \
--volume="$(PWD)/..:/go/src/berty.tech" \
--workdir="/go/src/berty.tech/docs" \
--entrypoint="sh" \
--rm \
bertytech/protoc:17 \
-xec 'make generate_local' \
)

.PHONY: generate_local
generate_local:
protoc -I ../api:../go/vendor:/protobuf --swagger_out=logtostderr=true:. ../api/bertyprotocol.proto
shasum $(GEN_SRC) | sort > $(GEN_SUM).tmp
mv $(GEN_SUM).tmp $(GEN_SUM)
277 changes: 277 additions & 0 deletions docs/bertyprotocol.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions docs/gen.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c70a7b4

Please sign in to comment.