Skip to content

Commit a80c84c

Browse files
feat(specs): recursive snippets and highlights result (generated)
algolia/api-clients-automation#3497 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent af90fbd commit a80c84c

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

algoliasearch/src/main/java/com/algolia/model/recommend/HighlightResult.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
/** HighlightResult */
1818
@JsonDeserialize(using = HighlightResult.Deserializer.class)
1919
public interface HighlightResult {
20+
// HighlightResult as Map<String, HighlightResult> wrapper.
21+
static HighlightResult ofMapOfStringHighlightResult(Map<String, HighlightResult> value) {
22+
return new MapOfStringHighlightResultWrapper(value);
23+
}
24+
2025
// HighlightResult as Map<String, HighlightResultOption> wrapper.
21-
static HighlightResult of(Map<String, HighlightResultOption> value) {
26+
static HighlightResult ofMapOfStringHighlightResultOption(Map<String, HighlightResultOption> value) {
2227
return new MapOfStringHighlightResultOptionWrapper(value);
2328
}
2429

@@ -27,6 +32,29 @@ static HighlightResult of(List<HighlightResultOption> value) {
2732
return new ListOfHighlightResultOptionWrapper(value);
2833
}
2934

35+
// HighlightResult as Map<String, HighlightResult> wrapper.
36+
@JsonSerialize(using = MapOfStringHighlightResultWrapper.Serializer.class)
37+
class MapOfStringHighlightResultWrapper implements HighlightResult {
38+
39+
private final Map<String, HighlightResult> value;
40+
41+
MapOfStringHighlightResultWrapper(Map<String, HighlightResult> value) {
42+
this.value = value;
43+
}
44+
45+
public Map<String, HighlightResult> getValue() {
46+
return value;
47+
}
48+
49+
static class Serializer extends JsonSerializer<MapOfStringHighlightResultWrapper> {
50+
51+
@Override
52+
public void serialize(MapOfStringHighlightResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
53+
gen.writeObject(value.getValue());
54+
}
55+
}
56+
}
57+
3058
// HighlightResult as Map<String, HighlightResultOption> wrapper.
3159
@JsonSerialize(using = MapOfStringHighlightResultOptionWrapper.Serializer.class)
3260
class MapOfStringHighlightResultOptionWrapper implements HighlightResult {
@@ -81,6 +109,18 @@ class Deserializer extends JsonDeserializer<HighlightResult> {
81109
@Override
82110
public HighlightResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
83111
JsonNode tree = jp.readValueAsTree();
112+
// deserialize Map<String, HighlightResult>
113+
if (tree.isObject()) {
114+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
115+
Map<String, HighlightResult> value = parser.readValueAs(new TypeReference<Map<String, HighlightResult>>() {});
116+
return new HighlightResult.MapOfStringHighlightResultWrapper(value);
117+
} catch (Exception e) {
118+
// deserialization failed, continue
119+
LOGGER.finest(
120+
"Failed to deserialize oneOf Map<String, HighlightResult> (error: " + e.getMessage() + ") (type: Map<String, HighlightResult>)"
121+
);
122+
}
123+
}
84124
// deserialize HighlightResultOption
85125
if (tree.isObject()) {
86126
try (JsonParser parser = tree.traverse(jp.getCodec())) {

algoliasearch/src/main/java/com/algolia/model/recommend/SnippetResult.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
/** SnippetResult */
1818
@JsonDeserialize(using = SnippetResult.Deserializer.class)
1919
public interface SnippetResult {
20+
// SnippetResult as Map<String, SnippetResult> wrapper.
21+
static SnippetResult ofMapOfStringSnippetResult(Map<String, SnippetResult> value) {
22+
return new MapOfStringSnippetResultWrapper(value);
23+
}
24+
2025
// SnippetResult as Map<String, SnippetResultOption> wrapper.
21-
static SnippetResult of(Map<String, SnippetResultOption> value) {
26+
static SnippetResult ofMapOfStringSnippetResultOption(Map<String, SnippetResultOption> value) {
2227
return new MapOfStringSnippetResultOptionWrapper(value);
2328
}
2429

@@ -27,6 +32,29 @@ static SnippetResult of(List<SnippetResultOption> value) {
2732
return new ListOfSnippetResultOptionWrapper(value);
2833
}
2934

35+
// SnippetResult as Map<String, SnippetResult> wrapper.
36+
@JsonSerialize(using = MapOfStringSnippetResultWrapper.Serializer.class)
37+
class MapOfStringSnippetResultWrapper implements SnippetResult {
38+
39+
private final Map<String, SnippetResult> value;
40+
41+
MapOfStringSnippetResultWrapper(Map<String, SnippetResult> value) {
42+
this.value = value;
43+
}
44+
45+
public Map<String, SnippetResult> getValue() {
46+
return value;
47+
}
48+
49+
static class Serializer extends JsonSerializer<MapOfStringSnippetResultWrapper> {
50+
51+
@Override
52+
public void serialize(MapOfStringSnippetResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
53+
gen.writeObject(value.getValue());
54+
}
55+
}
56+
}
57+
3058
// SnippetResult as Map<String, SnippetResultOption> wrapper.
3159
@JsonSerialize(using = MapOfStringSnippetResultOptionWrapper.Serializer.class)
3260
class MapOfStringSnippetResultOptionWrapper implements SnippetResult {
@@ -81,6 +109,18 @@ class Deserializer extends JsonDeserializer<SnippetResult> {
81109
@Override
82110
public SnippetResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
83111
JsonNode tree = jp.readValueAsTree();
112+
// deserialize Map<String, SnippetResult>
113+
if (tree.isObject()) {
114+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
115+
Map<String, SnippetResult> value = parser.readValueAs(new TypeReference<Map<String, SnippetResult>>() {});
116+
return new SnippetResult.MapOfStringSnippetResultWrapper(value);
117+
} catch (Exception e) {
118+
// deserialization failed, continue
119+
LOGGER.finest(
120+
"Failed to deserialize oneOf Map<String, SnippetResult> (error: " + e.getMessage() + ") (type: Map<String, SnippetResult>)"
121+
);
122+
}
123+
}
84124
// deserialize SnippetResultOption
85125
if (tree.isObject()) {
86126
try (JsonParser parser = tree.traverse(jp.getCodec())) {

algoliasearch/src/main/java/com/algolia/model/search/HighlightResult.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
/** HighlightResult */
1818
@JsonDeserialize(using = HighlightResult.Deserializer.class)
1919
public interface HighlightResult {
20+
// HighlightResult as Map<String, HighlightResult> wrapper.
21+
static HighlightResult ofMapOfStringHighlightResult(Map<String, HighlightResult> value) {
22+
return new MapOfStringHighlightResultWrapper(value);
23+
}
24+
2025
// HighlightResult as Map<String, HighlightResultOption> wrapper.
21-
static HighlightResult of(Map<String, HighlightResultOption> value) {
26+
static HighlightResult ofMapOfStringHighlightResultOption(Map<String, HighlightResultOption> value) {
2227
return new MapOfStringHighlightResultOptionWrapper(value);
2328
}
2429

@@ -27,6 +32,29 @@ static HighlightResult of(List<HighlightResultOption> value) {
2732
return new ListOfHighlightResultOptionWrapper(value);
2833
}
2934

35+
// HighlightResult as Map<String, HighlightResult> wrapper.
36+
@JsonSerialize(using = MapOfStringHighlightResultWrapper.Serializer.class)
37+
class MapOfStringHighlightResultWrapper implements HighlightResult {
38+
39+
private final Map<String, HighlightResult> value;
40+
41+
MapOfStringHighlightResultWrapper(Map<String, HighlightResult> value) {
42+
this.value = value;
43+
}
44+
45+
public Map<String, HighlightResult> getValue() {
46+
return value;
47+
}
48+
49+
static class Serializer extends JsonSerializer<MapOfStringHighlightResultWrapper> {
50+
51+
@Override
52+
public void serialize(MapOfStringHighlightResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
53+
gen.writeObject(value.getValue());
54+
}
55+
}
56+
}
57+
3058
// HighlightResult as Map<String, HighlightResultOption> wrapper.
3159
@JsonSerialize(using = MapOfStringHighlightResultOptionWrapper.Serializer.class)
3260
class MapOfStringHighlightResultOptionWrapper implements HighlightResult {
@@ -81,6 +109,18 @@ class Deserializer extends JsonDeserializer<HighlightResult> {
81109
@Override
82110
public HighlightResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
83111
JsonNode tree = jp.readValueAsTree();
112+
// deserialize Map<String, HighlightResult>
113+
if (tree.isObject()) {
114+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
115+
Map<String, HighlightResult> value = parser.readValueAs(new TypeReference<Map<String, HighlightResult>>() {});
116+
return new HighlightResult.MapOfStringHighlightResultWrapper(value);
117+
} catch (Exception e) {
118+
// deserialization failed, continue
119+
LOGGER.finest(
120+
"Failed to deserialize oneOf Map<String, HighlightResult> (error: " + e.getMessage() + ") (type: Map<String, HighlightResult>)"
121+
);
122+
}
123+
}
84124
// deserialize HighlightResultOption
85125
if (tree.isObject()) {
86126
try (JsonParser parser = tree.traverse(jp.getCodec())) {

algoliasearch/src/main/java/com/algolia/model/search/SnippetResult.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
/** SnippetResult */
1818
@JsonDeserialize(using = SnippetResult.Deserializer.class)
1919
public interface SnippetResult {
20+
// SnippetResult as Map<String, SnippetResult> wrapper.
21+
static SnippetResult ofMapOfStringSnippetResult(Map<String, SnippetResult> value) {
22+
return new MapOfStringSnippetResultWrapper(value);
23+
}
24+
2025
// SnippetResult as Map<String, SnippetResultOption> wrapper.
21-
static SnippetResult of(Map<String, SnippetResultOption> value) {
26+
static SnippetResult ofMapOfStringSnippetResultOption(Map<String, SnippetResultOption> value) {
2227
return new MapOfStringSnippetResultOptionWrapper(value);
2328
}
2429

@@ -27,6 +32,29 @@ static SnippetResult of(List<SnippetResultOption> value) {
2732
return new ListOfSnippetResultOptionWrapper(value);
2833
}
2934

35+
// SnippetResult as Map<String, SnippetResult> wrapper.
36+
@JsonSerialize(using = MapOfStringSnippetResultWrapper.Serializer.class)
37+
class MapOfStringSnippetResultWrapper implements SnippetResult {
38+
39+
private final Map<String, SnippetResult> value;
40+
41+
MapOfStringSnippetResultWrapper(Map<String, SnippetResult> value) {
42+
this.value = value;
43+
}
44+
45+
public Map<String, SnippetResult> getValue() {
46+
return value;
47+
}
48+
49+
static class Serializer extends JsonSerializer<MapOfStringSnippetResultWrapper> {
50+
51+
@Override
52+
public void serialize(MapOfStringSnippetResultWrapper value, JsonGenerator gen, SerializerProvider provider) throws IOException {
53+
gen.writeObject(value.getValue());
54+
}
55+
}
56+
}
57+
3058
// SnippetResult as Map<String, SnippetResultOption> wrapper.
3159
@JsonSerialize(using = MapOfStringSnippetResultOptionWrapper.Serializer.class)
3260
class MapOfStringSnippetResultOptionWrapper implements SnippetResult {
@@ -81,6 +109,18 @@ class Deserializer extends JsonDeserializer<SnippetResult> {
81109
@Override
82110
public SnippetResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
83111
JsonNode tree = jp.readValueAsTree();
112+
// deserialize Map<String, SnippetResult>
113+
if (tree.isObject()) {
114+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
115+
Map<String, SnippetResult> value = parser.readValueAs(new TypeReference<Map<String, SnippetResult>>() {});
116+
return new SnippetResult.MapOfStringSnippetResultWrapper(value);
117+
} catch (Exception e) {
118+
// deserialization failed, continue
119+
LOGGER.finest(
120+
"Failed to deserialize oneOf Map<String, SnippetResult> (error: " + e.getMessage() + ") (type: Map<String, SnippetResult>)"
121+
);
122+
}
123+
}
84124
// deserialize SnippetResultOption
85125
if (tree.isObject()) {
86126
try (JsonParser parser = tree.traverse(jp.getCodec())) {

0 commit comments

Comments
 (0)