Skip to content

Commit

Permalink
refactor: removes v1 from the host setting (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored May 6, 2024
1 parent 13daf15 commit 7cd0505
Show file tree
Hide file tree
Showing 37 changed files with 675 additions and 775 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# go-client-codegen

go-client-codegen is an automatically code generated Aiven Go Client. It is generated from the Aiven API specification.
`go-client-codegen` is an automatically code generated Aiven Go Client from the Aiven API specification.

_Warning:_ this client is under heavy development.

## Setup

Expand Down
4 changes: 3 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ func NewClient(opts ...Option) (Client, error) {
return nil, errTokenIsRequired
}

// Removes trailing / so it is easier later Host + URL
d.Host = strings.TrimSuffix(d.Host, "/")
return newClient(d), nil
}

type aivenClient struct {
Host string `envconfig:"AIVEN_WEB_URL" default:"https://api.aiven.io/v1"`
Host string `envconfig:"AIVEN_WEB_URL" default:"https://api.aiven.io"`
UserAgent string `envconfig:"AIVEN_USER_AGENT" default:"aiven-go-client/v3"`
Token string `envconfig:"AIVEN_TOKEN"`
Debug bool `envconfig:"AIVEN_DEBUG"`
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestNewClient(t *testing.T) {
func TestServiceCreate(t *testing.T) {
// Creates a test server
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/project/foo/service", r.URL.Path)
require.Equal(t, "/v1/project/foo/service", r.URL.Path)

// Validates request
expectIn := new(service.ServiceCreateIn)
Expand Down
15 changes: 11 additions & 4 deletions generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
)

const (
generatedHeader = "Code generated by Aiven. DO NOT EDIT."
versionIDParam = `/{version_id:latest|\d+}`
configPrefix = "GEN"
generatedHeader = "Code generated by Aiven. DO NOT EDIT."
configPrefix = "GEN"
defaultAPIVersion = "v1"
)

type config struct {
Expand All @@ -34,7 +34,10 @@ type config struct {
OpenAPIFile string `envconfig:"OPENAPI_FILE" default:"openapi.json"`
}

var pathClean = regexp.MustCompile(`\{[^{]+}`)
var (
pathClean = regexp.MustCompile(`\{[^{]+}`)
pathVersioning = regexp.MustCompile(`^/v[0-9]/`)
)

func main() {
err := exec()
Expand Down Expand Up @@ -84,6 +87,10 @@ func exec() error {
continue
}

if !pathVersioning.MatchString(path) {
path = fmt.Sprintf("/%s%s", defaultAPIVersion, path)
}

p.Path = path
p.Method = strings.ToUpper(meth)
p.ID = p.OperationID
Expand Down
57 changes: 29 additions & 28 deletions handler/account/account.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions handler/accountauthentication/accountauthentication.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7cd0505

Please sign in to comment.