Skip to content

Commit

Permalink
Publish Protobuf definitions to Buf Schema Registry (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Jul 28, 2024
1 parent ff39b8a commit 044eaff
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 61 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
with:
go-version: ${{ matrix.go-version }}

- uses: bufbuild/buf-setup-action@v1
with:
version: "1.34.0"

- name: Checkout code
uses: actions/checkout@v4

Expand Down Expand Up @@ -55,3 +59,7 @@ jobs:
env:
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
run: misc/scripts/release_packagecloud.sh

- uses: bufbuild/buf-push-action@v1
with:
buf_token: ${{ secrets.BUF_TOKEN }}
18 changes: 18 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: v2
modules:
- path: internal/apiproto
name: buf.build/centrifugo/apiproto
excludes:
- internal/apiproto/swagger
- path: internal/proxyproto
name: buf.build/centrifugo/proxyproto
- path: internal/unigrpc/unistream
name: buf.build/centrifugo/unistream
lint:
use:
- DEFAULT
ignore:
- internal/apiproto/swagger/api.swagger.proto
breaking:
use:
- FILE
55 changes: 1 addition & 54 deletions internal/apiproto/readme.md
Original file line number Diff line number Diff line change
@@ -1,54 +1 @@
## Generate HTTP API libraries from swagger spec:

```
git clone --depth 1 -b master https://github.com/swagger-api/swagger-codegen.git
cd swagger-codegen
cp /path/to/api.swagger.json ./api.swagger.json
```

### Go library:

```
./run-in-docker.sh generate -i api.swagger.json -l go -o /gen/out/go-centrifugo -DpackageName=centrifugo
ls out/go-centrifugo
```

Then:

```go
package main

import (
"context"
"fmt"
"net/http"
"time"

"test_project/centrifugo"
)

func main() {
httpClient := &http.Client{Transport: &http.Transport{
MaxIdleConnsPerHost: 100,
}, Timeout: time.Second}
client := centrifugo.NewAPIClient(&centrifugo.Configuration{
BasePath: "http://localhost:8000/api",
DefaultHeader: map[string]string{"Authorization": "apikey "},
HTTPClient: httpClient,
})
reply, resp, err := client.PublicationApi.CentrifugoApiPublish(context.Background(), centrifugo.PublishRequest{
Channel: "test",
Data: map[string]string{},
})
if err != nil {
panic(err)
}
if resp.StatusCode != 200 {
panic(resp.StatusCode)
}
if reply.Error_ != nil {
panic(reply.Error_.Message)
}
fmt.Println("ok")
}
```
Centrifugo server API Protobuf definitions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
{
"name": "push notification"
},
{
"name": "rate limiting"
},
{
"name": "batch"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
{
name: "push notification"
},
{
name: "rate limiting"
},
{
name: "batch"
}
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions misc/scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ fi

cd internal/apiproto
bash generate.sh
cd -

cd internal/apiproto/swagger
bash generate_swagger.sh
cd -

Expand Down
2 changes: 1 addition & 1 deletion misc/scripts/update_swagger_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cleanup_exit() {
}

git clone -c advice.detachedHead=false --depth 1 --branch v4.18.1 --single-branch https://github.com/swagger-api/swagger-ui.git "$TMP_WORK_DIR"
cp internal/apiproto/api.swagger.json "$TMP_WORK_DIR"/dist/swagger.json
cp internal/apiproto/swagger/api.swagger.json "$TMP_WORK_DIR"/dist/swagger.json

oldString="https://petstore.swagger.io/v2/"
newString="./"
Expand Down

0 comments on commit 044eaff

Please sign in to comment.