Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Protobuf definitions to Buf Schema Registry #863

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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
Loading