|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package co.elastic.clients.elasticsearch._types; |
| 21 | + |
| 22 | +import co.elastic.clients.elasticsearch.core.search.SearchRequestBody; |
| 23 | +import co.elastic.clients.json.JsonpDeserializable; |
| 24 | +import co.elastic.clients.json.JsonpDeserializer; |
| 25 | +import co.elastic.clients.json.JsonpMapper; |
| 26 | +import co.elastic.clients.json.JsonpSerializable; |
| 27 | +import co.elastic.clients.json.JsonpUtils; |
| 28 | +import co.elastic.clients.json.ObjectDeserializer; |
| 29 | +import co.elastic.clients.json.UnionDeserializer; |
| 30 | +import co.elastic.clients.util.ApiTypeHelper; |
| 31 | +import co.elastic.clients.util.ObjectBuilder; |
| 32 | +import co.elastic.clients.util.ObjectBuilderBase; |
| 33 | +import co.elastic.clients.util.TaggedUnion; |
| 34 | +import co.elastic.clients.util.TaggedUnionUtils; |
| 35 | +import jakarta.json.stream.JsonGenerator; |
| 36 | +import java.lang.Object; |
| 37 | +import java.lang.String; |
| 38 | +import java.util.Objects; |
| 39 | +import java.util.function.Function; |
| 40 | +import javax.annotation.Nullable; |
| 41 | + |
| 42 | +//---------------------------------------------------------------- |
| 43 | +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. |
| 44 | +//---------------------------------------------------------------- |
| 45 | +// |
| 46 | +// This code is generated from the Elasticsearch API specification |
| 47 | +// at https://github.com/elastic/elasticsearch-specification |
| 48 | +// |
| 49 | +// Manual updates to this file will be lost when the code is |
| 50 | +// re-generated. |
| 51 | +// |
| 52 | +// If you find a property that is missing or wrongly typed, please |
| 53 | +// open an issue or a PR on the API specification repository. |
| 54 | +// |
| 55 | +//---------------------------------------------------------------- |
| 56 | + |
| 57 | +// typedef: _types.ScriptSource |
| 58 | + |
| 59 | +/** |
| 60 | + * |
| 61 | + * @see <a href="../doc-files/api-spec.html#_types.ScriptSource">API |
| 62 | + * specification</a> |
| 63 | + */ |
| 64 | +@JsonpDeserializable |
| 65 | +public class ScriptSource implements TaggedUnion<ScriptSource.Kind, Object>, JsonpSerializable { |
| 66 | + |
| 67 | + public enum Kind { |
| 68 | + ScriptTemplate, ScriptString |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | + private final Kind _kind; |
| 73 | + private final Object _value; |
| 74 | + |
| 75 | + @Override |
| 76 | + public final Kind _kind() { |
| 77 | + return _kind; |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public final Object _get() { |
| 82 | + return _value; |
| 83 | + } |
| 84 | + |
| 85 | + private ScriptSource(Kind kind, Object value) { |
| 86 | + this._kind = kind; |
| 87 | + this._value = value; |
| 88 | + } |
| 89 | + |
| 90 | + private ScriptSource(Builder builder) { |
| 91 | + |
| 92 | + this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>"); |
| 93 | + this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>"); |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + public static ScriptSource of(Function<Builder, ObjectBuilder<ScriptSource>> fn) { |
| 98 | + return fn.apply(new Builder()).build(); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Is this variant instance of kind {@code script_template}? |
| 103 | + */ |
| 104 | + public boolean isScriptTemplate() { |
| 105 | + return _kind == Kind.ScriptTemplate; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Get the {@code script_template} variant value. |
| 110 | + * |
| 111 | + * @throws IllegalStateException |
| 112 | + * if the current variant is not of the {@code script_template} |
| 113 | + * kind. |
| 114 | + */ |
| 115 | + public SearchRequestBody scriptTemplate() { |
| 116 | + return TaggedUnionUtils.get(this, Kind.ScriptTemplate); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Is this variant instance of kind {@code script_string}? |
| 121 | + */ |
| 122 | + public boolean isScriptString() { |
| 123 | + return _kind == Kind.ScriptString; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Get the {@code script_string} variant value. |
| 128 | + * |
| 129 | + * @throws IllegalStateException |
| 130 | + * if the current variant is not of the {@code script_string} kind. |
| 131 | + */ |
| 132 | + public String scriptString() { |
| 133 | + return TaggedUnionUtils.get(this, Kind.ScriptString); |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 138 | + if (_value instanceof JsonpSerializable) { |
| 139 | + ((JsonpSerializable) _value).serialize(generator, mapper); |
| 140 | + } else { |
| 141 | + switch (_kind) { |
| 142 | + case ScriptString : |
| 143 | + generator.write(((String) this._value)); |
| 144 | + |
| 145 | + break; |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public String toString() { |
| 153 | + return JsonpUtils.toString(this); |
| 154 | + } |
| 155 | + |
| 156 | + public static class Builder extends ObjectBuilderBase implements ObjectBuilder<ScriptSource> { |
| 157 | + private Kind _kind; |
| 158 | + private Object _value; |
| 159 | + |
| 160 | + public ObjectBuilder<ScriptSource> scriptTemplate(SearchRequestBody v) { |
| 161 | + this._kind = Kind.ScriptTemplate; |
| 162 | + this._value = v; |
| 163 | + return this; |
| 164 | + } |
| 165 | + |
| 166 | + public ObjectBuilder<ScriptSource> scriptTemplate( |
| 167 | + Function<SearchRequestBody.Builder, ObjectBuilder<SearchRequestBody>> fn) { |
| 168 | + return this.scriptTemplate(fn.apply(new SearchRequestBody.Builder()).build()); |
| 169 | + } |
| 170 | + |
| 171 | + public ObjectBuilder<ScriptSource> scriptString(String v) { |
| 172 | + this._kind = Kind.ScriptString; |
| 173 | + this._value = v; |
| 174 | + return this; |
| 175 | + } |
| 176 | + |
| 177 | + public ScriptSource build() { |
| 178 | + _checkSingleUse(); |
| 179 | + return new ScriptSource(this); |
| 180 | + } |
| 181 | + |
| 182 | + } |
| 183 | + |
| 184 | + private static JsonpDeserializer<ScriptSource> buildScriptSourceDeserializer() { |
| 185 | + return new UnionDeserializer.Builder<ScriptSource, Kind, Object>(ScriptSource::new, false) |
| 186 | + .addMember(Kind.ScriptTemplate, SearchRequestBody._DESERIALIZER) |
| 187 | + .addMember(Kind.ScriptString, JsonpDeserializer.stringDeserializer()).build(); |
| 188 | + } |
| 189 | + |
| 190 | + public static final JsonpDeserializer<ScriptSource> _DESERIALIZER = JsonpDeserializer |
| 191 | + .lazy(ScriptSource::buildScriptSourceDeserializer); |
| 192 | +} |
0 commit comments