19
19
20
20
package co .elastic .clients .elasticsearch .ingest ;
21
21
22
+ import co .elastic .clients .json .JsonEnum ;
22
23
import co .elastic .clients .json .JsonpDeserializable ;
23
24
import co .elastic .clients .json .JsonpDeserializer ;
24
25
import co .elastic .clients .json .JsonpMapper ;
28
29
import co .elastic .clients .json .ObjectDeserializer ;
29
30
import co .elastic .clients .util .ApiTypeHelper ;
30
31
import co .elastic .clients .util .ObjectBuilder ;
32
+ import co .elastic .clients .util .TaggedUnion ;
33
+ import co .elastic .clients .util .TaggedUnionUtils ;
31
34
import co .elastic .clients .util .WithJsonObjectBuilderBase ;
32
35
import jakarta .json .stream .JsonGenerator ;
36
+ import java .lang .Object ;
33
37
import java .lang .String ;
34
38
import java .util .Objects ;
35
39
import java .util .function .Function ;
53
57
// typedef: ingest._types.DatabaseConfiguration
54
58
55
59
/**
56
- *
60
+ * The configuration necessary to identify which IP geolocation provider to use
61
+ * to download a database, as well as any provider-specific configuration
62
+ * necessary for such downloading. At present, the only supported providers are
63
+ * maxmind and ipinfo, and the maxmind provider requires that an account_id
64
+ * (string) is configured. A provider (either maxmind or ipinfo) must be
65
+ * specified. The web and local providers can be returned as read only
66
+ * configurations.
67
+ *
57
68
* @see <a href=
58
69
* "../doc-files/api-spec.html#ingest._types.DatabaseConfiguration">API
59
70
* specification</a>
60
71
*/
61
72
@ JsonpDeserializable
62
- public class DatabaseConfiguration implements JsonpSerializable {
63
- private final String name ;
73
+ public class DatabaseConfiguration implements TaggedUnion <DatabaseConfiguration .Kind , Object >, JsonpSerializable {
74
+
75
+ /**
76
+ * {@link DatabaseConfiguration} variant kinds.
77
+ *
78
+ * @see <a href=
79
+ * "../doc-files/api-spec.html#ingest._types.DatabaseConfiguration">API
80
+ * specification</a>
81
+ */
64
82
65
- private final Maxmind maxmind ;
83
+ public enum Kind implements JsonEnum {
84
+ Maxmind ("maxmind" ),
66
85
67
- // ---------------------------------------------------------------------------------------------
86
+ Ipinfo ("ipinfo" ),
87
+
88
+ ;
89
+
90
+ private final String jsonValue ;
91
+
92
+ Kind (String jsonValue ) {
93
+ this .jsonValue = jsonValue ;
94
+ }
95
+
96
+ public String jsonValue () {
97
+ return this .jsonValue ;
98
+ }
99
+
100
+ }
101
+
102
+ private final Kind _kind ;
103
+ private final Object _value ;
104
+
105
+ @ Override
106
+ public final Kind _kind () {
107
+ return _kind ;
108
+ }
109
+
110
+ @ Override
111
+ public final Object _get () {
112
+ return _value ;
113
+ }
114
+
115
+ private final String name ;
68
116
69
117
private DatabaseConfiguration (Builder builder ) {
70
118
119
+ this ._kind = ApiTypeHelper .requireNonNull (builder ._kind , builder , "<variant kind>" );
120
+ this ._value = ApiTypeHelper .requireNonNull (builder ._value , builder , "<variant value>" );
121
+
71
122
this .name = ApiTypeHelper .requireNonNull (builder .name , this , "name" );
72
- this .maxmind = ApiTypeHelper .requireNonNull (builder .maxmind , this , "maxmind" );
73
123
74
124
}
75
125
@@ -88,34 +138,54 @@ public final String name() {
88
138
}
89
139
90
140
/**
91
- * Required - The configuration necessary to identify which IP geolocation
92
- * provider to use to download the database, as well as any provider-specific
93
- * configuration necessary for such downloading. At present, the only supported
94
- * provider is maxmind, and the maxmind provider requires that an account_id
95
- * (string) is configured.
96
- * <p>
97
- * API name: {@code maxmind}
141
+ * Is this variant instance of kind {@code maxmind}?
98
142
*/
99
- public final Maxmind maxmind () {
100
- return this . maxmind ;
143
+ public boolean isMaxmind () {
144
+ return _kind == Kind . Maxmind ;
101
145
}
102
146
103
147
/**
104
- * Serialize this object to JSON.
148
+ * Get the {@code maxmind} variant value.
149
+ *
150
+ * @throws IllegalStateException
151
+ * if the current variant is not of the {@code maxmind} kind.
105
152
*/
106
- public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
107
- generator .writeStartObject ();
108
- serializeInternal (generator , mapper );
109
- generator .writeEnd ();
153
+ public Maxmind maxmind () {
154
+ return TaggedUnionUtils .get (this , Kind .Maxmind );
155
+ }
156
+
157
+ /**
158
+ * Is this variant instance of kind {@code ipinfo}?
159
+ */
160
+ public boolean isIpinfo () {
161
+ return _kind == Kind .Ipinfo ;
110
162
}
111
163
112
- protected void serializeInternal (JsonGenerator generator , JsonpMapper mapper ) {
164
+ /**
165
+ * Get the {@code ipinfo} variant value.
166
+ *
167
+ * @throws IllegalStateException
168
+ * if the current variant is not of the {@code ipinfo} kind.
169
+ */
170
+ public Ipinfo ipinfo () {
171
+ return TaggedUnionUtils .get (this , Kind .Ipinfo );
172
+ }
173
+
174
+ @ Override
175
+ @ SuppressWarnings ("unchecked" )
176
+ public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
177
+
178
+ generator .writeStartObject ();
113
179
114
180
generator .writeKey ("name" );
115
181
generator .write (this .name );
116
182
117
- generator .writeKey ("maxmind" );
118
- this .maxmind .serialize (generator , mapper );
183
+ generator .writeKey (_kind .jsonValue ());
184
+ if (_value instanceof JsonpSerializable ) {
185
+ ((JsonpSerializable ) _value ).serialize (generator , mapper );
186
+ }
187
+
188
+ generator .writeEnd ();
119
189
120
190
}
121
191
@@ -124,18 +194,13 @@ public String toString() {
124
194
return JsonpUtils .toString (this );
125
195
}
126
196
127
- // ---------------------------------------------------------------------------------------------
128
-
129
- /**
130
- * Builder for {@link DatabaseConfiguration}.
131
- */
132
-
133
197
public static class Builder extends WithJsonObjectBuilderBase <Builder >
134
198
implements
135
199
ObjectBuilder <DatabaseConfiguration > {
136
- private String name ;
200
+ private Kind _kind ;
201
+ private Object _value ;
137
202
138
- private Maxmind maxmind ;
203
+ private String name ;
139
204
140
205
/**
141
206
* Required - The provider-assigned name of the IP geolocation database to
@@ -148,64 +213,62 @@ public final Builder name(String value) {
148
213
return this ;
149
214
}
150
215
151
- /**
152
- * Required - The configuration necessary to identify which IP geolocation
153
- * provider to use to download the database, as well as any provider-specific
154
- * configuration necessary for such downloading. At present, the only supported
155
- * provider is maxmind, and the maxmind provider requires that an account_id
156
- * (string) is configured.
157
- * <p>
158
- * API name: {@code maxmind}
159
- */
160
- public final Builder maxmind (Maxmind value ) {
161
- this .maxmind = value ;
216
+ @ Override
217
+ protected Builder self () {
162
218
return this ;
163
219
}
220
+ public ContainerBuilder maxmind (Maxmind v ) {
221
+ this ._kind = Kind .Maxmind ;
222
+ this ._value = v ;
223
+ return new ContainerBuilder ();
224
+ }
164
225
165
- /**
166
- * Required - The configuration necessary to identify which IP geolocation
167
- * provider to use to download the database, as well as any provider-specific
168
- * configuration necessary for such downloading. At present, the only supported
169
- * provider is maxmind, and the maxmind provider requires that an account_id
170
- * (string) is configured.
171
- * <p>
172
- * API name: {@code maxmind}
173
- */
174
- public final Builder maxmind (Function <Maxmind .Builder , ObjectBuilder <Maxmind >> fn ) {
226
+ public ContainerBuilder maxmind (Function <Maxmind .Builder , ObjectBuilder <Maxmind >> fn ) {
175
227
return this .maxmind (fn .apply (new Maxmind .Builder ()).build ());
176
228
}
177
229
178
- @ Override
179
- protected Builder self () {
180
- return this ;
230
+ public ContainerBuilder ipinfo (Ipinfo v ) {
231
+ this ._kind = Kind .Ipinfo ;
232
+ this ._value = v ;
233
+ return new ContainerBuilder ();
234
+ }
235
+
236
+ public ContainerBuilder ipinfo (Function <Ipinfo .Builder , ObjectBuilder <Ipinfo >> fn ) {
237
+ return this .ipinfo (fn .apply (new Ipinfo .Builder ()).build ());
181
238
}
182
239
183
- /**
184
- * Builds a {@link DatabaseConfiguration}.
185
- *
186
- * @throws NullPointerException
187
- * if some of the required fields are null.
188
- */
189
240
public DatabaseConfiguration build () {
190
241
_checkSingleUse ();
191
-
192
242
return new DatabaseConfiguration (this );
193
243
}
194
- }
195
-
196
- // ---------------------------------------------------------------------------------------------
197
244
198
- /**
199
- * Json deserializer for {@link DatabaseConfiguration}
200
- */
201
- public static final JsonpDeserializer <DatabaseConfiguration > _DESERIALIZER = ObjectBuilderDeserializer
202
- .lazy (Builder ::new , DatabaseConfiguration ::setupDatabaseConfigurationDeserializer );
245
+ public class ContainerBuilder implements ObjectBuilder <DatabaseConfiguration > {
246
+
247
+ /**
248
+ * Required - The provider-assigned name of the IP geolocation database to
249
+ * download.
250
+ * <p>
251
+ * API name: {@code name}
252
+ */
253
+ public final ContainerBuilder name (String value ) {
254
+ Builder .this .name = value ;
255
+ return this ;
256
+ }
257
+
258
+ public DatabaseConfiguration build () {
259
+ return Builder .this .build ();
260
+ }
261
+ }
262
+ }
203
263
204
- protected static void setupDatabaseConfigurationDeserializer (ObjectDeserializer <DatabaseConfiguration . Builder > op ) {
264
+ protected static void setupDatabaseConfigurationDeserializer (ObjectDeserializer <Builder > op ) {
205
265
206
266
op .add (Builder ::name , JsonpDeserializer .stringDeserializer (), "name" );
207
267
op .add (Builder ::maxmind , Maxmind ._DESERIALIZER , "maxmind" );
268
+ op .add (Builder ::ipinfo , Ipinfo ._DESERIALIZER , "ipinfo" );
208
269
209
270
}
210
271
272
+ public static final JsonpDeserializer <DatabaseConfiguration > _DESERIALIZER = ObjectBuilderDeserializer
273
+ .lazy (Builder ::new , DatabaseConfiguration ::setupDatabaseConfigurationDeserializer , Builder ::build );
211
274
}
0 commit comments