Skip to content

Commit 1979134

Browse files
authored
Switch to OAPI for codegen (#5)
* testing oapi codegen + updated spec * try oapi codegen * working generator * working client build with oapi
1 parent 5be3b5a commit 1979134

26 files changed

Lines changed: 63332 additions & 448396 deletions

README.md

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
11
# Cycle API Go Client
22

3-
_This is an auto-generated API client based on the [OpenAPI Spec for Cycle](https://github.com/cycleplatform/api-spec). Please do not open any PRs for the generated code under /client. If you have any questions on what changes are made in the latest version, please refer to the spec above._
3+
_This is an auto-generated API client based on the [OpenAPI Spec for Cycle](https://github.com/cycleplatform/api-spec). Please do not open any PRs for the generated code in `generated.go`. If you have any questions on what changes are made in the latest version, please refer to the spec above._
44

5-
## Setup
65

7-
Install Ogen
6+
## Usage
87

9-
`go install -v github.com/ogen-go/ogen/cmd/ogen@latest`
8+
`go get github.com/cycleplatform/api-client-go`
109

11-
## Generating
10+
Create a client
1211

13-
### Updating the spec
12+
```go
13+
package main
14+
15+
import (
16+
cycle "github.com/cycleplatform/api-client-go"
17+
)
18+
19+
func main() {
20+
apiKey := os.Getenv("CYCLE_API_KEY")
21+
if apiKey == "" {
22+
log.Fatal("missing env var CYCLE_API_KEY")
23+
}
24+
25+
hubId := os.Getenv("CYCLE_HUB_ID")
26+
if hubId == "" {
27+
log.Fatal("missing env var CYCLE_HUB_ID")
28+
}
29+
30+
c, err := cycle.NewAuthenticatedClient(cycle.ClientConfig{
31+
APIKey: apiKey,
32+
HubID: hubId,
33+
})
34+
35+
if err != nil {
36+
log.Fatal(err)
37+
}
38+
39+
// Get list of environments
40+
resp, err := c.GetEnvironmentsWithResponse(context.TODO(), &cycle.GetEnvironmentsParams{})
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
45+
if resp.StatusCode() != http.StatusOK {
46+
log.Fatalf("Expected HTTP 200 but received %d %s", resp.StatusCode(), *resp.JSONDefault.Error.Title)
47+
}
48+
49+
for _, v := range resp.JSON200.Data {
50+
fmt.Printf("ID: %s - Name: %s\n", v.Id, v.Name)
51+
}
52+
}
53+
```
54+
55+
## Development
56+
57+
### Updating the API spec
58+
59+
Update the API spec to the latest version:
1460

1561
`git submodule update --recursive --remote`
1662

17-
Using `npm`, run `(cd api-spec; npm run build:public && npm run build:internal)`
63+
Using `npm`, run `(cd api-spec; npm run build:platform && npm run downconvert:platform)`
1864

1965
### Generating the client
2066

api-spec

Submodule api-spec updated 148 files

client/authentication.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

client/oas_cfg_gen.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)