Skip to content

Commit 603be58

Browse files
authored
patch list index (#45137)
* patch list index * fix mypy * use function overloads * update * hide list_indexes_with_selected_properties * updates * fix failure * fix pylint * fix pylint * Trailing whitespace
1 parent f8b9471 commit 603be58

File tree

20 files changed

+527
-67
lines changed

20 files changed

+527
-67
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"apiVersion": "2025-11-01-preview"
2+
"apiVersion": "2025-11-01-preview",
3+
"apiVersions": {
4+
"Search": "2025-11-01-preview"
5+
}
36
}

sdk/search/azure-search-documents/apiview-properties.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"azure.search.documents.indexes.models.SearchIndexKnowledgeSource": "Search.SearchIndexKnowledgeSource",
227227
"azure.search.documents.indexes.models.SearchIndexKnowledgeSourceParameters": "Search.SearchIndexKnowledgeSourceParameters",
228228
"azure.search.documents.knowledgebases.models.SearchIndexKnowledgeSourceParams": "Search.SearchIndexKnowledgeSourceParams",
229+
"azure.search.documents.indexes.models.SearchIndexResponse": "Search.SearchIndexResponse",
229230
"azure.search.documents.models.SearchRequest": "Search.SearchRequest",
230231
"azure.search.documents.indexes.models.SearchResourceEncryptionKey": "Search.SearchResourceEncryptionKey",
231232
"azure.search.documents.models.SearchResult": "Search.SearchResult",
@@ -396,8 +397,8 @@
396397
"azure.search.documents.aio.SearchIndexClient.create_synonym_map": "Customizations.SearchIndexClient.SynonymMaps.create",
397398
"azure.search.documents.SearchIndexClient.get_index": "Customizations.SearchIndexClient.Indexes.get",
398399
"azure.search.documents.aio.SearchIndexClient.get_index": "Customizations.SearchIndexClient.Indexes.get",
399-
"azure.search.documents.SearchIndexClient.list_indexes": "Customizations.SearchIndexClient.Indexes.list",
400-
"azure.search.documents.aio.SearchIndexClient.list_indexes": "Customizations.SearchIndexClient.Indexes.list",
400+
"azure.search.documents.SearchIndexClient.list_indexes_with_selected_properties": "Customizations.SearchIndexClient.Indexes.listWithSelectedProperties",
401+
"azure.search.documents.aio.SearchIndexClient.list_indexes_with_selected_properties": "Customizations.SearchIndexClient.Indexes.listWithSelectedProperties",
401402
"azure.search.documents.SearchIndexClient.create_index": "Customizations.SearchIndexClient.Indexes.create",
402403
"azure.search.documents.aio.SearchIndexClient.create_index": "Customizations.SearchIndexClient.Indexes.create",
403404
"azure.search.documents.SearchIndexClient.get_alias": "Customizations.SearchIndexClient.Aliases.get",

sdk/search/azure-search-documents/azure/search/documents/_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class SearchClient(_SearchClientOperationsMixin):
3434
~azure.core.credentials.TokenCredential
3535
:param index_name: The name of the index. Required.
3636
:type index_name: str
37-
:keyword api_version: The API version to use for this operation. Default value is
38-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
39-
behavior.
37+
:keyword api_version: The API version to use for this operation. Known values are
38+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
39+
default value may result in unsupported behavior.
4040
:paramtype api_version: str
4141
"""
4242

sdk/search/azure-search-documents/azure/search/documents/_configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
3131
~azure.core.credentials.TokenCredential
3232
:param index_name: The name of the index. Required.
3333
:type index_name: str
34-
:keyword api_version: The API version to use for this operation. Default value is
35-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
36-
behavior.
34+
:keyword api_version: The API version to use for this operation. Known values are
35+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
36+
default value may result in unsupported behavior.
3737
:paramtype api_version: str
3838
"""
3939

sdk/search/azure-search-documents/azure/search/documents/aio/_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class SearchClient(_SearchClientOperationsMixin):
3434
~azure.core.credentials_async.AsyncTokenCredential
3535
:param index_name: The name of the index. Required.
3636
:type index_name: str
37-
:keyword api_version: The API version to use for this operation. Default value is
38-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
39-
behavior.
37+
:keyword api_version: The API version to use for this operation. Known values are
38+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
39+
default value may result in unsupported behavior.
4040
:paramtype api_version: str
4141
"""
4242

sdk/search/azure-search-documents/azure/search/documents/aio/_configuration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class SearchClientConfiguration: # pylint: disable=too-many-instance-attributes
3131
~azure.core.credentials_async.AsyncTokenCredential
3232
:param index_name: The name of the index. Required.
3333
:type index_name: str
34-
:keyword api_version: The API version to use for this operation. Default value is
35-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
36-
behavior.
34+
:keyword api_version: The API version to use for this operation. Known values are
35+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
36+
default value may result in unsupported behavior.
3737
:paramtype api_version: str
3838
"""
3939

sdk/search/azure-search-documents/azure/search/documents/indexes/_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class SearchIndexClient(_SearchIndexClientOperationsMixin):
3232
credential type or a token credential type. Required.
3333
:type credential: ~azure.core.credentials.AzureKeyCredential or
3434
~azure.core.credentials.TokenCredential
35-
:keyword api_version: The API version to use for this operation. Default value is
36-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
37-
behavior.
35+
:keyword api_version: The API version to use for this operation. Known values are
36+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
37+
default value may result in unsupported behavior.
3838
:paramtype api_version: str
3939
"""
4040

@@ -111,9 +111,9 @@ class SearchIndexerClient(_SearchIndexerClientOperationsMixin):
111111
credential type or a token credential type. Required.
112112
:type credential: ~azure.core.credentials.AzureKeyCredential or
113113
~azure.core.credentials.TokenCredential
114-
:keyword api_version: The API version to use for this operation. Default value is
115-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
116-
behavior.
114+
:keyword api_version: The API version to use for this operation. Known values are
115+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
116+
default value may result in unsupported behavior.
117117
:paramtype api_version: str
118118
"""
119119

sdk/search/azure-search-documents/azure/search/documents/indexes/_configuration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class SearchIndexClientConfiguration: # pylint: disable=too-many-instance-attri
2929
credential type or a token credential type. Required.
3030
:type credential: ~azure.core.credentials.AzureKeyCredential or
3131
~azure.core.credentials.TokenCredential
32-
:keyword api_version: The API version to use for this operation. Default value is
33-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
34-
behavior.
32+
:keyword api_version: The API version to use for this operation. Known values are
33+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
34+
default value may result in unsupported behavior.
3535
:paramtype api_version: str
3636
"""
3737

@@ -84,9 +84,9 @@ class SearchIndexerClientConfiguration: # pylint: disable=too-many-instance-att
8484
credential type or a token credential type. Required.
8585
:type credential: ~azure.core.credentials.AzureKeyCredential or
8686
~azure.core.credentials.TokenCredential
87-
:keyword api_version: The API version to use for this operation. Default value is
88-
"2025-11-01-preview". Note that overriding this default value may result in unsupported
89-
behavior.
87+
:keyword api_version: The API version to use for this operation. Known values are
88+
"2025-11-01-preview" and None. Default value is "2025-11-01-preview". Note that overriding this
89+
default value may result in unsupported behavior.
9090
:paramtype api_version: str
9191
"""
9292

sdk/search/azure-search-documents/azure/search/documents/indexes/_operations/_operations.py

Lines changed: 118 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,28 @@ def build_search_index_get_index_request(name: str, **kwargs: Any) -> HttpReques
286286
return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
287287

288288

289-
def build_search_index_list_indexes_request(*, select: Optional[list[str]] = None, **kwargs: Any) -> HttpRequest:
289+
def build_search_index_list_indexes_request(**kwargs: Any) -> HttpRequest:
290+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
291+
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
292+
293+
api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2025-11-01-preview"))
294+
accept = _headers.pop("Accept", "application/json;odata.metadata=minimal")
295+
296+
# Construct URL
297+
_url = "/indexes"
298+
299+
# Construct parameters
300+
_params["api-version"] = _SERIALIZER.query("api_version", api_version, "str")
301+
302+
# Construct headers
303+
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
304+
305+
return HttpRequest(method="GET", url=_url, params=_params, headers=_headers, **kwargs)
306+
307+
308+
def build_search_index_list_indexes_with_selected_properties_request( # pylint: disable=name-too-long
309+
*, select: Optional[list[str]] = None, **kwargs: Any
310+
) -> HttpRequest:
290311
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
291312
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
292313

@@ -2210,13 +2231,9 @@ def get_index(self, name: str, **kwargs: Any) -> _models1.SearchIndex:
22102231
return deserialized # type: ignore
22112232

22122233
@distributed_trace
2213-
def list_indexes(self, *, select: Optional[list[str]] = None, **kwargs: Any) -> ItemPaged["_models1.SearchIndex"]:
2234+
def _list_indexes(self, **kwargs: Any) -> ItemPaged["_models1.SearchIndex"]:
22142235
"""Lists all indexes available for a search service.
22152236
2216-
:keyword select: Selects which top-level properties to retrieve. Specified as a comma-separated
2217-
list of JSON property names, or '*' for all properties. The default is all properties. Default
2218-
value is None.
2219-
:paramtype select: list[str]
22202237
:return: An iterator like instance of SearchIndex
22212238
:rtype: ~azure.core.paging.ItemPaged[~azure.search.documents.indexes.models.SearchIndex]
22222239
:raises ~azure.core.exceptions.HttpResponseError:
@@ -2238,7 +2255,6 @@ def prepare_request(next_link=None):
22382255
if not next_link:
22392256

22402257
_request = build_search_index_list_indexes_request(
2241-
select=select,
22422258
api_version=self._config.api_version,
22432259
headers=_headers,
22442260
params=_params,
@@ -2300,6 +2316,101 @@ def get_next(next_link=None):
23002316

23012317
return ItemPaged(get_next, extract_data)
23022318

2319+
@distributed_trace
2320+
def _list_indexes_with_selected_properties(
2321+
self, *, select: Optional[list[str]] = None, **kwargs: Any
2322+
) -> ItemPaged["_models1._models.SearchIndexResponse"]:
2323+
"""Lists all indexes available for a search service.
2324+
2325+
:keyword select: Selects which top-level properties to retrieve. Specified as a comma-separated
2326+
list of JSON property names, or '*' for all properties. The default is all properties. Default
2327+
value is None.
2328+
:paramtype select: list[str]
2329+
:return: An iterator like instance of SearchIndexResponse
2330+
:rtype:
2331+
~azure.core.paging.ItemPaged[~azure.search.documents.indexes.models._models.SearchIndexResponse]
2332+
:raises ~azure.core.exceptions.HttpResponseError:
2333+
"""
2334+
_headers = kwargs.pop("headers", {}) or {}
2335+
_params = kwargs.pop("params", {}) or {}
2336+
2337+
cls: ClsType[list[_models1._models.SearchIndexResponse]] = kwargs.pop("cls", None)
2338+
2339+
error_map: MutableMapping = {
2340+
401: ClientAuthenticationError,
2341+
404: ResourceNotFoundError,
2342+
409: ResourceExistsError,
2343+
304: ResourceNotModifiedError,
2344+
}
2345+
error_map.update(kwargs.pop("error_map", {}) or {})
2346+
2347+
def prepare_request(next_link=None):
2348+
if not next_link:
2349+
2350+
_request = build_search_index_list_indexes_with_selected_properties_request(
2351+
select=select,
2352+
api_version=self._config.api_version,
2353+
headers=_headers,
2354+
params=_params,
2355+
)
2356+
path_format_arguments = {
2357+
"endpoint": self._serialize.url(
2358+
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True
2359+
),
2360+
}
2361+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
2362+
2363+
else:
2364+
# make call to next link with the client's api-version
2365+
_parsed_next_link = urllib.parse.urlparse(next_link)
2366+
_next_request_params = case_insensitive_dict(
2367+
{
2368+
key: [urllib.parse.quote(v) for v in value]
2369+
for key, value in urllib.parse.parse_qs(_parsed_next_link.query).items()
2370+
}
2371+
)
2372+
_next_request_params["api-version"] = self._config.api_version
2373+
_request = HttpRequest(
2374+
"GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params
2375+
)
2376+
path_format_arguments = {
2377+
"endpoint": self._serialize.url(
2378+
"self._config.endpoint", self._config.endpoint, "str", skip_quote=True
2379+
),
2380+
}
2381+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
2382+
2383+
return _request
2384+
2385+
def extract_data(pipeline_response):
2386+
# pylint: disable=protected-access
2387+
deserialized = pipeline_response.http_response.json()
2388+
list_of_elem = _deserialize(list[_models1._models.SearchIndexResponse], deserialized.get("value", []))
2389+
if cls:
2390+
list_of_elem = cls(list_of_elem) # type: ignore
2391+
return None, iter(list_of_elem)
2392+
2393+
def get_next(next_link=None):
2394+
_request = prepare_request(next_link)
2395+
2396+
_stream = False
2397+
pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access
2398+
_request, stream=_stream, **kwargs
2399+
)
2400+
response = pipeline_response.http_response
2401+
2402+
if response.status_code not in [200]:
2403+
map_error(status_code=response.status_code, response=response, error_map=error_map)
2404+
error = _failsafe_deserialize(
2405+
_models2.ErrorResponse,
2406+
response,
2407+
)
2408+
raise HttpResponseError(response=response, model=error)
2409+
2410+
return pipeline_response
2411+
2412+
return ItemPaged(get_next, extract_data)
2413+
23032414
@overload
23042415
def create_index(
23052416
self, index: _models1.SearchIndex, *, content_type: str = "application/json", **kwargs: Any

sdk/search/azure-search-documents/azure/search/documents/indexes/_operations/_patch.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from azure.core.tracing.decorator import distributed_trace
1616

1717
from .. import models as _models
18+
from ..models._models import SearchIndexResponse as _SearchIndexResponse
1819
from ._operations import (
1920
_SearchIndexClientOperationsMixin as _SearchIndexClientOperationsMixinGenerated,
2021
_SearchIndexerClientOperationsMixin as _SearchIndexerClientOperationsMixinGenerated,
@@ -24,6 +25,37 @@
2425
import azure.search.documents
2526

2627

28+
def _convert_index_response(response: _SearchIndexResponse) -> _models.SearchIndex:
29+
"""Convert a SearchIndexResponse to a SearchIndex.
30+
31+
:param response: The SearchIndexResponse to convert.
32+
:type response: ~azure.search.documents.indexes.models._models.SearchIndexResponse
33+
:return: The converted SearchIndex.
34+
:rtype: ~azure.search.documents.indexes.models.SearchIndex
35+
"""
36+
return _models.SearchIndex(
37+
name=response.name,
38+
fields=response.fields or [],
39+
description=response.description,
40+
scoring_profiles=response.scoring_profiles,
41+
default_scoring_profile=response.default_scoring_profile,
42+
cors_options=response.cors_options,
43+
suggesters=response.suggesters,
44+
analyzers=response.analyzers,
45+
tokenizers=response.tokenizers,
46+
token_filters=response.token_filters,
47+
char_filters=response.char_filters,
48+
normalizers=response.normalizers,
49+
encryption_key=response.encryption_key,
50+
similarity=response.similarity,
51+
semantic_search=response.semantic,
52+
vector_search=response.vector_search,
53+
permission_filter_option=response.permission_filter_option,
54+
purview_enabled=response.purview_enabled,
55+
e_tag=response.e_tag,
56+
)
57+
58+
2759
class _SearchIndexClientOperationsMixin(_SearchIndexClientOperationsMixinGenerated):
2860
"""Custom operations mixin for SearchIndexClient."""
2961

@@ -325,6 +357,29 @@ def delete_knowledge_source(
325357
**kwargs,
326358
)
327359

360+
@distributed_trace
361+
def list_indexes(self, *, select: Optional[List[str]] = None, **kwargs: Any) -> ItemPaged[_models.SearchIndex]:
362+
"""Lists all indexes available for a search service.
363+
364+
:keyword select: Selects which top-level properties to retrieve. Specified as a comma-separated
365+
list of JSON property names, or '*' for all properties. The default is all properties.
366+
Default value is None.
367+
:paramtype select: list[str]
368+
:return: An iterator like instance of SearchIndex
369+
:rtype: ~azure.core.paging.ItemPaged[~azure.search.documents.indexes.models.SearchIndex]
370+
:raises ~azure.core.exceptions.HttpResponseError:
371+
"""
372+
if select is not None:
373+
return cast(
374+
ItemPaged[_models.SearchIndex],
375+
self._list_indexes_with_selected_properties(
376+
select=select,
377+
cls=lambda objs: [_convert_index_response(x) for x in objs],
378+
**kwargs,
379+
),
380+
)
381+
return self._list_indexes(**kwargs)
382+
328383
@distributed_trace
329384
def list_index_names(self, **kwargs: Any) -> ItemPaged[str]:
330385
"""Lists the names of all indexes available for a search service.
@@ -333,7 +388,7 @@ def list_index_names(self, **kwargs: Any) -> ItemPaged[str]:
333388
:rtype: ~azure.core.paging.ItemPaged[str]
334389
:raises ~azure.core.exceptions.HttpResponseError:
335390
"""
336-
names = self.list_indexes(cls=lambda objs: [x.name for x in objs], **kwargs)
391+
names = self._list_indexes(cls=lambda objs: [x.name for x in objs], **kwargs)
337392
return cast(ItemPaged[str], names)
338393

339394
@distributed_trace

0 commit comments

Comments
 (0)