Skip to content

Commit

Permalink
fix: set default fields for requests with only query params (#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Oct 30, 2023
1 parent 0dc5e63 commit 33dd2a3
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/account/v2/account_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ func (s *API) CreateProject(req *CreateProjectRequest, opts ...scw.RequestOption
func (s *API) ListProjects(req *ListProjectsRequest, opts ...scw.RequestOption) (*ListProjectsResponse, error) {
var err error

if req.OrganizationID == "" {
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
req.OrganizationID = defaultOrganizationID
}

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
parameter.AddToQuery(query, "name", req.Name)
Expand Down
10 changes: 10 additions & 0 deletions api/account/v3/account_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ func (s *ProjectAPI) CreateProject(req *ProjectAPICreateProjectRequest, opts ...
func (s *ProjectAPI) ListProjects(req *ProjectAPIListProjectsRequest, opts ...scw.RequestOption) (*ListProjectsResponse, error) {
var err error

if req.OrganizationID == "" {
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
req.OrganizationID = defaultOrganizationID
}

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
parameter.AddToQuery(query, "name", req.Name)
Expand Down
15 changes: 15 additions & 0 deletions api/billing/v2alpha1/billing_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ func NewAPI(client *scw.Client) *API {
func (s *API) GetConsumption(req *GetConsumptionRequest, opts ...scw.RequestOption) (*GetConsumptionResponse, error) {
var err error

if req.OrganizationID == "" {
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
req.OrganizationID = defaultOrganizationID
}

query := url.Values{}
parameter.AddToQuery(query, "organization_id", req.OrganizationID)

Expand All @@ -515,6 +520,11 @@ func (s *API) GetConsumption(req *GetConsumptionRequest, opts ...scw.RequestOpti
func (s *API) ListInvoices(req *ListInvoicesRequest, opts ...scw.RequestOption) (*ListInvoicesResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
parameter.AddToQuery(query, "started_after", req.StartedAfter)
Expand Down Expand Up @@ -569,6 +579,11 @@ func (s *API) DownloadInvoice(req *DownloadInvoiceRequest, opts ...scw.RequestOp
func (s *API) ListDiscounts(req *ListDiscountsRequest, opts ...scw.RequestOption) (*ListDiscountsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "order_by", req.OrderBy)
parameter.AddToQuery(query, "page", req.Page)
Expand Down
65 changes: 65 additions & 0 deletions api/cockpit/v1beta1/cockpit_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,11 @@ func (s *API) ActivateCockpit(req *ActivateCockpitRequest, opts ...scw.RequestOp
func (s *API) GetCockpit(req *GetCockpitRequest, opts ...scw.RequestOption) (*Cockpit, error) {
var err error

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "project_id", req.ProjectID)

Expand All @@ -985,6 +990,11 @@ func (s *API) GetCockpit(req *GetCockpitRequest, opts ...scw.RequestOption) (*Co
func (s *API) GetCockpitMetrics(req *GetCockpitMetricsRequest, opts ...scw.RequestOption) (*CockpitMetrics, error) {
var err error

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "project_id", req.ProjectID)
parameter.AddToQuery(query, "start_date", req.StartDate)
Expand Down Expand Up @@ -1094,6 +1104,16 @@ func (s *API) CreateDatasource(req *CreateDatasourceRequest, opts ...scw.Request
func (s *API) ListDatasources(req *ListDatasourcesRequest, opts ...scw.RequestOption) (*ListDatasourcesResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -1152,6 +1172,16 @@ func (s *API) CreateToken(req *CreateTokenRequest, opts ...scw.RequestOption) (*
func (s *API) ListTokens(req *ListTokensRequest, opts ...scw.RequestOption) (*ListTokensResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -1247,6 +1277,16 @@ func (s *API) CreateContactPoint(req *CreateContactPointRequest, opts ...scw.Req
func (s *API) ListContactPoints(req *ListContactPointsRequest, opts ...scw.RequestOption) (*ListContactPointsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -1403,6 +1443,16 @@ func (s *API) CreateGrafanaUser(req *CreateGrafanaUserRequest, opts ...scw.Reque
func (s *API) ListGrafanaUsers(req *ListGrafanaUsersRequest, opts ...scw.RequestOption) (*ListGrafanaUsersResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -1490,6 +1540,11 @@ func (s *API) ResetGrafanaUserPassword(req *ResetGrafanaUserPasswordRequest, opt
func (s *API) ListPlans(req *ListPlansRequest, opts ...scw.RequestOption) (*ListPlansResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -1542,6 +1597,16 @@ func (s *API) SelectPlan(req *SelectPlanRequest, opts ...scw.RequestOption) (*Se
func (s *API) ListGrafanaProductDashboards(req *ListGrafanaProductDashboardsRequest, opts ...scw.RequestOption) (*ListGrafanaProductDashboardsResponse, error) {
var err error

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "project_id", req.ProjectID)
parameter.AddToQuery(query, "page", req.Page)
Expand Down
35 changes: 35 additions & 0 deletions api/domain/v2beta1/domain_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2827,6 +2827,11 @@ func NewAPI(client *scw.Client) *API {
func (s *API) ListDNSZones(req *ListDNSZonesRequest, opts ...scw.RequestOption) (*ListDNSZonesResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
parameter.AddToQuery(query, "project_id", req.ProjectID)
Expand Down Expand Up @@ -3399,6 +3404,11 @@ func (s *API) CreateSSLCertificate(req *CreateSSLCertificateRequest, opts ...scw
func (s *API) ListSSLCertificates(req *ListSSLCertificatesRequest, opts ...scw.RequestOption) (*ListSSLCertificatesResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "dns_zone", req.DNSZone)
parameter.AddToQuery(query, "page", req.Page)
Expand Down Expand Up @@ -3501,6 +3511,11 @@ func NewRegistrarAPI(client *scw.Client) *RegistrarAPI {
func (s *RegistrarAPI) ListTasks(req *RegistrarAPIListTasksRequest, opts ...scw.RequestOption) (*ListTasksResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -3715,6 +3730,11 @@ func (s *RegistrarAPI) CheckContactsCompatibility(req *RegistrarAPICheckContacts
func (s *RegistrarAPI) ListContacts(req *RegistrarAPIListContactsRequest, opts ...scw.RequestOption) (*ListContactsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -3792,6 +3812,11 @@ func (s *RegistrarAPI) UpdateContact(req *RegistrarAPIUpdateContactRequest, opts
func (s *RegistrarAPI) ListDomains(req *RegistrarAPIListDomainsRequest, opts ...scw.RequestOption) (*ListDomainsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -3822,6 +3847,11 @@ func (s *RegistrarAPI) ListDomains(req *RegistrarAPIListDomainsRequest, opts ...
func (s *RegistrarAPI) ListRenewableDomains(req *RegistrarAPIListRenewableDomainsRequest, opts ...scw.RequestOption) (*ListRenewableDomainsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "page", req.Page)
parameter.AddToQuery(query, "page_size", req.PageSize)
Expand Down Expand Up @@ -4109,6 +4139,11 @@ func (s *RegistrarAPI) SearchAvailableDomains(req *RegistrarAPISearchAvailableDo
func (s *RegistrarAPI) ListTlds(req *RegistrarAPIListTldsRequest, opts ...scw.RequestOption) (*ListTldsResponse, error) {
var err error

defaultPageSize, exist := s.client.GetDefaultPageSize()
if (req.PageSize == nil || *req.PageSize == 0) && exist {
req.PageSize = &defaultPageSize
}

query := url.Values{}
parameter.AddToQuery(query, "tlds", req.Tlds)
parameter.AddToQuery(query, "page", req.Page)
Expand Down
Loading

0 comments on commit 33dd2a3

Please sign in to comment.