diff --git a/generator/main.go b/generator/main.go index 3c4d287..c0aa302 100644 --- a/generator/main.go +++ b/generator/main.go @@ -223,10 +223,6 @@ func exec() error { // Interface and implementation args funcArgs := []jen.Code{ctx} - // We want to add the query params type when there is any param - addQueryParams := true - queryParamType := lowerFirst(path.FuncName) + queryParamTypeSuffix - // Collects params: in path and in query // Adds to schemas to render enums for _, p := range path.Parameters { @@ -240,18 +236,11 @@ func exec() error { continue } - // Adds query params type once - if addQueryParams { - file.Comment(queryParamType + " http query params private type") - file.Type().Id(queryParamType).Index(jen.Lit(queryParamArraySize)).String() - addQueryParams = false - } - queryParams = append(queryParams, p.Schema) // Adds param function (request modifier) var code *jen.Statement - code, err = fmtQueryParam(path.FuncName, queryParamType, p) + code, err = fmtQueryParam(path.FuncName, p) if err != nil { return err } @@ -275,7 +264,7 @@ func exec() error { // Adds queryParams options if len(queryParams) > 0 { - funcArgs = append(funcArgs, jen.Id(queryParamName).Op("...").Id(queryParamType)) + funcArgs = append(funcArgs, jen.Id(queryParamName).Op("...").Add(fmtQueryParamType())) } typeMeth := jen.Id(path.FuncName).Params(funcArgs...) @@ -658,7 +647,7 @@ func fmtComment(c string) string { } // fmtQueryParam returns a query param -func fmtQueryParam(funcName, queryParamType string, p *Parameter) (*jen.Statement, error) { +func fmtQueryParam(funcName string, p *Parameter) (*jen.Statement, error) { keyFuncName := funcName + p.Schema.CamelName keyVarName := jen.Id(p.Schema.lowerCamel()) @@ -676,9 +665,9 @@ func fmtQueryParam(funcName, queryParamType string, p *Parameter) (*jen.Statemen param := jen.Comment(fmt.Sprintf("%s %s", keyFuncName, fmtComment(p.Description))) param.Line() param.Func().Id(keyFuncName). - Params(keyVarName.Clone().Add(getType(p.Schema))).Params(jen.Id(queryParamType)). + Params(keyVarName.Clone().Add(getType(p.Schema))).Params(fmtQueryParamType()). Block( - jen.Return(jen.Id(queryParamType).Values(jen.Lit(p.Schema.name), value)), + jen.Return(fmtQueryParamType().Values(jen.Lit(p.Schema.name), value)), ) return param, nil } diff --git a/handler/clickhouse/clickhouse.go b/handler/clickhouse/clickhouse.go index 9464451..8eefc4a 100644 --- a/handler/clickhouse/clickhouse.go +++ b/handler/clickhouse/clickhouse.go @@ -38,7 +38,7 @@ type Handler interface { // ServiceClickHouseQueryStats return statistics on recent queries // GET /v1/project/{project}/service/{service_name}/clickhouse/query/stats // https://api.aiven.io/doc/#tag/Service:_ClickHouse/operation/ServiceClickHouseQueryStats - ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...serviceClickHouseQueryStatsQuery) ([]ServiceClickHouseQueryStatsOut, error) + ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...[2]string) ([]ServiceClickHouseQueryStatsOut, error) // ServiceClickHouseTieredStorageSummary get the ClickHouse tiered storage summary // GET /v1/project/{project}/service/{service_name}/clickhouse/tiered-storage/summary @@ -109,24 +109,21 @@ func (h *ClickHouseHandler) ServiceClickHouseQuery(ctx context.Context, project return out, nil } -// serviceClickHouseQueryStatsQuery http query params private type -type serviceClickHouseQueryStatsQuery [2]string - // ServiceClickHouseQueryStatsLimit Limit for number of results -func ServiceClickHouseQueryStatsLimit(limit int) serviceClickHouseQueryStatsQuery { - return serviceClickHouseQueryStatsQuery{"limit", fmt.Sprintf("%d", limit)} +func ServiceClickHouseQueryStatsLimit(limit int) [2]string { + return [2]string{"limit", fmt.Sprintf("%d", limit)} } // ServiceClickHouseQueryStatsOffset Offset for retrieved results based on sort order -func ServiceClickHouseQueryStatsOffset(offset int) serviceClickHouseQueryStatsQuery { - return serviceClickHouseQueryStatsQuery{"offset", fmt.Sprintf("%d", offset)} +func ServiceClickHouseQueryStatsOffset(offset int) [2]string { + return [2]string{"offset", fmt.Sprintf("%d", offset)} } // ServiceClickHouseQueryStatsOrderByType Order in which to sort retrieved results -func ServiceClickHouseQueryStatsOrderByType(orderByType OrderByType) serviceClickHouseQueryStatsQuery { - return serviceClickHouseQueryStatsQuery{"order_by", fmt.Sprintf("%s", orderByType)} +func ServiceClickHouseQueryStatsOrderByType(orderByType OrderByType) [2]string { + return [2]string{"order_by", fmt.Sprintf("%s", orderByType)} } -func (h *ClickHouseHandler) ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...serviceClickHouseQueryStatsQuery) ([]ServiceClickHouseQueryStatsOut, error) { +func (h *ClickHouseHandler) ServiceClickHouseQueryStats(ctx context.Context, project string, serviceName string, query ...[2]string) ([]ServiceClickHouseQueryStatsOut, error) { p := make([][2]string, 0, len(query)) for _, v := range query { p = append(p, v) diff --git a/handler/kafka/kafka.go b/handler/kafka/kafka.go index 1c9c663..c589d45 100644 --- a/handler/kafka/kafka.go +++ b/handler/kafka/kafka.go @@ -53,7 +53,7 @@ type Handler interface { // ServiceKafkaQuotaDelete delete Kafka quota // DELETE /v1/project/{project}/service/{service_name}/quota // https://api.aiven.io/doc/#tag/Service:_Kafka/operation/ServiceKafkaQuotaDelete - ServiceKafkaQuotaDelete(ctx context.Context, project string, serviceName string) error + ServiceKafkaQuotaDelete(ctx context.Context, project string, serviceName string, query ...[2]string) error // ServiceKafkaQuotaDescribe describe Specific Kafka quotas // GET /v1/project/{project}/service/{service_name}/quota/describe @@ -182,9 +182,23 @@ func (h *KafkaHandler) ServiceKafkaQuotaCreate(ctx context.Context, project stri _, err := h.doer.Do(ctx, "ServiceKafkaQuotaCreate", "POST", path, in) return err } -func (h *KafkaHandler) ServiceKafkaQuotaDelete(ctx context.Context, project string, serviceName string) error { + +// ServiceKafkaQuotaDeleteClientId Client ID. +func ServiceKafkaQuotaDeleteClientId(clientId string) [2]string { + return [2]string{"client-id", clientId} +} + +// ServiceKafkaQuotaDeleteUser Username. +func ServiceKafkaQuotaDeleteUser(user string) [2]string { + return [2]string{"user", user} +} +func (h *KafkaHandler) ServiceKafkaQuotaDelete(ctx context.Context, project string, serviceName string, query ...[2]string) error { + p := make([][2]string, 0, len(query)) + for _, v := range query { + p = append(p, v) + } path := fmt.Sprintf("/v1/project/%s/service/%s/quota", url.PathEscape(project), url.PathEscape(serviceName)) - _, err := h.doer.Do(ctx, "ServiceKafkaQuotaDelete", "DELETE", path, nil) + _, err := h.doer.Do(ctx, "ServiceKafkaQuotaDelete", "DELETE", path, nil, p...) return err } func (h *KafkaHandler) ServiceKafkaQuotaDescribe(ctx context.Context, project string, serviceName string) (*ServiceKafkaQuotaDescribeOut, error) { diff --git a/handler/service/service.go b/handler/service/service.go index 2ce6b84..7d348e2 100644 --- a/handler/service/service.go +++ b/handler/service/service.go @@ -99,7 +99,7 @@ type Handler interface { // ServiceGet get service information // GET /v1/project/{project}/service/{service_name} // https://api.aiven.io/doc/#tag/Service/operation/ServiceGet - ServiceGet(ctx context.Context, project string, serviceName string, query ...serviceGetQuery) (*ServiceGetOut, error) + ServiceGet(ctx context.Context, project string, serviceName string, query ...[2]string) (*ServiceGetOut, error) // ServiceGetMigrationStatus get migration status // GET /v1/project/{project}/service/{service_name}/migration @@ -134,7 +134,7 @@ type Handler interface { // ServiceIntegrationEndpointGet get service integration endpoint // GET /v1/project/{project}/integration_endpoint/{integration_endpoint_id} // https://api.aiven.io/doc/#tag/Service_Integrations/operation/ServiceIntegrationEndpointGet - ServiceIntegrationEndpointGet(ctx context.Context, project string, integrationEndpointId string, query ...serviceIntegrationEndpointGetQuery) (*ServiceIntegrationEndpointGetOut, error) + ServiceIntegrationEndpointGet(ctx context.Context, project string, integrationEndpointId string, query ...[2]string) (*ServiceIntegrationEndpointGetOut, error) // ServiceIntegrationEndpointList list available integration endpoints for project // GET /v1/project/{project}/integration_endpoint @@ -219,7 +219,7 @@ type Handler interface { // ServiceUpdate update service configuration // PUT /v1/project/{project}/service/{service_name} // https://api.aiven.io/doc/#tag/Service/operation/ServiceUpdate - ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...serviceUpdateQuery) (*ServiceUpdateOut, error) + ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...[2]string) (*ServiceUpdateOut, error) // ServiceUserCreate create a new (sub) user for service // POST /v1/project/{project}/service/{service_name}/user @@ -442,14 +442,11 @@ func (h *ServiceHandler) ServiceEnableWrites(ctx context.Context, project string return out.Until, nil } -// serviceGetQuery http query params private type -type serviceGetQuery [2]string - // ServiceGetIncludeSecrets Explicitly indicates that the client wants to read secrets that might be returned by this endpoint. -func ServiceGetIncludeSecrets(includeSecrets bool) serviceGetQuery { - return serviceGetQuery{"include_secrets", fmt.Sprintf("%t", includeSecrets)} +func ServiceGetIncludeSecrets(includeSecrets bool) [2]string { + return [2]string{"include_secrets", fmt.Sprintf("%t", includeSecrets)} } -func (h *ServiceHandler) ServiceGet(ctx context.Context, project string, serviceName string, query ...serviceGetQuery) (*ServiceGetOut, error) { +func (h *ServiceHandler) ServiceGet(ctx context.Context, project string, serviceName string, query ...[2]string) (*ServiceGetOut, error) { path := fmt.Sprintf("/v1/project/%s/service/%s", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceGet", "GET", path, nil) if err != nil { @@ -525,14 +522,11 @@ func (h *ServiceHandler) ServiceIntegrationEndpointDelete(ctx context.Context, p return err } -// serviceIntegrationEndpointGetQuery http query params private type -type serviceIntegrationEndpointGetQuery [2]string - // ServiceIntegrationEndpointGetIncludeSecrets Explicitly indicates that the client wants to read secrets that might be returned by this endpoint. -func ServiceIntegrationEndpointGetIncludeSecrets(includeSecrets bool) serviceIntegrationEndpointGetQuery { - return serviceIntegrationEndpointGetQuery{"include_secrets", fmt.Sprintf("%t", includeSecrets)} +func ServiceIntegrationEndpointGetIncludeSecrets(includeSecrets bool) [2]string { + return [2]string{"include_secrets", fmt.Sprintf("%t", includeSecrets)} } -func (h *ServiceHandler) ServiceIntegrationEndpointGet(ctx context.Context, project string, integrationEndpointId string, query ...serviceIntegrationEndpointGetQuery) (*ServiceIntegrationEndpointGetOut, error) { +func (h *ServiceHandler) ServiceIntegrationEndpointGet(ctx context.Context, project string, integrationEndpointId string, query ...[2]string) (*ServiceIntegrationEndpointGetOut, error) { path := fmt.Sprintf("/v1/project/%s/integration_endpoint/%s", url.PathEscape(project), url.PathEscape(integrationEndpointId)) b, err := h.doer.Do(ctx, "ServiceIntegrationEndpointGet", "GET", path, nil) if err != nil { @@ -746,14 +740,11 @@ func (h *ServiceHandler) ServiceTaskGet(ctx context.Context, project string, ser return &out.Task, nil } -// serviceUpdateQuery http query params private type -type serviceUpdateQuery [2]string - // ServiceUpdateAllowUncleanPoweroff Allows or disallows powering off a service if some WAL segments are not available for a future restoration of the service, which might result in data loss when powering the service back on -func ServiceUpdateAllowUncleanPoweroff(allowUncleanPoweroff bool) serviceUpdateQuery { - return serviceUpdateQuery{"allow_unclean_poweroff", fmt.Sprintf("%t", allowUncleanPoweroff)} +func ServiceUpdateAllowUncleanPoweroff(allowUncleanPoweroff bool) [2]string { + return [2]string{"allow_unclean_poweroff", fmt.Sprintf("%t", allowUncleanPoweroff)} } -func (h *ServiceHandler) ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...serviceUpdateQuery) (*ServiceUpdateOut, error) { +func (h *ServiceHandler) ServiceUpdate(ctx context.Context, project string, serviceName string, in *ServiceUpdateIn, query ...[2]string) (*ServiceUpdateOut, error) { path := fmt.Sprintf("/v1/project/%s/service/%s", url.PathEscape(project), url.PathEscape(serviceName)) b, err := h.doer.Do(ctx, "ServiceUpdate", "PUT", path, in) if err != nil {