From 983f717754fa68b3b736f5e7ebb2b558c217eaf7 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 10:09:16 -0800 Subject: [PATCH 01/10] Add as_dict support --- .../search/documents/indexes/models/_index.py | 50 +++++++ .../documents/indexes/models/_models.py | 125 ++++++++++++++++++ .../tests/test_serialization.py | 28 ++++ 3 files changed, 203 insertions(+) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index 28ede871d7c9..a5241a745a44 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -253,6 +253,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchFi """ return cls._from_generated(_SearchField.deserialize(data, content_type=content_type)) # type: ignore + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SearchField": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SearchField instance + :rtype: SearchField + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SearchField.from_dict(data, content_type=content_type)) + def SimpleField( *, @@ -674,6 +699,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchIn """ return cls._from_generated(_SearchIndex.deserialize(data, content_type=content_type)) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SearchIndex": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SearchIndex instance + :rtype: SearchIndex + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SearchIndex.from_dict(data, content_type=content_type)) + def pack_search_field(search_field: SearchField) -> _SearchField: if isinstance(search_field, dict): diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 14d0ff763c5d..9b751e620e4b 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -141,6 +141,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchIn """ return cls._from_generated(_SearchIndexerSkillset.deserialize(data, content_type=content_type)) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SearchIndexerSkillset": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SearchIndexerSkillset instance + :rtype: SearchIndexerSkillset + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SearchIndexerSkillset.from_dict(data, content_type=content_type)) + class EntityRecognitionSkillVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the Entity Recognition skill version to use.""" @@ -465,6 +490,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "AnalyzeT """ return cls._from_analyze_request(AnalyzeRequest.deserialize(data, content_type=content_type)) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "AnalyzeTextOptions": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A AnalyzeTextOptions instance + :rtype: AnalyzeTextOptions + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(AnalyzeRequest.from_dict(data, content_type=content_type)) + class CustomAnalyzer(LexicalAnalyzer): """Allows you to take control over the process of converting text into indexable/searchable tokens. @@ -764,6 +814,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchRe _SearchResourceEncryptionKey.deserialize(data, content_type=content_type) ) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SearchResourceEncryptionKey": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SearchResourceEncryptionKey instance + :rtype: SearchResourceEncryptionKey + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SearchResourceEncryptionKey.from_dict(data, content_type=content_type)) + class SynonymMap: """Represents a synonym map definition. @@ -841,6 +916,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SynonymM """ return cls._from_generated(_SynonymMap.deserialize(data, content_type=content_type)) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SynonymMap": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SynonymMap instance + :rtype: SynonymMap + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SynonymMap.from_dict(data, content_type=content_type)) + class SearchIndexerDataSourceConnection: """Represents a datasource connection definition, which can be used to configure an indexer. @@ -946,6 +1046,31 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchIn """ return cls._from_generated(_SearchIndexerDataSource.deserialize(data, content_type=content_type)) + def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: + """Return a dict that can be serialized using json.dump. + + :param bool keep_readonly: If you want to serialize the readonly attributes + :returns: A dict JSON compatible object + :rtype: dict + """ + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + + @classmethod + def from_dict( + cls, + data: Any, + content_type: Optional[str] = None, + ) -> "SearchIndexerDataSourceConnection": + """Parse a dict using given key extractor return a model. + + :param dict data: A dict using RestAPI structure + :param str content_type: JSON by default, set application/xml if XML. + :returns: A SearchIndexerDataSourceConnection instance + :rtype: SearchIndexerDataSourceConnection + :raises: DeserializationError if something went wrong + """ + return cls._from_generated(_SearchIndexerDataSource.from_dict(data, content_type=content_type)) + def pack_analyzer(analyzer): if not analyzer: diff --git a/sdk/search/azure-search-documents/tests/test_serialization.py b/sdk/search/azure-search-documents/tests/test_serialization.py index 44a1d81f2a0c..1db085ef3a05 100644 --- a/sdk/search/azure-search-documents/tests/test_serialization.py +++ b/sdk/search/azure-search-documents/tests/test_serialization.py @@ -77,3 +77,31 @@ def test_serialize_search_indexer_skillset(): serialized_skillset = skillset.serialize() skillset = SearchIndexerSkillset.deserialize(serialized_skillset) assert skillset + +def test_serialize_search_index_dict(): + new_index_name = "hotels" + fields = [ + SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True), + SimpleField(name="baseRate", type=SearchFieldDataType.Double), + SearchableField(name="description", type=SearchFieldDataType.String, collection=True), + SearchableField(name="hotelName", type=SearchFieldDataType.String), + ComplexField( + name="address", + fields=[ + SimpleField(name="streetAddress", type=SearchFieldDataType.String), + SimpleField(name="city", type=SearchFieldDataType.String), + SimpleField(name="state", type=SearchFieldDataType.String), + ], + collection=True, + ), + ] + cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) + scoring_profile = ScoringProfile(name="MyProfile") + scoring_profiles = [] + scoring_profiles.append(scoring_profile) + index = SearchIndex( + name=new_index_name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options + ) + search_index_serialized_dict = index.as_dict() + search_index = SearchIndex.from_dict(search_index_serialized_dict) + assert search_index From 107681083523a9edeb4241a19dd7b05a0532b7c3 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 10:49:02 -0800 Subject: [PATCH 02/10] updates --- .../azure/search/documents/indexes/models/_index.py | 8 ++++---- .../azure/search/documents/indexes/models/_models.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index a5241a745a44..73da79248317 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -205,7 +205,7 @@ def _to_generated(self) -> _SearchField: ) @classmethod - def _from_generated(cls, search_field): + def _from_generated(cls, search_field) -> "SearchField": if not search_field: return None # pylint:disable=protected-access @@ -251,7 +251,7 @@ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchFi :returns: A SearchField instance :raises: DeserializationError if something went wrong """ - return cls._from_generated(_SearchField.deserialize(data, content_type=content_type)) # type: ignore + return cls._from_generated(_SearchField.deserialize(data, content_type=content_type)) def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[str, Any]: """Return a dict that can be serialized using json.dump. @@ -260,7 +260,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( @@ -706,7 +706,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 9b751e620e4b..72fdfb95cd69 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -148,7 +148,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( @@ -497,7 +497,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_analyze_request().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( @@ -513,7 +513,7 @@ def from_dict( :rtype: AnalyzeTextOptions :raises: DeserializationError if something went wrong """ - return cls._from_generated(AnalyzeRequest.from_dict(data, content_type=content_type)) + return cls._from_analyze_request(AnalyzeRequest.from_dict(data, content_type=content_type)) class CustomAnalyzer(LexicalAnalyzer): @@ -821,7 +821,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( @@ -923,7 +923,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( @@ -1053,7 +1053,7 @@ def as_dict(self, keep_readonly: bool = True, **kwargs: Any) -> MutableMapping[s :returns: A dict JSON compatible object :rtype: dict """ - return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) + return self._to_generated().as_dict(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def from_dict( From 8f94602b240928b517de47a71c8e18457748e196 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 11:29:56 -0800 Subject: [PATCH 03/10] updates --- .../azure/search/documents/indexes/models/_index.py | 2 -- .../azure/search/documents/indexes/models/_models.py | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index 73da79248317..a796cc8e43d6 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -206,8 +206,6 @@ def _to_generated(self) -> _SearchField: @classmethod def _from_generated(cls, search_field) -> "SearchField": - if not search_field: - return None # pylint:disable=protected-access fields = [SearchField._from_generated(x) for x in search_field.fields] if search_field.fields else None hidden = not search_field.retrievable if search_field.retrievable is not None else None diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 72fdfb95cd69..b9a569700ddf 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -1,3 +1,4 @@ +# pylint: disable=too-many-lines # ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for @@ -776,7 +777,7 @@ def _to_generated(self): ) @classmethod - def _from_generated(cls, search_resource_encryption_key): + def _from_generated(cls, search_resource_encryption_key) -> "SearchResourceEncryptionKey": if not search_resource_encryption_key: return None if search_resource_encryption_key.access_credentials: From d3b008595b648441b57ce063ca38f8e017fc2eee Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 11:56:31 -0800 Subject: [PATCH 04/10] Update --- .../azure/search/documents/indexes/models/_models.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index b9a569700ddf..63f6540d1aed 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -778,8 +778,6 @@ def _to_generated(self): @classmethod def _from_generated(cls, search_resource_encryption_key) -> "SearchResourceEncryptionKey": - if not search_resource_encryption_key: - return None if search_resource_encryption_key.access_credentials: application_id = search_resource_encryption_key.access_credentials.application_id application_secret = search_resource_encryption_key.access_credentials.application_secret From 733616f279a8bbc57c287ce763ed77d282f77f9c Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 12:42:40 -0800 Subject: [PATCH 05/10] update --- .../azure/search/documents/indexes/models/_index.py | 8 +++++--- .../azure/search/documents/indexes/models/_models.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index a796cc8e43d6..130090714bf9 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -205,7 +205,9 @@ def _to_generated(self) -> _SearchField: ) @classmethod - def _from_generated(cls, search_field) -> "SearchField": + def _from_generated(cls, search_field) -> Optional["SearchField"]: + if not search_field: + return None # pylint:disable=protected-access fields = [SearchField._from_generated(x) for x in search_field.fields] if search_field.fields else None hidden = not search_field.retrievable if search_field.retrievable is not None else None @@ -241,7 +243,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> MutableMappin return self._to_generated().serialize(keep_readonly=keep_readonly, **kwargs) @classmethod - def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchField": + def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Optional["SearchField"]: """Parse a str using the RestAPI syntax and return a SearchField instance. :param str data: A str using RestAPI structure. JSON by default. @@ -265,7 +267,7 @@ def from_dict( cls, data: Any, content_type: Optional[str] = None, - ) -> "SearchField": + ) -> Optional["SearchField"]: """Parse a dict using given key extractor return a model. :param dict data: A dict using RestAPI structure diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 63f6540d1aed..4cc25ab4b6fd 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -777,7 +777,9 @@ def _to_generated(self): ) @classmethod - def _from_generated(cls, search_resource_encryption_key) -> "SearchResourceEncryptionKey": + def _from_generated(cls, search_resource_encryption_key) -> Optional["SearchResourceEncryptionKey"]: + if not search_resource_encryption_key: + return None if search_resource_encryption_key.access_credentials: application_id = search_resource_encryption_key.access_credentials.application_id application_secret = search_resource_encryption_key.access_credentials.application_secret @@ -801,7 +803,7 @@ def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> MutableMappin return self._to_generated().serialize(keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod - def deserialize(cls, data: Any, content_type: Optional[str] = None) -> "SearchResourceEncryptionKey": + def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Optional["SearchResourceEncryptionKey"]: """Parse a str using the RestAPI syntax and return a SearchResourceEncryptionKey instance. :param str data: A str using RestAPI structure. JSON by default. @@ -827,7 +829,7 @@ def from_dict( cls, data: Any, content_type: Optional[str] = None, - ) -> "SearchResourceEncryptionKey": + ) -> Optional["SearchResourceEncryptionKey"]: """Parse a dict using given key extractor return a model. :param dict data: A dict using RestAPI structure From ef2381f46559178a83e1c6a72af3ed305b0a6d8c Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 28 Feb 2024 14:53:41 -0800 Subject: [PATCH 06/10] update --- sdk/search/azure-search-documents/tests/test_serialization.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/search/azure-search-documents/tests/test_serialization.py b/sdk/search/azure-search-documents/tests/test_serialization.py index 1db085ef3a05..09a5f04caf32 100644 --- a/sdk/search/azure-search-documents/tests/test_serialization.py +++ b/sdk/search/azure-search-documents/tests/test_serialization.py @@ -78,6 +78,7 @@ def test_serialize_search_indexer_skillset(): skillset = SearchIndexerSkillset.deserialize(serialized_skillset) assert skillset + def test_serialize_search_index_dict(): new_index_name = "hotels" fields = [ From bd9516f7d2b7a8153e377bf8206c8258bf726b75 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 14:06:27 -0800 Subject: [PATCH 07/10] updates --- .../search/documents/indexes/models/_index.py | 26 +++++++++++++ .../documents/indexes/models/_models.py | 39 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index 130090714bf9..730a1db11e58 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -278,6 +278,19 @@ def from_dict( """ return cls._from_generated(_SearchField.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + def SimpleField( *, @@ -724,6 +737,19 @@ def from_dict( """ return cls._from_generated(_SearchIndex.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + def pack_search_field(search_field: SearchField) -> _SearchField: if isinstance(search_field, dict): diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 4cc25ab4b6fd..7dcaa1a48e7a 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -840,6 +840,19 @@ def from_dict( """ return cls._from_generated(_SearchResourceEncryptionKey.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + class SynonymMap: """Represents a synonym map definition. @@ -942,6 +955,19 @@ def from_dict( """ return cls._from_generated(_SynonymMap.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + class SearchIndexerDataSourceConnection: """Represents a datasource connection definition, which can be used to configure an indexer. @@ -1072,6 +1098,19 @@ def from_dict( """ return cls._from_generated(_SearchIndexerDataSource.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + def pack_analyzer(analyzer): if not analyzer: From 38f3b35d62e6920a378dc8bdb7713be4f664fe8f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 14:10:40 -0800 Subject: [PATCH 08/10] update --- .../documents/indexes/models/_models.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index 7dcaa1a48e7a..c2810808a203 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -167,6 +167,19 @@ def from_dict( """ return cls._from_generated(_SearchIndexerSkillset.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + class EntityRecognitionSkillVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Specifies the Entity Recognition skill version to use.""" @@ -516,6 +529,19 @@ def from_dict( """ return cls._from_analyze_request(AnalyzeRequest.from_dict(data, content_type=content_type)) + def __eq__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other: Any) -> bool: + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self) -> str: + return str(self.__dict__) + class CustomAnalyzer(LexicalAnalyzer): """Allows you to take control over the process of converting text into indexable/searchable tokens. From 845b9ff4384eb031fbe21c4e169679f02530afc3 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 14:12:57 -0800 Subject: [PATCH 09/10] update --- sdk/search/azure-search-documents/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/CHANGELOG.md b/sdk/search/azure-search-documents/CHANGELOG.md index f4603347136e..c60c85bdbb1b 100644 --- a/sdk/search/azure-search-documents/CHANGELOG.md +++ b/sdk/search/azure-search-documents/CHANGELOG.md @@ -10,7 +10,7 @@ ### Bugs Fixed -- Fixed the issue that `SearchIndexerSkillset`, `SearchField`, `SearchIndex`, `AnalyzeTextOptions`, `SearchResourceEncryptionKey`, `SynonymMap`, `SearchIndexerDataSourceConnection` could not be serialized. +- Fixed the issue that `SearchIndexerSkillset`, `SearchField`, `SearchIndex`, `AnalyzeTextOptions`, `SearchResourceEncryptionKey`, `SynonymMap`, `SearchIndexerDataSourceConnection` could not be serialized and `as_dict` did not work. ### Other Changes From 3da6087533dfc67d968b9d35f7238892369e59da Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Thu, 29 Feb 2024 14:45:08 -0800 Subject: [PATCH 10/10] updates --- .../search/documents/indexes/models/_index.py | 28 ++++++-- .../documents/indexes/models/_models.py | 70 ++++++++++++++++--- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py index 730a1db11e58..9a430dd553c3 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_index.py @@ -279,13 +279,23 @@ def from_dict( return cls._from_generated(_SearchField.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: @@ -738,13 +748,23 @@ def from_dict( return cls._from_generated(_SearchIndex.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py index c2810808a203..37c23e97fa48 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/models/_models.py @@ -168,13 +168,23 @@ def from_dict( return cls._from_generated(_SearchIndexerSkillset.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: @@ -530,13 +540,23 @@ def from_dict( return cls._from_analyze_request(AnalyzeRequest.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: @@ -867,13 +887,23 @@ def from_dict( return cls._from_generated(_SearchResourceEncryptionKey.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: @@ -982,13 +1012,23 @@ def from_dict( return cls._from_generated(_SynonymMap.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: @@ -1125,13 +1165,23 @@ def from_dict( return cls._from_generated(_SearchIndexerDataSource.from_dict(data, content_type=content_type)) def __eq__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: True if all attributes are equal, else False + :rtype: bool + """ if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False def __ne__(self, other: Any) -> bool: - """Compare objects by comparing all attributes.""" + """Compare objects by comparing all attributes. + + :param Any other: the object to compare with + :returns: False if all attributes are equal, else True + :rtype: bool + """ return not self.__eq__(other) def __str__(self) -> str: