Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove multiapi generated code #18052

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

VERSION = "unknown"

class SearchClientConfiguration(Configuration):
"""Configuration for SearchClient.

Expand Down Expand Up @@ -46,7 +44,8 @@ def __init__(

self.endpoint = endpoint
self.index_name = index_name
kwargs.setdefault('sdk_moniker', 'azure-search-documents/{}'.format(VERSION))
self.api_version = "2020-06-30-Preview"
kwargs.setdefault('sdk_moniker', 'search-documents/{}'.format(VERSION))
self._configure(**kwargs)

def _configure(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,124 +1,85 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import TYPE_CHECKING

from azure.core import PipelineClient
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from msrest import Deserializer, Serializer

from ._configuration import SearchClientConfiguration

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional
from typing import Any

from azure.core.pipeline.transport import HttpRequest, HttpResponse

class _SDKClient(object):
def __init__(self, *args, **kwargs):
"""This is a fake class to support current implemetation of MultiApiClientMixin."
Will be removed in final version of multiapi azure-core based client
"""
pass
from ._configuration import SearchClientConfiguration
from .operations import DocumentsOperations
from . import models

class SearchClient(MultiApiClientMixin, _SDKClient):
"""Client that can be used to query an index and upload, merge, or delete documents.

This ready contains multiple API versions, to help you deal with all of the Azure clouds
(Azure Stack, Azure Government, Azure China, etc.).
By default, it uses the latest API version available on public Azure.
For production, you should stick to a particular api-version and/or profile.
The profile sets a mapping between an operation group and its API version.
The api-version parameter sets the default API version if the operation
group is not described in the profile.
class SearchClient(object):
"""Client that can be used to query an index and upload, merge, or delete documents.

:ivar documents: DocumentsOperations operations
:vartype documents: azure.search.documents.operations.DocumentsOperations
:param endpoint: The endpoint URL of the search service.
:type endpoint: str
:param index_name: The name of the index.
:type index_name: str
:param api_version: API version to use if no profile is provided, or if missing in profile.
:type api_version: str
:param profile: A profile definition, from KnownProfiles to dict.
:type profile: azure.profiles.KnownProfiles
"""

DEFAULT_API_VERSION = '2020-06-30-Preview'
_PROFILE_TAG = "azure.search.documents.SearchClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
None: DEFAULT_API_VERSION,
}},
_PROFILE_TAG + " latest"
)

def __init__(
self,
endpoint, # type: str
index_name, # type: str
api_version=None, # type: Optional[str]
profile=KnownProfiles.default, # type: KnownProfiles
**kwargs # type: Any
):
if api_version == '2020-06-30' or api_version == '2020-06-30-Preview':
base_url = '{endpoint}/indexes(\'{indexName}\')'
else:
raise ValueError("API version {} is not available".format(api_version))
# type: (...) -> None
base_url = '{endpoint}/indexes(\'{indexName}\')'
self._config = SearchClientConfiguration(endpoint, index_name, **kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
super(SearchClient, self).__init__(
api_version=api_version,
profile=profile
)

@classmethod
def _models_dict(cls, api_version):
return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)}
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

@classmethod
def models(cls, api_version=DEFAULT_API_VERSION):
"""Module depends on the API version:
self.documents = DocumentsOperations(
self._client, self._config, self._serialize, self._deserialize)

* 2020-06-30: :mod:`v2020_06.models<azure.search.documents.v2020_06.models>`
* 2020-06-30-Preview: :mod:`v2020_06_preview.models<azure.search.documents.v2020_06_preview.models>`
"""
if api_version == '2020-06-30':
from .v2020_06 import models
return models
elif api_version == '2020-06-30-Preview':
from .v2020_06_preview import models
return models
raise ValueError("API version {} is not available".format(api_version))

@property
def documents(self):
"""Instance depends on the API version:

* 2020-06-30: :class:`DocumentsOperations<azure.search.documents.v2020_06.operations.DocumentsOperations>`
* 2020-06-30-Preview: :class:`DocumentsOperations<azure.search.documents.v2020_06_preview.operations.DocumentsOperations>`
def _send_request(self, http_request, **kwargs):
# type: (HttpRequest, Any) -> HttpResponse
"""Runs the network request through the client's chained policies.

:param http_request: The network request you want to make. Required.
:type http_request: ~azure.core.pipeline.transport.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.pipeline.transport.HttpResponse
"""
api_version = self._get_api_version('documents')
if api_version == '2020-06-30':
from .v2020_06.operations import DocumentsOperations as OperationClass
elif api_version == '2020-06-30-Preview':
from .v2020_06_preview.operations import DocumentsOperations as OperationClass
else:
raise ValueError("API version {} does not have operation group 'documents'".format(api_version))
return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
'indexName': self._serialize.url("self._config.index_name", self._config.index_name, 'str'),
}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
stream = kwargs.pop("stream", True)
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
return pipeline_response.http_response

def close(self):
# type: () -> None
self._client.close()

def __enter__(self):
# type: () -> SearchClient
self._client.__enter__()
return self

def __exit__(self, *exc_details):
# type: (Any) -> None
self._client.__exit__(*exc_details)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

from .._version import VERSION
VERSION = "unknown"

class SearchClientConfiguration(Configuration):
"""Configuration for SearchClient.
Expand All @@ -31,7 +29,7 @@ def __init__(
self,
endpoint: str,
index_name: str,
**kwargs # type: Any
**kwargs: Any
) -> None:
if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand All @@ -41,7 +39,8 @@ def __init__(

self.endpoint = endpoint
self.index_name = index_name
kwargs.setdefault('sdk_moniker', 'azure-search-documents/{}'.format(VERSION))
self.api_version = "2020-06-30-Preview"
kwargs.setdefault('sdk_moniker', 'search-documents/{}'.format(VERSION))
self._configure(**kwargs)

def _configure(
Expand Down
Loading