Skip to content

Commit

Permalink
chore: Sync with the latest swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek committed Jul 21, 2021
1 parent 25199b3 commit 14576d2
Show file tree
Hide file tree
Showing 17 changed files with 10,311 additions and 6,787 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Unreleased
## 2.3.0 [in progress]
### Features
- [#264](https://github.com/influxdata/influxdb-client-go/pull/264) Synced generated server API with the latest [oss.yml](https://github.com/influxdata/openapi/blob/master/contracts/oss.yml).

### Documentation
- [#261](https://github.com/influxdata/influxdb-client-go/pull/261) Update Line Protocol document link to v2.0

Expand Down
8 changes: 7 additions & 1 deletion api/authorizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ func (a *authorizationsAPI) listAuthorizations(ctx context.Context, query *domai

func (a *authorizationsAPI) CreateAuthorization(ctx context.Context, authorization *domain.Authorization) (*domain.Authorization, error) {
params := &domain.PostAuthorizationsParams{}
response, err := a.apiClient.PostAuthorizationsWithResponse(ctx, params, domain.PostAuthorizationsJSONRequestBody(*authorization))
req := domain.PostAuthorizationsJSONRequestBody{
AuthorizationUpdateRequest: authorization.AuthorizationUpdateRequest,
OrgID: authorization.OrgID,
Permissions: authorization.Permissions,
UserID: authorization.UserID,
}
response, err := a.apiClient.PostAuthorizationsWithResponse(ctx, params, req)
if err != nil {
return nil, err
}
Expand Down
31 changes: 26 additions & 5 deletions api/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ type BucketsAPI interface {
GetMembersWithID(ctx context.Context, bucketID string) (*[]domain.ResourceMember, error)
// AddMember adds a member to a bucket.
AddMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceMember, error)
// AddMember adds a member with id memberID to a bucket with bucketID.
// AddMemberWithID adds a member with id memberID to a bucket with bucketID.
AddMemberWithID(ctx context.Context, bucketID, memberID string) (*domain.ResourceMember, error)
// RemoveMember removes a member from a bucket.
RemoveMember(ctx context.Context, bucket *domain.Bucket, user *domain.User) error
// RemoveMember removes a member with id memberID from a bucket with bucketID.
// RemoveMemberWithID removes a member with id memberID from a bucket with bucketID.
RemoveMemberWithID(ctx context.Context, bucketID, memberID string) error
// GetOwners returns owners of a bucket.
GetOwners(ctx context.Context, bucket *domain.Bucket) (*[]domain.ResourceOwner, error)
// GetOwnersWithID returns owners of a bucket with bucketID.
GetOwnersWithID(ctx context.Context, bucketID string) (*[]domain.ResourceOwner, error)
// AddOwner adds an owner to a bucket.
AddOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) (*domain.ResourceOwner, error)
// AddOwner adds an owner with id memberID to a bucket with bucketID.
// AddOwnerWithID adds an owner with id memberID to a bucket with bucketID.
AddOwnerWithID(ctx context.Context, bucketID, memberID string) (*domain.ResourceOwner, error)
// RemoveOwner removes an owner from a bucket.
RemoveOwner(ctx context.Context, bucket *domain.Bucket, user *domain.User) error
// RemoveOwner removes a member with id memberID from a bucket with bucketID.
// RemoveOwnerWithID removes a member with id memberID from a bucket with bucketID.
RemoveOwnerWithID(ctx context.Context, bucketID, memberID string) error
}

Expand Down Expand Up @@ -193,7 +193,12 @@ func (b *bucketsAPI) DeleteBucketWithID(ctx context.Context, bucketID string) er

func (b *bucketsAPI) UpdateBucket(ctx context.Context, bucket *domain.Bucket) (*domain.Bucket, error) {
params := &domain.PatchBucketsIDParams{}
response, err := b.apiClient.PatchBucketsIDWithResponse(ctx, *bucket.Id, params, domain.PatchBucketsIDJSONRequestBody(*bucket))
req := domain.PatchBucketsIDJSONRequestBody{
Description: bucket.Description,
Name: &bucket.Name,
RetentionRules: retentionRulesToPatchRetentionRules(&bucket.RetentionRules),
}
response, err := b.apiClient.PatchBucketsIDWithResponse(ctx, *bucket.Id, params, req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -300,3 +305,19 @@ func (b *bucketsAPI) RemoveOwnerWithID(ctx context.Context, bucketID, memberID s
}
return nil
}

func retentionRulesToPatchRetentionRules(rrs *domain.RetentionRules) *domain.PatchRetentionRules {
if rrs == nil {
return nil
}
prrs := make([]domain.PatchRetentionRule, len(*rrs))
for i, rr := range *rrs {
prrs[i] = domain.PatchRetentionRule{
EverySeconds: &rr.EverySeconds,
ShardGroupDurationSeconds: rr.ShardGroupDurationSeconds,
Type: domain.PatchRetentionRuleType(rr.Type),
}
}
dprrs := domain.PatchRetentionRules(prrs)
return &dprrs
}
8 changes: 4 additions & 4 deletions api/buckets_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestBucketsAPI(t *testing.T) {
require.NotNil(t, owners)
assert.Len(t, *owners, 1)

err = bucketsAPI.RemoveOwner(ctx, b, &(*owners)[0].User)
err = bucketsAPI.RemoveOwnerWithID(ctx, *b.Id, *(*owners)[0].Id)
require.Nil(t, err, err)

owners, err = bucketsAPI.GetOwners(ctx, b)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestBucketsAPI(t *testing.T) {
require.NotNil(t, members)
assert.Len(t, *members, 1)

err = bucketsAPI.RemoveMember(ctx, b, &(*members)[0].User)
err = bucketsAPI.RemoveMemberWithID(ctx, *b.Id, *(*members)[0].Id)
require.Nil(t, err, err)

members, err = bucketsAPI.GetMembers(ctx, b)
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestBucketsAPI_requestFailing(t *testing.T) {
_, err = bucketsAPI.AddMember(ctx, bucket, user)
assert.NotNil(t, err)

err = bucketsAPI.RemoveMember(ctx, bucket, user)
err = bucketsAPI.RemoveMemberWithID(ctx, *bucket.Id, *user.Id)
assert.NotNil(t, err)

_, err = bucketsAPI.GetOwners(ctx, bucket)
Expand All @@ -344,6 +344,6 @@ func TestBucketsAPI_requestFailing(t *testing.T) {
_, err = bucketsAPI.AddOwner(ctx, bucket, user)
assert.NotNil(t, err)

err = bucketsAPI.RemoveOwner(ctx, bucket, user)
err = bucketsAPI.RemoveOwnerWithID(ctx, *bucket.Id, *user.Id)
assert.NotNil(t, err)
}
1 change: 0 additions & 1 deletion api/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func ExampleAuthorizationsAPI() {
auth := &domain.Authorization{
OrgID: org.Id,
Permissions: &permissions,
User: &user.Name,
UserID: user.Id,
}

Expand Down
12 changes: 10 additions & 2 deletions api/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ func (o *organizationsAPI) FindOrganizationsByUserID(ctx context.Context, userID

func (o *organizationsAPI) CreateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) {
params := &domain.PostOrgsParams{}
response, err := o.apiClient.PostOrgsWithResponse(ctx, params, domain.PostOrgsJSONRequestBody(*org))
req := domain.PostOrgsJSONRequestBody{
Name: org.Name,
Description: org.Description,
}
response, err := o.apiClient.PostOrgsWithResponse(ctx, params, req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +167,11 @@ func (o *organizationsAPI) DeleteOrganizationWithID(ctx context.Context, orgID s

func (o *organizationsAPI) UpdateOrganization(ctx context.Context, org *domain.Organization) (*domain.Organization, error) {
params := &domain.PatchOrgsIDParams{}
response, err := o.apiClient.PatchOrgsIDWithResponse(ctx, *org.Id, params, domain.PatchOrgsIDJSONRequestBody(*org))
req := domain.PatchOrgsIDJSONRequestBody{
Name: &org.Name,
Description: org.Description,
}
response, err := o.apiClient.PatchOrgsIDWithResponse(ctx, *org.Id, params, req)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/organizations_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestOrganizationsAPI(t *testing.T) {
require.Nil(t, err)
require.NotNil(t, u)

err = orgsAPI.RemoveOwner(ctx, org2, u)
err = orgsAPI.RemoveOwnerWithID(ctx, *org2.Id, *u.Id)
require.Nil(t, err)

owners, err = orgsAPI.GetOwners(ctx, org2)
Expand All @@ -170,7 +170,7 @@ func TestOrganizationsAPI(t *testing.T) {
require.NotNil(t, orgs)
require.Len(t, *orgs, 2)

err = orgsAPI.RemoveMember(ctx, org, user)
err = orgsAPI.RemoveMemberWithID(ctx, *org.Id, *user.Id)
require.Nil(t, err)

members, err = orgsAPI.GetMembers(ctx, org)
Expand Down
14 changes: 7 additions & 7 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ type TasksAPI interface {
FindMembersWithID(ctx context.Context, taskID string) ([]domain.ResourceMember, error)
// AddMember adds a member to a task.
AddMember(ctx context.Context, task *domain.Task, user *domain.User) (*domain.ResourceMember, error)
// AddMember adds a member with id memberID to a task with taskID.
// AddMemberWithID adds a member with id memberID to a task with taskID.
AddMemberWithID(ctx context.Context, taskID, memberID string) (*domain.ResourceMember, error)
// RemoveMember removes a member from a task.
RemoveMember(ctx context.Context, task *domain.Task, user *domain.User) error
// RemoveMember removes a member with id memberID from a task with taskID.
// RemoveMemberWithID removes a member with id memberID from a task with taskID.
RemoveMemberWithID(ctx context.Context, taskID, memberID string) error
// FindOwners retrieves owners of a task.
FindOwners(ctx context.Context, task *domain.Task) ([]domain.ResourceOwner, error)
// FindOwnersWithID retrieves owners of a task with taskID.
FindOwnersWithID(ctx context.Context, taskID string) ([]domain.ResourceOwner, error)
// AddOwner adds an owner to a task.
AddOwner(ctx context.Context, task *domain.Task, user *domain.User) (*domain.ResourceOwner, error)
// AddOwner adds an owner with id memberID to a task with taskID.
// AddOwnerWithID adds an owner with id memberID to a task with taskID.
AddOwnerWithID(ctx context.Context, taskID, memberID string) (*domain.ResourceOwner, error)
// RemoveOwner removes an owner from a task.
RemoveOwner(ctx context.Context, task *domain.Task, user *domain.User) error
// RemoveOwner removes a member with id memberID from a task with taskID.
// RemoveOwnerWithID removes a member with id memberID from a task with taskID.
RemoveOwnerWithID(ctx context.Context, taskID, memberID string) error
// FindRuns retrieves a task runs according the filter. More fields can be applied. Filter can be nil.
FindRuns(ctx context.Context, task *domain.Task, filter *RunFilter) ([]domain.Run, error)
Expand All @@ -109,15 +109,15 @@ type TasksAPI interface {
FindRunLogsWithID(ctx context.Context, taskID, runID string) ([]domain.LogEvent, error)
// RunManually manually start a run of the task now, overriding the current schedule.
RunManually(ctx context.Context, task *domain.Task) (*domain.Run, error)
// RunManually manually start a run of a task with taskID now, overriding the current schedule.
// RunManuallyWithID manually start a run of a task with taskID now, overriding the current schedule.
RunManuallyWithID(ctx context.Context, taskID string) (*domain.Run, error)
// RetryRun retry a task run.
RetryRun(ctx context.Context, run *domain.Run) (*domain.Run, error)
// RetryRunWithID retry a run with runID of a task with taskID.
RetryRunWithID(ctx context.Context, taskID, runID string) (*domain.Run, error)
// CancelRun cancels a running task.
CancelRun(ctx context.Context, run *domain.Run) error
// CancelRun cancels a running task.
// CancelRunWithID cancels a running task.
CancelRunWithID(ctx context.Context, taskID, runID string) error
// FindLogs retrieves all logs for a task.
FindLogs(ctx context.Context, task *domain.Task) ([]domain.LogEvent, error)
Expand Down Expand Up @@ -482,7 +482,7 @@ func (t *tasksAPI) RetryRun(ctx context.Context, run *domain.Run) (*domain.Run,

func (t *tasksAPI) RetryRunWithID(ctx context.Context, taskID, runID string) (*domain.Run, error) {
params := &domain.PostTasksIDRunsIDRetryParams{}
response, err := t.apiClient.PostTasksIDRunsIDRetryWithResponse(ctx, taskID, runID, params)
response, err := t.apiClient.PostTasksIDRunsIDRetryWithBodyWithResponse(ctx, taskID, runID, params, "application/json; charset=utf-8", nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/tasks_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func TestTasksAPI_MembersOwners(t *testing.T) {
require.NotNil(t, owners)
assert.Len(t, owners, 1)

err = tasksAPI.RemoveOwner(ctx, task, &owners[0].User)
err = tasksAPI.RemoveOwnerWithID(ctx, task.Id, *owners[0].Id)
require.Nil(t, err, err)

owners, err = tasksAPI.FindOwners(ctx, task)
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestTasksAPI_MembersOwners(t *testing.T) {
require.NotNil(t, members)
assert.Len(t, members, 1)

err = tasksAPI.RemoveMember(ctx, task, &members[0].User)
err = tasksAPI.RemoveMemberWithID(ctx, task.Id, *members[0].Id)
require.Nil(t, err, err)

members, err = tasksAPI.FindMembers(ctx, task)
Expand Down
42 changes: 37 additions & 5 deletions api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (u *usersAPI) GetUsers(ctx context.Context) (*[]domain.User, error) {
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON200.Users, nil
return userResponsesToUsers(response.JSON200.Users), nil
}

func (u *usersAPI) FindUserByID(ctx context.Context, userID string) (*domain.User, error) {
Expand All @@ -88,7 +88,7 @@ func (u *usersAPI) FindUserByID(ctx context.Context, userID string) (*domain.Use
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON200, nil
return userResponseToUser(response.JSON200), nil
}

func (u *usersAPI) FindUserByName(ctx context.Context, userName string) (*domain.User, error) {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (u *usersAPI) CreateUser(ctx context.Context, user *domain.User) (*domain.U
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON201, nil
return userResponseToUser(response.JSON201), nil
}

func (u *usersAPI) UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error) {
Expand All @@ -135,7 +135,7 @@ func (u *usersAPI) UpdateUser(ctx context.Context, user *domain.User) (*domain.U
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON200, nil
return userResponseToUser(response.JSON200), nil
}

func (u *usersAPI) UpdateUserPassword(ctx context.Context, user *domain.User, password string) error {
Expand Down Expand Up @@ -180,7 +180,7 @@ func (u *usersAPI) Me(ctx context.Context) (*domain.User, error) {
if response.JSONDefault != nil {
return nil, domain.ErrorToHTTPError(response.JSONDefault, response.StatusCode())
}
return response.JSON200, nil
return userResponseToUser(response.JSON200), nil
}

func (u *usersAPI) MeUpdatePassword(ctx context.Context, oldPassword, newPassword string) error {
Expand Down Expand Up @@ -254,3 +254,35 @@ func (u *usersAPI) SignOut(ctx context.Context) error {
}
return nil
}

func userResponseToUser(ur *domain.UserResponse) *domain.User {
if ur == nil {
return nil
}
user := &domain.User{
Id: ur.Id,
Name: ur.Name,
OauthID: ur.OauthID,
Status: userResponseStatusToUserStatus(ur.Status),
}
return user
}

func userResponseStatusToUserStatus(urs *domain.UserResponseStatus) *domain.UserStatus {
if urs == nil {
return nil
}
us := domain.UserStatus(*urs)
return &us
}

func userResponsesToUsers(urs *[]domain.UserResponse) *[]domain.User {
if urs == nil {
return nil
}
us := make([]domain.User, len(*urs))
for i, ur := range *urs {
us[i] = *userResponseToUser(&ur)
}
return &us
}
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *clientImpl) Setup(ctx context.Context, username, password, org, bucket
c.lock.Lock()
defer c.lock.Unlock()
params := &domain.PostSetupParams{}
retentionPeriodSeconds := retentionPeriodHours * 3600
retentionPeriodSeconds := int64(retentionPeriodHours * 3600)
retentionPeriodHrs := int(time.Duration(retentionPeriodSeconds) * time.Second)
body := &domain.PostSetupJSONRequestBody{
Bucket: bucket,
Expand Down
2 changes: 1 addition & 1 deletion client_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestSetup(t *testing.T) {
require.NotNil(t, response.Bucket)
require.NotNil(t, response.Bucket.RetentionRules)
require.Len(t, response.Bucket.RetentionRules, 1)
assert.Equal(t, 24*3600, response.Bucket.RetentionRules[0].EverySeconds)
assert.Equal(t, int64(24*3600), response.Bucket.RetentionRules[0].EverySeconds)

_, err = client.Setup(context.Background(), "my-user", "my-password", "my-org", "my-bucket", 0)
require.NotNil(t, err)
Expand Down
8 changes: 4 additions & 4 deletions domain/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated types and API client

`swagger.yml` is copied from InfluxDB and customized. Must be periodically sync with latest changes
`oss.yml` is copied from InfluxDB and customized, until changes are meged. Must be periodically sync with latest changes
and types and client must be re-generated


Expand All @@ -10,14 +10,14 @@
`git checkout dev-master`
`go install ./cmd/oapi-codegen/oapi-codegen.go`
## Download and sync latest swagger
`wget https://raw.githubusercontent.com/influxdata/influxdb/master/http/swagger.yml`
`wget https://raw.githubusercontent.com/influxdata/openapi/master/contracts/oss.yml`

## Generate
`cd domain`

Generate types
`oapi-codegen -generate types -o types.gen.go -package domain swagger.yml`
`oapi-codegen -generate types -o types.gen.go -package domain oss.yml`

Generate client
`oapi-codegen -generate client -o client.gen.go -package domain -templates .\templates swagger.yml`
`oapi-codegen -generate client -o client.gen.go -package domain -templates .\templates oss.yml`

Loading

0 comments on commit 14576d2

Please sign in to comment.