Skip to content

Commit

Permalink
fix(specs): ignorePlurals can be a boolean string (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3620

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
algolia-bot and millotp committed Aug 30, 2024
1 parent 7e7764e commit df6c63b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 12 deletions.
33 changes: 33 additions & 0 deletions algoliasearch/recommend/models/boolean_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# coding: utf-8

"""
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
"""

from __future__ import annotations

from enum import Enum
from json import loads
from sys import version_info

if version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


class BooleanString(str, Enum):
"""
BooleanString
"""

"""
allowed enum values
"""
TRUE = "true"
FALSE = "false"

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BooleanString from a JSON string"""
return cls(loads(json_str))
24 changes: 18 additions & 6 deletions algoliasearch/recommend/models/ignore_plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing_extensions import Self


from algoliasearch.recommend.models.boolean_string import BooleanString
from algoliasearch.recommend.models.supported_language import SupportedLanguage


Expand All @@ -30,11 +31,14 @@ class IgnorePlurals(BaseModel):
default=None,
description="ISO code for languages for which this feature should be active. This overrides languages you set with `queryLanguages`. ",
)
oneof_schema_2_validator: Optional[StrictBool] = Field(
oneof_schema_2_validator: Optional[BooleanString] = None
oneof_schema_3_validator: Optional[StrictBool] = Field(
default=False,
description="If true, `ignorePlurals` is active for all languages included in `queryLanguages`, or for all supported languages, if `queryLanguges` is empty. If false, singulars, plurals, and other declensions won't be considered equivalent. ",
)
actual_instance: Optional[Union[List[SupportedLanguage], bool]] = None
actual_instance: Optional[Union[BooleanString, List[SupportedLanguage], bool]] = (
None
)

def __init__(self, *args, **kwargs) -> None:
if args:
Expand All @@ -51,7 +55,9 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(**kwargs)

@model_serializer
def unwrap_actual_instance(self) -> Optional[Union[List[SupportedLanguage], bool]]:
def unwrap_actual_instance(
self,
) -> Optional[Union[BooleanString, List[SupportedLanguage], bool]]:
"""
Unwraps the `actual_instance` when calling the `to_json` method.
"""
Expand All @@ -75,15 +81,21 @@ def from_json(cls, json_str: str) -> Self:
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
try:
instance.oneof_schema_2_validator = loads(json_str)
instance.actual_instance = instance.oneof_schema_2_validator
instance.actual_instance = BooleanString.from_json(json_str)

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
try:
instance.oneof_schema_3_validator = loads(json_str)
instance.actual_instance = instance.oneof_schema_3_validator

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

raise ValueError(
"No match found when deserializing the JSON string into IgnorePlurals with oneOf schemas: List[SupportedLanguage], bool. Details: "
"No match found when deserializing the JSON string into IgnorePlurals with oneOf schemas: BooleanString, List[SupportedLanguage], bool. Details: "
+ ", ".join(error_messages)
)

Expand Down
33 changes: 33 additions & 0 deletions algoliasearch/search/models/boolean_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# coding: utf-8

"""
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
"""

from __future__ import annotations

from enum import Enum
from json import loads
from sys import version_info

if version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


class BooleanString(str, Enum):
"""
BooleanString
"""

"""
allowed enum values
"""
TRUE = "true"
FALSE = "false"

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of BooleanString from a JSON string"""
return cls(loads(json_str))
24 changes: 18 additions & 6 deletions algoliasearch/search/models/ignore_plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing_extensions import Self


from algoliasearch.search.models.boolean_string import BooleanString
from algoliasearch.search.models.supported_language import SupportedLanguage


Expand All @@ -30,11 +31,14 @@ class IgnorePlurals(BaseModel):
default=None,
description="ISO code for languages for which this feature should be active. This overrides languages you set with `queryLanguages`. ",
)
oneof_schema_2_validator: Optional[StrictBool] = Field(
oneof_schema_2_validator: Optional[BooleanString] = None
oneof_schema_3_validator: Optional[StrictBool] = Field(
default=False,
description="If true, `ignorePlurals` is active for all languages included in `queryLanguages`, or for all supported languages, if `queryLanguges` is empty. If false, singulars, plurals, and other declensions won't be considered equivalent. ",
)
actual_instance: Optional[Union[List[SupportedLanguage], bool]] = None
actual_instance: Optional[Union[BooleanString, List[SupportedLanguage], bool]] = (
None
)

def __init__(self, *args, **kwargs) -> None:
if args:
Expand All @@ -51,7 +55,9 @@ def __init__(self, *args, **kwargs) -> None:
super().__init__(**kwargs)

@model_serializer
def unwrap_actual_instance(self) -> Optional[Union[List[SupportedLanguage], bool]]:
def unwrap_actual_instance(
self,
) -> Optional[Union[BooleanString, List[SupportedLanguage], bool]]:
"""
Unwraps the `actual_instance` when calling the `to_json` method.
"""
Expand All @@ -75,15 +81,21 @@ def from_json(cls, json_str: str) -> Self:
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
try:
instance.oneof_schema_2_validator = loads(json_str)
instance.actual_instance = instance.oneof_schema_2_validator
instance.actual_instance = BooleanString.from_json(json_str)

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))
try:
instance.oneof_schema_3_validator = loads(json_str)
instance.actual_instance = instance.oneof_schema_3_validator

return instance
except (ValidationError, ValueError) as e:
error_messages.append(str(e))

raise ValueError(
"No match found when deserializing the JSON string into IgnorePlurals with oneOf schemas: List[SupportedLanguage], bool. Details: "
"No match found when deserializing the JSON string into IgnorePlurals with oneOf schemas: BooleanString, List[SupportedLanguage], bool. Details: "
+ ", ".join(error_messages)
)

Expand Down

0 comments on commit df6c63b

Please sign in to comment.