Skip to content

Commit

Permalink
work on adding to BSR
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Jul 18, 2024
1 parent c5a4e45 commit 5b5e2ef
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 55 deletions.
16 changes: 16 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
modules:
- path: internal/apiproto
name: buf.build/centrifugal/apiproto
excludes:
- internal/apiproto/swagger
- path: internal/unigrpc/unistream
name: buf.build/centrifugal/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.
File renamed without changes.
File renamed without changes.
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 5b5e2ef

Please sign in to comment.