Skip to content

Commit

Permalink
Rename & Add OpenAPI Specification Generator (#107)
Browse files Browse the repository at this point in the history
* rename npm name to wechaty-grpc (#106)

* add grpc http annotations (wip)

* add grpc gateway image

* add swagger info annotation

* make payload dirty restful

* fix name

* add more restful endpoint definitions

* fix streaming methods

* better protoc tools installer script

* clean openapi scripts

* rename src/index -> src/mod

* generate proto js files with annotation

* 0.19.1
  • Loading branch information
huan authored Feb 20, 2021
1 parent 56c24b9 commit 5cabc93
Show file tree
Hide file tree
Showing 21 changed files with 496 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install Dependencies
run: |
npm install
npm run install:lint:protoc
npm run install:protoc
- name: Generate gRPC Stubs
run: npm run generate
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Dependencies
run: |
npm install
npm run install:lint:protoc
npm run install:protoc
- name: Generate gRPC Stubs
run: npm run generate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ csharp/Wechaty.Grpc/bin/
csharp/Wechaty.Grpc/nupkg/package/
csharp/Wechaty.Grpc/Properties

third-party/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ protoc \

> <https://github.com/improbable-eng/ts-protoc-gen>

## OpenAPI

![gRPC Gateway](docs/images/grpc-gateway-architecture.svg)

> Image credit: [grpc-gateway](https://grpc-ecosystem.github.io/grpc-gateway/)

## RESOURCES

### Documentation
Expand Down
1 change: 1 addition & 0 deletions docs/images/grpc-gateway-architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
EventResponse,
ContactAliasRequest,
// EventType,
} from '../src/'
} from '../src/mod'
import { StringValue } from 'google-protobuf/google/protobuf/wrappers_pb'

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EventType,
DingResponse,
EventRequest,
} from '../src/index'
} from '../src/mod'

// import { StringValue } from 'google-protobuf/google/protobuf/wrappers_pb'

Expand Down
1 change: 0 additions & 1 deletion openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
gen/
gateway
go.sum
35 changes: 17 additions & 18 deletions openapi/Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
PROTOC=protoc \
GENERATED_DIR:="${CURDIR}/../generated/"
THIRD_PARTY_DIR:="${CURDIR}/../third-party/"

PROTOC:=protoc \
-I ../proto/ \
-I ../proto/wechaty/ \
-I ${THIRD_PARTY_DIR} \
../proto/wechaty/puppet.proto \

.PHONY: all
all: clean generate reverse_proxy_server
all: generate

.PHONY: generate
generate:
${PROTOC} \
--openapiv2_out ${GENERATED_DIR} \
--openapiv2_opt logtostderr=true \
--openapiv2_opt generate_unbound_methods=true \

.PHONY: clean
clean:
rm -fr gen/*
rm -fr ${GENERATED_DIR}/*

.PHONY: install
install:
[ -d gen ] || mkdir gen
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
go mod tidy

.PHONY: generate
generate: gen_protobuf gen_gateway gen_openapi

.PHONY: gen_protobuf
gen_protobuf:
${PROTOC} \
--go_out ./gen/ --go_opt paths=source_relative \
--go-grpc_out ./gen/ --go-grpc_opt paths=source_relative \
../proto/wechaty/puppet.proto
--go_out ${GENERATED_DIR} --go_opt paths=source_relative \
--go-grpc_out ${GENERATED_DIR} --go-grpc_opt paths=source_relative \

.PHONY: gen_gateway
gen_gateway:
${PROTOC} \
--grpc-gateway_out ./gen/ \
--grpc-gateway_out ${GENERATED_DIR} \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt generate_unbound_methods=true \

.PHONY: gen_openapi
gen_openapi:
${PROTOC} \
--openapiv2_out ./gen/ \
--openapiv2_opt logtostderr=true \

4 changes: 3 additions & 1 deletion openapi/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# GO gRPC Gateway

gRPC Gateway: <https://github.com/grpc-ecosystem/grpc-gateway>
- gRPC Gateway: <https://github.com/grpc-ecosystem/grpc-gateway>
- Template: <https://github.com/johanbrandhorst/grpc-gateway-boilerplate>
5 changes: 3 additions & 2 deletions openapi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.16

require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.4.3
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/protobuf v3.15.0+incompatible // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.1.0
github.com/wechaty/go-grpc v0.18.12
github.com/wechaty/go-grpc v0.18.12 // indirect
google.golang.org/grpc v1.34.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.25.0
Expand Down
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"name": "@chatie/grpc",
"version": "0.18.12",
"description": "gRPC for Chatie",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.js",
"name": "wechaty-grpc",
"version": "0.19.1",
"description": "gRPC for Wechaty",
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.js",
"directories": {
"example": "examples",
"test": "tests"
},
"scripts": {
"clean": "shx rm -fr dist/* generated/*",
"dist": "npm run clean && npm run generate && tsc && shx mv generated/ dist/",
"dist": "npm-run-all clean generate && tsc && shx mv generated/ dist/",
"dist:py": "python3 setup.py sdist bdist_wheel",
"publish:py": "twine upload dist/*",
"example:server": "nodemon --exec ts-node examples/server.ts",
"example:client": "ts-node examples/client.ts",
"generate": "bash -x scripts/generate-stub.sh",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:proto",
"lint": "npm-run-all lint:es lint:ts lint:proto",
"lint:es": "eslint --ignore-pattern fixtures/ \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"",
"lint:ts": "tsc --noEmit",
"lint:proto": "bash -c 'protoc -I proto/wechaty --lint_out=. $(find proto/ -type f -name *.proto)'",
"install:lint:protoc": "bash -x scripts/install-protoc-gen-lint.sh",
"lint:proto": "bash -c 'protoc -I third-party -I proto/wechaty --lint_out=. $(find proto/ -type f -name *.proto)'",
"install:protoc": "bash -x scripts/install-protoc.sh",
"test": "npm run lint && npm run test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"pack": "npm pack"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Chatie/grpc.git"
"url": "git+https://github.com/wechaty/grpc.git"
},
"keywords": [
"grpc",
Expand All @@ -41,27 +41,28 @@
"author": "Huan LI <zixia@zixia.net>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/Chatie/grpc/issues"
"url": "https://github.com/wechaty/grpc/issues"
},
"homepage": "https://github.com/Chatie/grpc#readme",
"homepage": "https://github.com/wechaty/grpc#readme",
"dependencies": {
"grpc": "^1.24.2",
"google-protobuf": "^3.11.3"
"grpc": "^1.24.5",
"google-protobuf": "^3.15.1"
},
"devDependencies": {
"@chatie/eslint-config": "^0.12.1",
"@chatie/eslint-config": "^0.12.3",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.10.1",
"@types/google-protobuf": "^3.7.2",
"@chatie/tsconfig": "^0.14.1",
"@types/google-protobuf": "^3.7.4",
"@types/protobufjs": "^6.0.0",
"grpc-tools": "^1.8.0",
"grpc_tools_node_protoc_ts": "^5.0.0",
"grpc-tools": "^1.10.0",
"grpc_tools_node_protoc_ts": "^5.1.1",
"grpcc": "^1.1.3",
"nodemon": "^2.0.0",
"nodemon": "^2.0.7",
"npm-run-all": "^4.1.5",
"request": "^2.88.2",
"shx": "^0.3.2",
"ts-protoc-gen": "^0.13.0",
"shx": "^0.3.3",
"ts-protoc-gen": "^0.14.0",
"tstest": "^0.4.10"
},
"engines": {
Expand Down
Loading

0 comments on commit 5cabc93

Please sign in to comment.