Skip to content

Commit dd412c6

Browse files
feat(specs): add fields for metadata in composition injectedItems (generated)
algolia/api-clients-automation#5241 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Gavin Wade <[email protected]>
1 parent 0009c12 commit dd412c6

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

src/main/scala/algoliasearch/composition/Hit.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ case class Hit(
5050
snippetResult /* _snippetResult */: Option[Map[String, SnippetResult]] = scala.None,
5151
rankingInfo /* _rankingInfo */: Option[HitRankingInfo] = scala.None,
5252
distinctSeqID /* _distinctSeqID */: Option[Int] = scala.None,
53+
extra /* _extra */: Option[HitMetadata] = scala.None,
5354
additionalProperties: Option[List[JField]] = None
5455
)
5556

@@ -59,7 +60,8 @@ class HitSerializer extends Serializer[Hit] {
5960
"_highlightResult" -> "highlightResult",
6061
"_snippetResult" -> "snippetResult",
6162
"_rankingInfo" -> "rankingInfo",
62-
"_distinctSeqID" -> "distinctSeqID"
63+
"_distinctSeqID" -> "distinctSeqID",
64+
"_extra" -> "extra"
6365
)
6466
override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), Hit] = {
6567
case (TypeInfo(clazz, _), json) if clazz == classOf[Hit] =>
@@ -75,7 +77,7 @@ class HitSerializer extends Serializer[Hit] {
7577
val mf = manifest[Hit]
7678
val obj = Extraction.extract[Hit](renamedObject)(formats, mf)
7779

78-
val fields = Set("objectID", "_highlightResult", "_snippetResult", "_rankingInfo", "_distinctSeqID")
80+
val fields = Set("objectID", "_highlightResult", "_snippetResult", "_rankingInfo", "_distinctSeqID", "_extra")
7981
val additionalProperties = jobject removeField {
8082
case (name, _) if fields.contains(name) => true
8183
case _ => false
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/** Composition API The Algolia Composition API lets you run composed search requests on your Compositions. ## Client
2+
* libraries Use Algolia's API clients and libraries to reliably integrate Algolia's APIs with your apps. See:
3+
* [Algolia's ecosystem](https://www.algolia.com/doc/guides/getting-started/how-algolia-works/in-depth/ecosystem/) ##
4+
* Base URLs The base URLs for requests to the Composition API are: - `https://{APPLICATION_ID}.algolia.net` -
5+
* `https://{APPLICATION_ID}-dsn.algolia.net`. If your subscription includes a [Distributed Search
6+
* Network](https://dashboard.algolia.com/infra), this ensures that requests are sent to servers closest to users. Both
7+
* URLs provide high availability by distributing requests with load balancing. **All requests must use HTTPS.** ##
8+
* Retry strategy To guarantee high availability, implement a retry strategy for all API requests using the URLs of
9+
* your servers as fallbacks: - `https://{APPLICATION_ID}-1.algolianet.com` -
10+
* `https://{APPLICATION_ID}-2.algolianet.com` - `https://{APPLICATION_ID}-3.algolianet.com` These URLs use a different
11+
* DNS provider than the primary URLs. You should randomize this list to ensure an even load across the three servers.
12+
* All Algolia API clients implement this retry strategy. ## Authentication To authenticate your API requests, add
13+
* these headers: - `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the
14+
* necessary permissions to make the request. The required access control list (ACL) to make a request is listed in
15+
* each endpoint's reference. You can find your application ID and API key in the [Algolia
16+
* dashboard](https://dashboard.algolia.com/account). ## Request format Depending on the endpoint, request bodies are
17+
* either JSON objects or arrays of JSON objects, ## Parameters Parameters are passed as query parameters for GET and
18+
* DELETE requests, and in the request body for POST and PUT requests. Query parameters must be
19+
* [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII characters must be
20+
* UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. Arrays as query parameters must be one of: - A
21+
* comma-separated string: `attributesToRetrieve=title,description` - A URL-encoded JSON array:
22+
* `attributesToRetrieve=%5B%22title%22,%22description%22%D` ## Response status and errors The Composition API returns
23+
* JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order of attributes in the API
24+
* response. Successful responses return a `2xx` status. Client errors return a `4xx` status. Server errors are
25+
* indicated by a `5xx` status. Error responses have a `message` property with more information. ## Version The current
26+
* version of the Composition API is version 1, as indicated by the `/1/` in each endpoint's URL.
27+
*
28+
* The version of the OpenAPI document: 1.0.0
29+
*
30+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
31+
* https://openapi-generator.tech Do not edit the class manually.
32+
*/
33+
package algoliasearch.composition
34+
35+
import org.json4s._
36+
37+
/** An object that contains the extra key-value pairs provided in the injectedItem definition.
38+
*
39+
* @param injectedItemKey
40+
* The key of the injectedItem that inserted this metadata.
41+
*/
42+
case class HitMetadata(
43+
injectedItemKey /* _injectedItemKey */: Option[String] = scala.None,
44+
additionalProperties: Option[List[JField]] = None
45+
)
46+
47+
class HitMetadataSerializer extends Serializer[HitMetadata] {
48+
49+
private val renamedFields = Map[String, String](
50+
"_injectedItemKey" -> "injectedItemKey"
51+
)
52+
override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), HitMetadata] = {
53+
case (TypeInfo(clazz, _), json) if clazz == classOf[HitMetadata] =>
54+
json match {
55+
case jobject: JObject =>
56+
// Rename fields from JSON to Scala
57+
val renamedObject = JObject(
58+
jobject.obj.map { field =>
59+
renamedFields.get(field._1).map(JField(_, field._2)).getOrElse(field)
60+
}
61+
)
62+
val formats = format - this
63+
val mf = manifest[HitMetadata]
64+
val obj = Extraction.extract[HitMetadata](renamedObject)(formats, mf)
65+
66+
val fields = Set("_injectedItemKey")
67+
val additionalProperties = jobject removeField {
68+
case (name, _) if fields.contains(name) => true
69+
case _ => false
70+
}
71+
additionalProperties match {
72+
case JObject(fieldsList) => obj copy (additionalProperties = Some(fieldsList))
73+
case _ => obj
74+
}
75+
case _ => throw new IllegalArgumentException(s"Can't deserialize $json as HitMetadata")
76+
}
77+
}
78+
79+
override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = { case value: HitMetadata =>
80+
val formats = format - this // remove current serializer from formats to avoid stackoverflow
81+
val baseObj = Extraction.decompose(value.copy(additionalProperties = None))(formats)
82+
val renamedObj = baseObj transformField {
83+
case JField(name, value) if renamedFields.exists(_._2 == name) => (renamedFields.find(_._2 == name).get._1, value)
84+
}
85+
value.additionalProperties match {
86+
case Some(fields) => renamedObj merge JObject(fields)
87+
case None => renamedObj
88+
}
89+
}
90+
}

src/main/scala/algoliasearch/composition/JsonSupport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ object JsonSupport {
5858
new CompositionsSearchResponseSerializer() :+
5959
new ErrorBaseSerializer() :+
6060
new HitSerializer() :+
61+
new HitMetadataSerializer() :+
6162
new ResultsCompositionsResponseSerializer() :+
6263
new ResultsInjectedItemInfoResponseSerializer() :+
6364
new SearchHitsSerializer() :+

0 commit comments

Comments
 (0)