Skip to content

Commit 96a87f1

Browse files
algolia-botmillotp
andcommitted
fix(specs): ignorePlurals can be a boolean string (generated)
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>
1 parent c985710 commit 96a87f1

File tree

6 files changed

+146
-4
lines changed

6 files changed

+146
-4
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/** Recommend API The Recommend API lets you retrieve recommendations from one of Algolia's AI recommendation models
2+
* that you previously trained on your data. ## Client libraries Use Algolia's API clients and libraries to reliably
3+
* integrate Algolia's APIs with your apps. The official API clients are covered by Algolia's [Service Level
4+
* Agreement](https://www.algolia.com/policies/sla/). See: [Algolia's
5+
* ecosystem](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) ## Base URLs
6+
* The base URLs for requests to the Recommend API are: - `https://{APPLICATION_ID}.algolia.net` -
7+
* `https://{APPLICATION_ID}-dsn.algolia.net`. If your subscription includes a [Distributed Search
8+
* Network](https://dashboard.algolia.com/infra), this ensures that requests are sent to servers closest to users. Both
9+
* URLs provide high availability by distributing requests with load balancing. **All requests must use HTTPS.** ##
10+
* Retry strategy To guarantee a high availability, implement a retry strategy for all API requests using the URLs of
11+
* your servers as fallbacks: - `https://{APPLICATION_ID}-1.algolianet.com` -
12+
* `https://{APPLICATION_ID}-2.algolianet.com` - `https://{APPLICATION_ID}-3.algolianet.com` These URLs use a different
13+
* DNS provider than the primary URLs. You should randomize this list to ensure an even load across the three servers.
14+
* All Algolia API clients implement this retry strategy. ## Authentication To authenticate your API requests, add
15+
* these headers: - `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the
16+
* necessary permissions to make the request. The required access control list (ACL) to make a request is listed in
17+
* each endpoint's reference. You can find your application ID and API key in the [Algolia
18+
* dashboard](https://dashboard.algolia.com/account). ## Request format Request bodies must be JSON objects. ##
19+
* Response status and errors The Recommend API returns JSON responses. Since JSON doesn't guarantee any specific
20+
* ordering, don't rely on the order of attributes in the API response. Successful responses return a `2xx` status.
21+
* Client errors return a `4xx` status. Server errors are indicated by a `5xx` status. Error responses have a `message`
22+
* property with more information. ## Version The current version of the Recommend API is version 1, as indicated by
23+
* the `/1/` in each endpoint's URL.
24+
*
25+
* The version of the OpenAPI document: 1.0.0
26+
*
27+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
28+
* https://openapi-generator.tech Do not edit the class manually.
29+
*/
30+
package algoliasearch.recommend
31+
32+
import org.json4s._
33+
34+
sealed trait BooleanString extends IgnorePluralsTrait
35+
36+
/** BooleanString enumeration
37+
*/
38+
object BooleanString {
39+
case object `True` extends BooleanString {
40+
override def toString = "true"
41+
}
42+
case object `False` extends BooleanString {
43+
override def toString = "false"
44+
}
45+
val values: Seq[BooleanString] = Seq(`True`, `False`)
46+
47+
def withName(name: String): BooleanString = BooleanString.values
48+
.find(_.toString == name)
49+
.getOrElse(throw new MappingException(s"Unknown BooleanString value: $name"))
50+
}
51+
52+
class BooleanStringSerializer
53+
extends CustomSerializer[BooleanString](_ =>
54+
(
55+
{
56+
case JString(value) => BooleanString.withName(value)
57+
case JNull => null
58+
},
59+
{ case value: BooleanString =>
60+
JString(value.toString)
61+
}
62+
)
63+
)

src/main/scala/algoliasearch/recommend/IgnorePlurals.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
package algoliasearch.recommend
3131

32+
import algoliasearch.recommend.BooleanString._
3233
import algoliasearch.recommend.SupportedLanguage._
3334

3435
import org.json4s._
@@ -38,6 +39,8 @@ import org.json4s._
3839
*/
3940
sealed trait IgnorePlurals
4041

42+
trait IgnorePluralsTrait extends IgnorePlurals
43+
4144
object IgnorePlurals {
4245

4346
case class SeqOfSupportedLanguage(value: Seq[SupportedLanguage]) extends IgnorePlurals
@@ -59,14 +62,16 @@ object IgnorePluralsSerializer extends Serializer[IgnorePlurals] {
5962
json match {
6063
case JArray(value) if value.forall(_.isInstanceOf[JArray]) =>
6164
IgnorePlurals.SeqOfSupportedLanguage(value.map(_.extract))
62-
case JBool(value) => IgnorePlurals.BooleanValue(value)
63-
case _ => throw new MappingException("Can't convert " + json + " to IgnorePlurals")
65+
case value: JString => Extraction.extract[BooleanString](value)
66+
case JBool(value) => IgnorePlurals.BooleanValue(value)
67+
case _ => throw new MappingException("Can't convert " + json + " to IgnorePlurals")
6468
}
6569
}
6670

6771
override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case value: IgnorePlurals =>
6872
value match {
6973
case IgnorePlurals.SeqOfSupportedLanguage(value) => JArray(value.map(Extraction.decompose).toList)
74+
case value: BooleanString => JString(value.toString)
7075
case IgnorePlurals.BooleanValue(value) => JBool(value)
7176
}
7277
}

src/main/scala/algoliasearch/recommend/JsonSupport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object JsonSupport {
3636
new AdvancedSyntaxFeaturesSerializer() :+
3737
new AlternativesAsExactSerializer() :+
3838
new AroundRadiusAllSerializer() :+
39+
new BooleanStringSerializer() :+
3940
new ExactOnSingleWordQuerySerializer() :+
4041
new FbtModelSerializer() :+
4142
new LookingSimilarModelSerializer() :+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/** Search API The Algolia Search API lets you search, configure, and mange your indices and records. ## Client
2+
* libraries Use Algolia's API clients and libraries to reliably integrate Algolia's APIs with your apps. The official
3+
* API clients are covered by Algolia's [Service Level Agreement](https://www.algolia.com/policies/sla/). See:
4+
* [Algolia's ecosystem](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) ##
5+
* Base URLs The base URLs for requests to the Search API are: - `https://{APPLICATION_ID}.algolia.net` -
6+
* `https://{APPLICATION_ID}-dsn.algolia.net`. If your subscription includes a [Distributed Search
7+
* Network](https://dashboard.algolia.com/infra), this ensures that requests are sent to servers closest to users. Both
8+
* URLs provide high availability by distributing requests with load balancing. **All requests must use HTTPS.** ##
9+
* Retry strategy To guarantee a high availability, implement a retry strategy for all API requests using the URLs of
10+
* your servers as fallbacks: - `https://{APPLICATION_ID}-1.algolianet.com` -
11+
* `https://{APPLICATION_ID}-2.algolianet.com` - `https://{APPLICATION_ID}-3.algolianet.com` These URLs use a different
12+
* DNS provider than the primary URLs. You should randomize this list to ensure an even load across the three servers.
13+
* All Algolia API clients implement this retry strategy. ## Authentication To authenticate your API requests, add
14+
* these headers: - `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the
15+
* necessary permissions to make the request. The required access control list (ACL) to make a request is listed in
16+
* each endpoint's reference. You can find your application ID and API key in the [Algolia
17+
* dashboard](https://dashboard.algolia.com/account). ## Request format Depending on the endpoint, request bodies are
18+
* either JSON objects or arrays of JSON objects, ## Parameters Parameters are passed as query parameters for GET and
19+
* DELETE requests, and in the request body for POST and PUT requests. Query parameters must be
20+
* [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII characters must be
21+
* UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. Arrays as query parameters must be one of: - A
22+
* comma-separated string: `attributesToRetrieve=title,description` - A URL-encoded JSON array:
23+
* `attributesToRetrieve=%5B%22title%22,%22description%22%D` ## Response status and errors The Search API returns JSON
24+
* responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order of attributes in the API
25+
* response. Successful responses return a `2xx` status. Client errors return a `4xx` status. Server errors are
26+
* indicated by a `5xx` status. Error responses have a `message` property with more information. ## Version The current
27+
* version of the Search API is version 1, as indicated by the `/1/` in each endpoint's URL.
28+
*
29+
* The version of the OpenAPI document: 1.0.0
30+
*
31+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
32+
* https://openapi-generator.tech Do not edit the class manually.
33+
*/
34+
package algoliasearch.search
35+
36+
import org.json4s._
37+
38+
sealed trait BooleanString extends IgnorePluralsTrait
39+
40+
/** BooleanString enumeration
41+
*/
42+
object BooleanString {
43+
case object `True` extends BooleanString {
44+
override def toString = "true"
45+
}
46+
case object `False` extends BooleanString {
47+
override def toString = "false"
48+
}
49+
val values: Seq[BooleanString] = Seq(`True`, `False`)
50+
51+
def withName(name: String): BooleanString = BooleanString.values
52+
.find(_.toString == name)
53+
.getOrElse(throw new MappingException(s"Unknown BooleanString value: $name"))
54+
}
55+
56+
class BooleanStringSerializer
57+
extends CustomSerializer[BooleanString](_ =>
58+
(
59+
{
60+
case JString(value) => BooleanString.withName(value)
61+
case JNull => null
62+
},
63+
{ case value: BooleanString =>
64+
JString(value.toString)
65+
}
66+
)
67+
)

src/main/scala/algoliasearch/search/IgnorePlurals.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434
package algoliasearch.search
3535

36+
import algoliasearch.search.BooleanString._
3637
import algoliasearch.search.SupportedLanguage._
3738

3839
import org.json4s._
@@ -42,6 +43,8 @@ import org.json4s._
4243
*/
4344
sealed trait IgnorePlurals
4445

46+
trait IgnorePluralsTrait extends IgnorePlurals
47+
4548
object IgnorePlurals {
4649

4750
case class SeqOfSupportedLanguage(value: Seq[SupportedLanguage]) extends IgnorePlurals
@@ -63,14 +66,16 @@ object IgnorePluralsSerializer extends Serializer[IgnorePlurals] {
6366
json match {
6467
case JArray(value) if value.forall(_.isInstanceOf[JArray]) =>
6568
IgnorePlurals.SeqOfSupportedLanguage(value.map(_.extract))
66-
case JBool(value) => IgnorePlurals.BooleanValue(value)
67-
case _ => throw new MappingException("Can't convert " + json + " to IgnorePlurals")
69+
case value: JString => Extraction.extract[BooleanString](value)
70+
case JBool(value) => IgnorePlurals.BooleanValue(value)
71+
case _ => throw new MappingException("Can't convert " + json + " to IgnorePlurals")
6872
}
6973
}
7074

7175
override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case value: IgnorePlurals =>
7276
value match {
7377
case IgnorePlurals.SeqOfSupportedLanguage(value) => JArray(value.map(Extraction.decompose).toList)
78+
case value: BooleanString => JString(value.toString)
7479
case IgnorePlurals.BooleanValue(value) => JBool(value)
7580
}
7681
}

src/main/scala/algoliasearch/search/JsonSupport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ object JsonSupport {
4444
new AnchoringSerializer() :+
4545
new ApiKeyOperationSerializer() :+
4646
new AroundRadiusAllSerializer() :+
47+
new BooleanStringSerializer() :+
4748
new BuiltInOperationTypeSerializer() :+
4849
new DictionaryActionSerializer() :+
4950
new DictionaryEntryStateSerializer() :+

0 commit comments

Comments
 (0)