Skip to content

Commit 8c54c88

Browse files
fix(specs): more accurate composition behavior typing (generated)
algolia/api-clients-automation#5892 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Gavin Wade <[email protected]>
1 parent 9b1635b commit 8c54c88

File tree

3 files changed

+167
-63
lines changed

3 files changed

+167
-63
lines changed

algoliasearch/src/main/java/com/algolia/model/composition/CompositionBehavior.java

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,53 @@
33

44
package com.algolia.model.composition;
55

6+
import com.algolia.exceptions.AlgoliaRuntimeException;
67
import com.fasterxml.jackson.annotation.*;
8+
import com.fasterxml.jackson.core.*;
9+
import com.fasterxml.jackson.databind.*;
710
import com.fasterxml.jackson.databind.annotation.*;
8-
import java.util.Objects;
11+
import java.io.IOException;
12+
import java.util.logging.Logger;
913

1014
/** An object containing either an `injection` or `multifeed` behavior schema, but not both. */
11-
public class CompositionBehavior {
12-
13-
@JsonProperty("injection")
14-
private Injection injection;
15-
16-
@JsonProperty("multifeed")
17-
private Multifeed multifeed;
18-
19-
public CompositionBehavior setInjection(Injection injection) {
20-
this.injection = injection;
21-
return this;
22-
}
23-
24-
/** Get injection */
25-
@javax.annotation.Nullable
26-
public Injection getInjection() {
27-
return injection;
28-
}
29-
30-
public CompositionBehavior setMultifeed(Multifeed multifeed) {
31-
this.multifeed = multifeed;
32-
return this;
33-
}
34-
35-
/** Get multifeed */
36-
@javax.annotation.Nullable
37-
public Multifeed getMultifeed() {
38-
return multifeed;
39-
}
40-
41-
@Override
42-
public boolean equals(Object o) {
43-
if (this == o) {
44-
return true;
15+
@JsonDeserialize(using = CompositionBehavior.Deserializer.class)
16+
public interface CompositionBehavior {
17+
class Deserializer extends JsonDeserializer<CompositionBehavior> {
18+
19+
private static final Logger LOGGER = Logger.getLogger(Deserializer.class.getName());
20+
21+
@Override
22+
public CompositionBehavior deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
23+
JsonNode tree = jp.readValueAsTree();
24+
// deserialize CompositionInjectionBehavior
25+
if (tree.isObject()) {
26+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
27+
return parser.readValueAs(CompositionInjectionBehavior.class);
28+
} catch (Exception e) {
29+
// deserialization failed, continue
30+
LOGGER.finest(
31+
"Failed to deserialize oneOf CompositionInjectionBehavior (error: " + e.getMessage() + ") (type: CompositionInjectionBehavior)"
32+
);
33+
}
34+
}
35+
// deserialize CompositionMultifeedBehavior
36+
if (tree.isObject()) {
37+
try (JsonParser parser = tree.traverse(jp.getCodec())) {
38+
return parser.readValueAs(CompositionMultifeedBehavior.class);
39+
} catch (Exception e) {
40+
// deserialization failed, continue
41+
LOGGER.finest(
42+
"Failed to deserialize oneOf CompositionMultifeedBehavior (error: " + e.getMessage() + ") (type: CompositionMultifeedBehavior)"
43+
);
44+
}
45+
}
46+
throw new AlgoliaRuntimeException(String.format("Failed to deserialize json element: %s", tree));
4547
}
46-
if (o == null || getClass() != o.getClass()) {
47-
return false;
48-
}
49-
CompositionBehavior compositionBehavior = (CompositionBehavior) o;
50-
return Objects.equals(this.injection, compositionBehavior.injection) && Objects.equals(this.multifeed, compositionBehavior.multifeed);
51-
}
52-
53-
@Override
54-
public int hashCode() {
55-
return Objects.hash(injection, multifeed);
56-
}
57-
58-
@Override
59-
public String toString() {
60-
StringBuilder sb = new StringBuilder();
61-
sb.append("class CompositionBehavior {\n");
62-
sb.append(" injection: ").append(toIndentedString(injection)).append("\n");
63-
sb.append(" multifeed: ").append(toIndentedString(multifeed)).append("\n");
64-
sb.append("}");
65-
return sb.toString();
66-
}
6748

68-
/**
69-
* Convert the given object to string with each line indented by 4 spaces (except the first line).
70-
*/
71-
private String toIndentedString(Object o) {
72-
if (o == null) {
73-
return "null";
49+
/** Handle deserialization of the 'null' value. */
50+
@Override
51+
public CompositionBehavior getNullValue(DeserializationContext ctxt) throws JsonMappingException {
52+
throw new JsonMappingException(ctxt.getParser(), "CompositionBehavior cannot be null");
7453
}
75-
return o.toString().replace("\n", "\n ");
7654
}
7755
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost
2+
// - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
package com.algolia.model.composition;
5+
6+
import com.fasterxml.jackson.annotation.*;
7+
import com.fasterxml.jackson.databind.annotation.*;
8+
import java.util.Objects;
9+
10+
/** An object containing an `injection` behavior. */
11+
@JsonDeserialize(as = CompositionInjectionBehavior.class)
12+
public class CompositionInjectionBehavior implements CompositionBehavior {
13+
14+
@JsonProperty("injection")
15+
private Injection injection;
16+
17+
public CompositionInjectionBehavior setInjection(Injection injection) {
18+
this.injection = injection;
19+
return this;
20+
}
21+
22+
/** Get injection */
23+
@javax.annotation.Nonnull
24+
public Injection getInjection() {
25+
return injection;
26+
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
if (this == o) {
31+
return true;
32+
}
33+
if (o == null || getClass() != o.getClass()) {
34+
return false;
35+
}
36+
CompositionInjectionBehavior compositionInjectionBehavior = (CompositionInjectionBehavior) o;
37+
return Objects.equals(this.injection, compositionInjectionBehavior.injection);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(injection);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
StringBuilder sb = new StringBuilder();
48+
sb.append("class CompositionInjectionBehavior {\n");
49+
sb.append(" injection: ").append(toIndentedString(injection)).append("\n");
50+
sb.append("}");
51+
return sb.toString();
52+
}
53+
54+
/**
55+
* Convert the given object to string with each line indented by 4 spaces (except the first line).
56+
*/
57+
private String toIndentedString(Object o) {
58+
if (o == null) {
59+
return "null";
60+
}
61+
return o.toString().replace("\n", "\n ");
62+
}
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost
2+
// - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
package com.algolia.model.composition;
5+
6+
import com.fasterxml.jackson.annotation.*;
7+
import com.fasterxml.jackson.databind.annotation.*;
8+
import java.util.Objects;
9+
10+
/** An object containing a `multifeed` behavior. */
11+
@JsonDeserialize(as = CompositionMultifeedBehavior.class)
12+
public class CompositionMultifeedBehavior implements CompositionBehavior {
13+
14+
@JsonProperty("multifeed")
15+
private Multifeed multifeed;
16+
17+
public CompositionMultifeedBehavior setMultifeed(Multifeed multifeed) {
18+
this.multifeed = multifeed;
19+
return this;
20+
}
21+
22+
/** Get multifeed */
23+
@javax.annotation.Nonnull
24+
public Multifeed getMultifeed() {
25+
return multifeed;
26+
}
27+
28+
@Override
29+
public boolean equals(Object o) {
30+
if (this == o) {
31+
return true;
32+
}
33+
if (o == null || getClass() != o.getClass()) {
34+
return false;
35+
}
36+
CompositionMultifeedBehavior compositionMultifeedBehavior = (CompositionMultifeedBehavior) o;
37+
return Objects.equals(this.multifeed, compositionMultifeedBehavior.multifeed);
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
return Objects.hash(multifeed);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
StringBuilder sb = new StringBuilder();
48+
sb.append("class CompositionMultifeedBehavior {\n");
49+
sb.append(" multifeed: ").append(toIndentedString(multifeed)).append("\n");
50+
sb.append("}");
51+
return sb.toString();
52+
}
53+
54+
/**
55+
* Convert the given object to string with each line indented by 4 spaces (except the first line).
56+
*/
57+
private String toIndentedString(Object o) {
58+
if (o == null) {
59+
return "null";
60+
}
61+
return o.toString().replace("\n", "\n ");
62+
}
63+
}

0 commit comments

Comments
 (0)