1+ { {> licenseInfo} }
2+
3+ package { {modelPackage} };
4+
5+ import java.util.Objects;
6+ import java.util.Map;
7+ import { {javaxPackage} }.ws.rs.core.GenericType;
8+
9+ import com.fasterxml.jackson.annotation.JsonValue;
10+
11+ /**
12+ * Abstract class for oneOf,anyOf schemas defined in OpenAPI spec
13+ */
14+
15+ public abstract class AbstractOpenApiSchema {
16+
17+ // store the actual instance of the schema/object
18+ private Object instance;
19+
20+ // is nullable
21+ private Boolean isNullable;
22+
23+ // schema type (e.g. oneOf, anyOf)
24+ private final String schemaType;
25+
26+ public AbstractOpenApiSchema(String schemaType, Boolean isNullable) {
27+ this.schemaType = schemaType;
28+ this.isNullable = isNullable;
29+ }
30+
31+ /**
32+ * Get the list of oneOf/anyOf composed schemas allowed to be stored in this object
33+ *
34+ * @return an instance of the actual schema/object
35+ */
36+ public abstract Map<String , GenericType <? >> getSchemas();
37+
38+ /**
39+ * Get the actual instance
40+ *
41+ * @return an instance of the actual schema/object
42+ */
43+ @JsonValue
44+ public Object getActualInstance() { return instance;}
45+
46+ /**
47+ * Set the actual instance
48+ *
49+ * @param instance the actual instance of the schema/object
50+ */
51+ public void setActualInstance(Object instance) { this.instance = instance;}
52+
53+ /**
54+ * Get the instant recursively when the schemas defined in oneOf/anyof happen to be oneOf/anyOf schema as well
55+ *
56+ * @return an instance of the actual schema/object
57+ */
58+ public Object getActualInstanceRecursively() {
59+ return getActualInstanceRecursively(this);
60+ }
61+
62+ private Object getActualInstanceRecursively(AbstractOpenApiSchema object) {
63+ if (object.getActualInstance() == null) {
64+ return null;
65+ } else if (object.getActualInstance() instanceof AbstractOpenApiSchema) {
66+ return getActualInstanceRecursively((AbstractOpenApiSchema)object.getActualInstance());
67+ } else {
68+ return object.getActualInstance();
69+ }
70+ }
71+
72+ /**
73+ * Get the schema type (e.g. anyOf, oneOf)
74+ *
75+ * @return the schema type
76+ */
77+ public String getSchemaType() {
78+ return schemaType;
79+ }
80+
81+ @Override
82+ public String toString() {
83+ StringBuilder sb = new StringBuilder();
84+ sb.append(" class " ).append(getClass()).append(" {\n " );
85+ sb.append(" instance: " ).append(toIndentedString(instance)).append(" \n " );
86+ sb.append(" isNullable: " ).append(toIndentedString(isNullable)).append(" \n " );
87+ sb.append(" schemaType: " ).append(toIndentedString(schemaType)).append(" \n " );
88+ sb.append(" }" );
89+ return sb.toString();
90+ }
91+
92+ /**
93+ * Convert the given object to string with each line indented by 4 spaces
94+ * (except the first line).
95+ */
96+ private String toIndentedString(Object o) {
97+ if (o == null) {
98+ return " null" ;
99+ }
100+ return o.toString().replace("\n", "\n ");
101+ }
102+
103+ public boolean equals(Object o) {
104+ if (this == o) {
105+ return true ;
106+ }
107+ if (o == null || getClass() != o.getClass()) {
108+ return false ;
109+ }
110+ AbstractOpenApiSchema a = (AbstractOpenApiSchema) o;
111+ return Objects.equals(this.instance, a.instance) &&
112+ Objects.equals(this.isNullable, a.isNullable) &&
113+ Objects.equals(this.schemaType, a.schemaType);
114+ }
115+
116+ @Override
117+ public int hashCode() {
118+ return Objects.hash(instance, isNullable, schemaType);
119+ }
120+
121+ /**
122+ * Is nullable
123+ *
124+ * @return true if it's nullable
125+ */
126+ public Boolean isNullable() {
127+ if (Boolean.TRUE .equals(isNullable)) {
128+ return Boolean.TRUE ;
129+ } else {
130+ return Boolean.FALSE ;
131+ }
132+ }
133+
134+ { {> libraries/jersey2/additional_properties} }
135+
136+ }
0 commit comments