diff --git a/.codegen/service.py.tmpl b/.codegen/service.py.tmpl index dd1abfea0..052116424 100644 --- a/.codegen/service.py.tmpl +++ b/.codegen/service.py.tmpl @@ -270,29 +270,32 @@ class {{.Name}}API:{{if .Description}} {{- end}} while True: json = {{template "method-do" .}} - if '{{.Pagination.Results.Name}}' not in json or not json['{{.Pagination.Results.Name}}']: + if '{{.Pagination.Results.Name}}' in json: + for v in json['{{.Pagination.Results.Name}}']: + {{if .NeedsOffsetDedupe -}} + i = v['{{.IdentifierField.Name}}'] + if i in seen: + continue + seen.add(i) + {{end -}} + yield {{.Pagination.Entity.PascalName}}.from_dict(v) + {{ if .Pagination.Token -}} + if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']: return - for v in json['{{.Pagination.Results.Name}}']: - {{if .NeedsOffsetDedupe -}} - i = v['{{.IdentifierField.Name}}'] - if i in seen: - continue - seen.add(i) - {{end -}} - yield {{.Pagination.Entity.PascalName}}.from_dict(v) - {{if eq .Path "/api/2.0/clusters/events" -}} + {{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}'] + {{- else if eq .Path "/api/2.0/clusters/events" -}} if 'next_page' not in json or not json['next_page']: return body = json['next_page'] - {{- else if .Pagination.Token -}} - if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']: + {{- else -}} + if '{{.Pagination.Results.Name}}' not in json or not json['{{.Pagination.Results.Name}}']: return - {{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}'] - {{- else if eq .Pagination.Increment 1 -}} + {{ if eq .Pagination.Increment 1 -}} query['{{.Pagination.Offset.Name}}'] += 1 {{- else -}} query['{{.Pagination.Offset.Name}}'] += len(json['{{.Pagination.Results.Name}}']) {{- end}} + {{- end}} {{else -}} json = {{template "method-do" .}} parsed = {{.Response.PascalName}}.from_dict(json).{{template "safe-snake-name" .Pagination.Results}} diff --git a/databricks/sdk/service/catalog.py b/databricks/sdk/service/catalog.py index c1c068aff..5c240c62e 100755 --- a/databricks/sdk/service/catalog.py +++ b/databricks/sdk/service/catalog.py @@ -5804,10 +5804,9 @@ def list(self, '/api/2.1/unity-catalog/external-locations', query=query, headers=headers) - if 'external_locations' not in json or not json['external_locations']: - return - for v in json['external_locations']: - yield ExternalLocationInfo.from_dict(v) + if 'external_locations' in json: + for v in json['external_locations']: + yield ExternalLocationInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -5988,10 +5987,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/functions', query=query, headers=headers) - if 'functions' not in json or not json['functions']: - return - for v in json['functions']: - yield FunctionInfo.from_dict(v) + if 'functions' in json: + for v in json['functions']: + yield FunctionInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -6718,10 +6716,9 @@ def list(self, f'/api/2.1/unity-catalog/models/{full_name}/versions', query=query, headers=headers) - if 'model_versions' not in json or not json['model_versions']: - return - for v in json['model_versions']: - yield ModelVersionInfo.from_dict(v) + if 'model_versions' in json: + for v in json['model_versions']: + yield ModelVersionInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -6928,10 +6925,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/models', query=query, headers=headers) - if 'registered_models' not in json or not json['registered_models']: - return - for v in json['registered_models']: - yield RegisteredModelInfo.from_dict(v) + if 'registered_models' in json: + for v in json['registered_models']: + yield RegisteredModelInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -7112,10 +7108,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/schemas', query=query, headers=headers) - if 'schemas' not in json or not json['schemas']: - return - for v in json['schemas']: - yield SchemaInfo.from_dict(v) + if 'schemas' in json: + for v in json['schemas']: + yield SchemaInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -7306,10 +7301,9 @@ def list(self, '/api/2.1/unity-catalog/storage-credentials', query=query, headers=headers) - if 'storage_credentials' not in json or not json['storage_credentials']: - return - for v in json['storage_credentials']: - yield StorageCredentialInfo.from_dict(v) + if 'storage_credentials' in json: + for v in json['storage_credentials']: + yield StorageCredentialInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -7709,10 +7703,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/tables', query=query, headers=headers) - if 'tables' not in json or not json['tables']: - return - for v in json['tables']: - yield TableInfo.from_dict(v) + if 'tables' in json: + for v in json['tables']: + yield TableInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -7765,10 +7758,9 @@ def list_summaries(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/table-summaries', query=query, headers=headers) - if 'tables' not in json or not json['tables']: - return - for v in json['tables']: - yield TableSummary.from_dict(v) + if 'tables' in json: + for v in json['tables']: + yield TableSummary.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/compute.py b/databricks/sdk/service/compute.py index 816f0db3a..efa4c54b8 100755 --- a/databricks/sdk/service/compute.py +++ b/databricks/sdk/service/compute.py @@ -6405,10 +6405,9 @@ def events(self, while True: json = self._api.do('POST', '/api/2.0/clusters/events', body=body, headers=headers) - if 'events' not in json or not json['events']: - return - for v in json['events']: - yield ClusterEvent.from_dict(v) + if 'events' in json: + for v in json['events']: + yield ClusterEvent.from_dict(v) if 'next_page' not in json or not json['next_page']: return body = json['next_page'] @@ -7733,10 +7732,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.0/policy-families', query=query, headers=headers) - if 'policy_families' not in json or not json['policy_families']: - return - for v in json['policy_families']: - yield PolicyFamily.from_dict(v) + if 'policy_families' in json: + for v in json['policy_families']: + yield PolicyFamily.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/iam.py b/databricks/sdk/service/iam.py index 5a4131f19..18d16d3fb 100755 --- a/databricks/sdk/service/iam.py +++ b/databricks/sdk/service/iam.py @@ -1465,14 +1465,15 @@ def list(self, f'/api/2.0/accounts/{self._api.account_id}/scim/v2/Groups', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield Group.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield Group.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, @@ -1705,14 +1706,15 @@ def list(self, f'/api/2.0/accounts/{self._api.account_id}/scim/v2/ServicePrincipals', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield ServicePrincipal.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield ServicePrincipal.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, @@ -2005,14 +2007,15 @@ def list(self, f'/api/2.0/accounts/{self._api.account_id}/scim/v2/Users', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield User.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield User.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, @@ -2267,14 +2270,15 @@ def list(self, if "count" not in query: query['count'] = 100 while True: json = self._api.do('GET', '/api/2.0/preview/scim/v2/Groups', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield Group.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield Group.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, @@ -2646,14 +2650,15 @@ def list(self, '/api/2.0/preview/scim/v2/ServicePrincipals', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield ServicePrincipal.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield ServicePrincipal.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, @@ -2955,14 +2960,15 @@ def list(self, if "count" not in query: query['count'] = 100 while True: json = self._api.do('GET', '/api/2.0/preview/scim/v2/Users', query=query, headers=headers) + if 'Resources' in json: + for v in json['Resources']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield User.from_dict(v) if 'Resources' not in json or not json['Resources']: return - for v in json['Resources']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield User.from_dict(v) query['startIndex'] += len(json['Resources']) def patch(self, diff --git a/databricks/sdk/service/jobs.py b/databricks/sdk/service/jobs.py index e7fef2de3..c9453ae04 100755 --- a/databricks/sdk/service/jobs.py +++ b/databricks/sdk/service/jobs.py @@ -4945,10 +4945,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/jobs/list', query=query, headers=headers) - if 'jobs' not in json or not json['jobs']: - return - for v in json['jobs']: - yield BaseJob.from_dict(v) + if 'jobs' in json: + for v in json['jobs']: + yield BaseJob.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -5017,10 +5016,9 @@ def list_runs(self, while True: json = self._api.do('GET', '/api/2.1/jobs/runs/list', query=query, headers=headers) - if 'runs' not in json or not json['runs']: - return - for v in json['runs']: - yield BaseRun.from_dict(v) + if 'runs' in json: + for v in json['runs']: + yield BaseRun.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/ml.py b/databricks/sdk/service/ml.py index ff2da8655..8194f5436 100755 --- a/databricks/sdk/service/ml.py +++ b/databricks/sdk/service/ml.py @@ -3710,10 +3710,9 @@ def get_history(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/metrics/get-history', query=query, headers=headers) - if 'metrics' not in json or not json['metrics']: - return - for v in json['metrics']: - yield Metric.from_dict(v) + if 'metrics' in json: + for v in json['metrics']: + yield Metric.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -3807,10 +3806,9 @@ def list_artifacts(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/artifacts/list', query=query, headers=headers) - if 'files' not in json or not json['files']: - return - for v in json['files']: - yield FileInfo.from_dict(v) + if 'files' in json: + for v in json['files']: + yield FileInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -3844,10 +3842,9 @@ def list_experiments(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/experiments/list', query=query, headers=headers) - if 'experiments' not in json or not json['experiments']: - return - for v in json['experiments']: - yield Experiment.from_dict(v) + if 'experiments' in json: + for v in json['experiments']: + yield Experiment.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -4125,10 +4122,9 @@ def search_experiments(self, while True: json = self._api.do('POST', '/api/2.0/mlflow/experiments/search', body=body, headers=headers) - if 'experiments' not in json or not json['experiments']: - return - for v in json['experiments']: - yield Experiment.from_dict(v) + if 'experiments' in json: + for v in json['experiments']: + yield Experiment.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return body['page_token'] = json['next_page_token'] @@ -4186,10 +4182,9 @@ def search_runs(self, while True: json = self._api.do('POST', '/api/2.0/mlflow/runs/search', body=body, headers=headers) - if 'runs' not in json or not json['runs']: - return - for v in json['runs']: - yield Run.from_dict(v) + if 'runs' in json: + for v in json['runs']: + yield Run.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return body['page_token'] = json['next_page_token'] @@ -4903,10 +4898,9 @@ def list_models(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/registered-models/list', query=query, headers=headers) - if 'registered_models' not in json or not json['registered_models']: - return - for v in json['registered_models']: - yield Model.from_dict(v) + if 'registered_models' in json: + for v in json['registered_models']: + yield Model.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -4963,10 +4957,9 @@ def list_webhooks(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/registry-webhooks/list', query=query, headers=headers) - if 'webhooks' not in json or not json['webhooks']: - return - for v in json['webhooks']: - yield RegistryWebhook.from_dict(v) + if 'webhooks' in json: + for v in json['webhooks']: + yield RegistryWebhook.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -5062,10 +5055,9 @@ def search_model_versions(self, while True: json = self._api.do('GET', '/api/2.0/mlflow/model-versions/search', query=query, headers=headers) - if 'model_versions' not in json or not json['model_versions']: - return - for v in json['model_versions']: - yield ModelVersion.from_dict(v) + if 'model_versions' in json: + for v in json['model_versions']: + yield ModelVersion.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -5108,10 +5100,9 @@ def search_models(self, '/api/2.0/mlflow/registered-models/search', query=query, headers=headers) - if 'registered_models' not in json or not json['registered_models']: - return - for v in json['registered_models']: - yield Model.from_dict(v) + if 'registered_models' in json: + for v in json['registered_models']: + yield Model.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/oauth2.py b/databricks/sdk/service/oauth2.py index 9a48d9082..bf0fc4436 100755 --- a/databricks/sdk/service/oauth2.py +++ b/databricks/sdk/service/oauth2.py @@ -629,10 +629,9 @@ def list(self, f'/api/2.0/accounts/{self._api.account_id}/oauth2/published-apps/', query=query, headers=headers) - if 'apps' not in json or not json['apps']: - return - for v in json['apps']: - yield PublishedAppOutput.from_dict(v) + if 'apps' in json: + for v in json['apps']: + yield PublishedAppOutput.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/pipelines.py b/databricks/sdk/service/pipelines.py index 6ef8efa73..b27b5cbe0 100755 --- a/databricks/sdk/service/pipelines.py +++ b/databricks/sdk/service/pipelines.py @@ -1891,10 +1891,9 @@ def list_pipeline_events(self, f'/api/2.0/pipelines/{pipeline_id}/events', query=query, headers=headers) - if 'events' not in json or not json['events']: - return - for v in json['events']: - yield PipelineEvent.from_dict(v) + if 'events' in json: + for v in json['events']: + yield PipelineEvent.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -1940,10 +1939,9 @@ def list_pipelines(self, while True: json = self._api.do('GET', '/api/2.0/pipelines', query=query, headers=headers) - if 'statuses' not in json or not json['statuses']: - return - for v in json['statuses']: - yield PipelineStateInfo.from_dict(v) + if 'statuses' in json: + for v in json['statuses']: + yield PipelineStateInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/settings.py b/databricks/sdk/service/settings.py index c13adb756..e542c250f 100755 --- a/databricks/sdk/service/settings.py +++ b/databricks/sdk/service/settings.py @@ -2075,10 +2075,9 @@ def list_network_connectivity_configurations(self, f'/api/2.0/accounts/{self._api.account_id}/network-connectivity-configs', query=query, headers=headers) - if 'items' not in json or not json['items']: - return - for v in json['items']: - yield NetworkConnectivityConfiguration.from_dict(v) + if 'items' in json: + for v in json['items']: + yield NetworkConnectivityConfiguration.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -2110,10 +2109,9 @@ def list_private_endpoint_rules( f'/api/2.0/accounts/{self._api.account_id}/network-connectivity-configs/{network_connectivity_config_id}/private-endpoint-rules', query=query, headers=headers) - if 'items' not in json or not json['items']: - return - for v in json['items']: - yield NccAzurePrivateEndpointRule.from_dict(v) + if 'items' in json: + for v in json['items']: + yield NccAzurePrivateEndpointRule.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/sharing.py b/databricks/sdk/service/sharing.py index 37753bdcb..ef4f98684 100755 --- a/databricks/sdk/service/sharing.py +++ b/databricks/sdk/service/sharing.py @@ -1644,10 +1644,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.1/unity-catalog/clean-rooms', query=query, headers=headers) - if 'clean_rooms' not in json or not json['clean_rooms']: - return - for v in json['clean_rooms']: - yield CleanRoomInfo.from_dict(v) + if 'clean_rooms' in json: + for v in json['clean_rooms']: + yield CleanRoomInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/sql.py b/databricks/sdk/service/sql.py index 7eacd64e3..b7dc9a297 100755 --- a/databricks/sdk/service/sql.py +++ b/databricks/sdk/service/sql.py @@ -4073,14 +4073,15 @@ def list(self, query['page'] = 1 while True: json = self._api.do('GET', '/api/2.0/preview/sql/dashboards', query=query, headers=headers) + if 'results' in json: + for v in json['results']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield Dashboard.from_dict(v) if 'results' not in json or not json['results']: return - for v in json['results']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield Dashboard.from_dict(v) query['page'] += 1 def restore(self, dashboard_id: str): @@ -4387,14 +4388,15 @@ def list(self, query['page'] = 1 while True: json = self._api.do('GET', '/api/2.0/preview/sql/queries', query=query, headers=headers) + if 'results' in json: + for v in json['results']: + i = v['id'] + if i in seen: + continue + seen.add(i) + yield Query.from_dict(v) if 'results' not in json or not json['results']: return - for v in json['results']: - i = v['id'] - if i in seen: - continue - seen.add(i) - yield Query.from_dict(v) query['page'] += 1 def restore(self, query_id: str): @@ -4499,10 +4501,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.0/sql/history/queries', query=query, headers=headers) - if 'res' not in json or not json['res']: - return - for v in json['res']: - yield QueryInfo.from_dict(v) + if 'res' in json: + for v in json['res']: + yield QueryInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/vectorsearch.py b/databricks/sdk/service/vectorsearch.py index 95ad717cb..52aaf172a 100755 --- a/databricks/sdk/service/vectorsearch.py +++ b/databricks/sdk/service/vectorsearch.py @@ -978,10 +978,9 @@ def list_endpoints(self, *, page_token: Optional[str] = None) -> Iterator[Endpoi while True: json = self._api.do('GET', '/api/2.0/vector-search/endpoints', query=query, headers=headers) - if 'endpoints' not in json or not json['endpoints']: - return - for v in json['endpoints']: - yield EndpointInfo.from_dict(v) + if 'endpoints' in json: + for v in json['endpoints']: + yield EndpointInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] @@ -1117,10 +1116,9 @@ def list_indexes(self, while True: json = self._api.do('GET', '/api/2.0/vector-search/indexes', query=query, headers=headers) - if 'vector_indexes' not in json or not json['vector_indexes']: - return - for v in json['vector_indexes']: - yield MiniVectorIndex.from_dict(v) + if 'vector_indexes' in json: + for v in json['vector_indexes']: + yield MiniVectorIndex.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['page_token'] = json['next_page_token'] diff --git a/databricks/sdk/service/workspace.py b/databricks/sdk/service/workspace.py index cf5dacc3a..142fff57d 100755 --- a/databricks/sdk/service/workspace.py +++ b/databricks/sdk/service/workspace.py @@ -1516,10 +1516,9 @@ def list(self, while True: json = self._api.do('GET', '/api/2.0/repos', query=query, headers=headers) - if 'repos' not in json or not json['repos']: - return - for v in json['repos']: - yield RepoInfo.from_dict(v) + if 'repos' in json: + for v in json['repos']: + yield RepoInfo.from_dict(v) if 'next_page_token' not in json or not json['next_page_token']: return query['next_page_token'] = json['next_page_token']