Skip to content

Commit

Permalink
feat: auto-updated SDK (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: kislerdm <kislerdm@users.noreply.github.com>
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
  • Loading branch information
github-actions[bot] and kislerdm authored Sep 29, 2023
1 parent 417ef74 commit aac3cf2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
6 changes: 3 additions & 3 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ var endpointResponseExamples = map[string]map[string]mockResponse{
Code: 200,
},
"PATCH": mockResponse{
Content: `{"operations":[],"project":{"active_time_seconds":100,"branch_logical_size_limit":0,"branch_logical_size_limit_bytes":10500,"compute_time_seconds":100,"consumption_period_end":"2023-03-01T00:00:00Z","consumption_period_start":"2023-02-01T00:00:00Z","cpu_used_sec":213230,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","data_storage_bytes_hour":1040,"data_transfer_bytes":1000000,"history_retention_seconds":604800,"id":"shiny-wind-028834","name":"myproject","owner_id":"1232111","pg_version":15,"platform_id":"aws","provisioner":"k8s-pod","proxy_host":"us-east-2.aws.neon.tech","region_id":"aws-us-east-2","store_passwords":true,"updated_at":"2022-12-04T02:39:25Z","written_data_bytes":100800}}`,
Content: `{"project":{"active_time_seconds":100,"branch_logical_size_limit":0,"branch_logical_size_limit_bytes":10500,"compute_time_seconds":100,"consumption_period_end":"2023-03-01T00:00:00Z","consumption_period_start":"2023-02-01T00:00:00Z","cpu_used_sec":213230,"created_at":"2022-11-23T17:42:25Z","creation_source":"console","data_storage_bytes_hour":1040,"data_transfer_bytes":1000000,"history_retention_seconds":604800,"id":"shiny-wind-028834","name":"myproject","owner_id":"1232111","pg_version":15,"platform_id":"aws","provisioner":"k8s-pod","proxy_host":"us-east-2.aws.neon.tech","region_id":"aws-us-east-2","store_passwords":true,"updated_at":"2022-12-04T02:39:25Z","written_data_bytes":100800}}`,
Code: 200,
},
},
Expand Down Expand Up @@ -480,8 +480,8 @@ var endpointResponseExamples = map[string]map[string]mockResponse{
// Mock client return the response as per API spec, except for the errors: 404 and 401 status codes are covered only.
// - 401 is returned when the string `invalidApiKey` is used as the API key;
// - 404 is returned if either of the following:
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
// - the string value `notFound` is used as the string argument, e.g. projectID
// - a negative int/float value is used as the int/float argument, e.g. database ID
func NewMockHTTPClient() HTTPClient {
u, _ := url.Parse(baseURL)
return mockHTTPClient{
Expand Down
50 changes: 38 additions & 12 deletions openAPIDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"security": [
{
"BearerAuth": []
},
{
"CookieAuth": []
}
],
"tags": [
Expand Down Expand Up @@ -523,10 +526,9 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProjectOperations"
"$ref": "#/components/schemas/ProjectResponse"
},
"example": {
"operations": [],
"project": {
"id": "shiny-wind-028834",
"platform_id": "aws",
Expand Down Expand Up @@ -2772,6 +2774,11 @@
"type": "http",
"scheme": "bearer",
"description": "The Neon API requires an API key to authorize your requests, which you can enter below.\nRefer to our documentation to find out how to generate and use [API keys](https://neon.tech/docs/manage/api-keys).\n"
},
"CookieAuth": {
"type": "apiKey",
"in": "cookie",
"name": "zenith"
}
},
"schemas": {
Expand Down Expand Up @@ -4859,6 +4866,31 @@
}
}
},
"UpdateUserInfoRequest": {
"type": "object",
"required": [
"id",
"email"
],
"properties": {
"email": {
"type": "string"
},
"id": {
"type": "string",
"format": "uuid"
},
"image": {
"type": "string"
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
}
},
"CurrentUserInfoResponse": {
"type": "object",
"required": [
Expand All @@ -4868,6 +4900,7 @@
"email",
"login",
"name",
"last_name",
"image",
"projects_limit",
"branches_limit",
Expand Down Expand Up @@ -4905,6 +4938,9 @@
"name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"projects_limit": {
"type": "integer",
"format": "int64"
Expand Down Expand Up @@ -5061,16 +5097,6 @@
"ErrorCode": {
"type": "string"
},
"ProjectOperations": {
"allOf": [
{
"$ref": "#/components/schemas/ProjectResponse"
},
{
"$ref": "#/components/schemas/OperationsResponse"
}
]
},
"BranchOperations": {
"allOf": [
{
Expand Down
14 changes: 5 additions & 9 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type Client interface {
// UpdateProject Updates the specified project.
// You can obtain a `project_id` by listing the projects for your Neon account.
// Neon permits updating the project name only.
UpdateProject(projectID string, cfg ProjectUpdateRequest) (ProjectOperations, error)
UpdateProject(projectID string, cfg ProjectUpdateRequest) (ProjectResponse, error)

// DeleteProject Deletes the specified project.
// You can obtain a `project_id` by listing the projects for your Neon account.
Expand Down Expand Up @@ -532,10 +532,10 @@ func (c *client) GetProject(projectID string) (ProjectResponse, error) {
return v, nil
}

func (c *client) UpdateProject(projectID string, cfg ProjectUpdateRequest) (ProjectOperations, error) {
var v ProjectOperations
func (c *client) UpdateProject(projectID string, cfg ProjectUpdateRequest) (ProjectResponse, error) {
var v ProjectResponse
if err := c.requestHandler(c.baseURL+"/projects/"+projectID, "PATCH", cfg, &v); err != nil {
return ProjectOperations{}, err
return ProjectResponse{}, err
}
return v, nil
}
Expand Down Expand Up @@ -1005,6 +1005,7 @@ type CurrentUserInfoResponse struct {
Email string `json:"email"`
ID string `json:"id"`
Image string `json:"image"`
LastName string `json:"last_name"`
Login string `json:"login"`
MaxAutoscalingLimit ComputeUnit `json:"max_autoscaling_limit"`
Name string `json:"name"`
Expand Down Expand Up @@ -1462,11 +1463,6 @@ type ProjectListItem struct {
UpdatedAt time.Time `json:"updated_at"`
}

type ProjectOperations struct {
OperationsResponse
ProjectResponse
}

type ProjectOwnerData struct {
BranchesLimit int `json:"branches_limit"`
Email string `json:"email"`
Expand Down
8 changes: 4 additions & 4 deletions sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ func Test_client_GetProject(t *testing.T) {
}

func Test_client_UpdateProject(t *testing.T) {
deserializeResp := func(s string) ProjectOperations {
var v ProjectOperations
deserializeResp := func(s string) ProjectResponse {
var v ProjectResponse
if err := json.Unmarshal([]byte(s), &v); err != nil {
panic(err)
}
Expand All @@ -865,7 +865,7 @@ func Test_client_UpdateProject(t *testing.T) {
name string
args args
apiKey string
want ProjectOperations
want ProjectResponse
wantErr bool
}{
{
Expand All @@ -885,7 +885,7 @@ func Test_client_UpdateProject(t *testing.T) {
cfg: ProjectUpdateRequest{},
},
apiKey: "invalidApiKey",
want: ProjectOperations{},
want: ProjectResponse{},
wantErr: true,
},
}
Expand Down

0 comments on commit aac3cf2

Please sign in to comment.