2424import com .google .gson .stream .JsonWriter ;
2525import java .io .IOException ;
2626import java .util .Arrays ;
27+ import java .util .HashMap ;
2728import java .util .HashSet ;
29+ import java .util .List ;
2830import java .util .Map ;
2931import java .util .Objects ;
30- import java .util .Set ;
3132
3233/** Set this to customize active health checks for targets in this pool. */
3334@ javax .annotation .Generated (
@@ -176,6 +177,50 @@ public void setUnhealthyThreshold(@javax.annotation.Nullable Integer unhealthyTh
176177 this .unhealthyThreshold = unhealthyThreshold ;
177178 }
178179
180+ /**
181+ * A container for additional, undeclared properties. This is a holder for any undeclared
182+ * properties as specified with the 'additionalProperties' keyword in the OAS document.
183+ */
184+ private Map <String , Object > additionalProperties ;
185+
186+ /**
187+ * Set the additional (undeclared) property with the specified name and value. If the property
188+ * does not already exist, create it otherwise replace it.
189+ *
190+ * @param key name of the property
191+ * @param value value of the property
192+ * @return the ActiveHealthCheck instance itself
193+ */
194+ public ActiveHealthCheck putAdditionalProperty (String key , Object value ) {
195+ if (this .additionalProperties == null ) {
196+ this .additionalProperties = new HashMap <String , Object >();
197+ }
198+ this .additionalProperties .put (key , value );
199+ return this ;
200+ }
201+
202+ /**
203+ * Return the additional (undeclared) property.
204+ *
205+ * @return a map of objects
206+ */
207+ public Map <String , Object > getAdditionalProperties () {
208+ return additionalProperties ;
209+ }
210+
211+ /**
212+ * Return the additional (undeclared) property with the specified name.
213+ *
214+ * @param key name of the property
215+ * @return an object
216+ */
217+ public Object getAdditionalProperty (String key ) {
218+ if (this .additionalProperties == null ) {
219+ return null ;
220+ }
221+ return this .additionalProperties .get (key );
222+ }
223+
179224 @ Override
180225 public boolean equals (Object o ) {
181226 if (this == o ) {
@@ -190,7 +235,9 @@ public boolean equals(Object o) {
190235 && Objects .equals (this .interval , activeHealthCheck .interval )
191236 && Objects .equals (this .intervalJitter , activeHealthCheck .intervalJitter )
192237 && Objects .equals (this .timeout , activeHealthCheck .timeout )
193- && Objects .equals (this .unhealthyThreshold , activeHealthCheck .unhealthyThreshold );
238+ && Objects .equals (this .unhealthyThreshold , activeHealthCheck .unhealthyThreshold )
239+ && Objects .equals (
240+ this .additionalProperties , activeHealthCheck .additionalProperties );
194241 }
195242
196243 @ Override
@@ -201,7 +248,8 @@ public int hashCode() {
201248 interval ,
202249 intervalJitter ,
203250 timeout ,
204- unhealthyThreshold );
251+ unhealthyThreshold ,
252+ additionalProperties );
205253 }
206254
207255 @ Override
@@ -216,6 +264,9 @@ public String toString() {
216264 sb .append (" unhealthyThreshold: " )
217265 .append (toIndentedString (unhealthyThreshold ))
218266 .append ("\n " );
267+ sb .append (" additionalProperties: " )
268+ .append (toIndentedString (additionalProperties ))
269+ .append ("\n " );
219270 sb .append ("}" );
220271 return sb .toString ();
221272 }
@@ -266,17 +317,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
266317 ActiveHealthCheck .openapiRequiredFields .toString ()));
267318 }
268319 }
269-
270- Set <Map .Entry <String , JsonElement >> entries = jsonElement .getAsJsonObject ().entrySet ();
271- // check to see if the JSON string contains additional fields
272- for (Map .Entry <String , JsonElement > entry : entries ) {
273- if (!ActiveHealthCheck .openapiFields .contains (entry .getKey ())) {
274- throw new IllegalArgumentException (
275- String .format (
276- "The field `%s` in the JSON string is not defined in the `ActiveHealthCheck` properties. JSON: %s" ,
277- entry .getKey (), jsonElement .toString ()));
278- }
279- }
280320 JsonObject jsonObj = jsonElement .getAsJsonObject ();
281321 // validate the optional field `httpHealthChecks`
282322 if (jsonObj .get ("httpHealthChecks" ) != null
@@ -323,14 +363,71 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
323363 public void write (JsonWriter out , ActiveHealthCheck value )
324364 throws IOException {
325365 JsonObject obj = thisAdapter .toJsonTree (value ).getAsJsonObject ();
366+ obj .remove ("additionalProperties" );
367+ // serialize additional properties
368+ if (value .getAdditionalProperties () != null ) {
369+ for (Map .Entry <String , Object > entry :
370+ value .getAdditionalProperties ().entrySet ()) {
371+ if (entry .getValue () instanceof String )
372+ obj .addProperty (entry .getKey (), (String ) entry .getValue ());
373+ else if (entry .getValue () instanceof Number )
374+ obj .addProperty (entry .getKey (), (Number ) entry .getValue ());
375+ else if (entry .getValue () instanceof Boolean )
376+ obj .addProperty (entry .getKey (), (Boolean ) entry .getValue ());
377+ else if (entry .getValue () instanceof Character )
378+ obj .addProperty (
379+ entry .getKey (), (Character ) entry .getValue ());
380+ else {
381+ JsonElement jsonElement = gson .toJsonTree (entry .getValue ());
382+ if (jsonElement .isJsonArray ()) {
383+ obj .add (entry .getKey (), jsonElement .getAsJsonArray ());
384+ } else {
385+ obj .add (entry .getKey (), jsonElement .getAsJsonObject ());
386+ }
387+ }
388+ }
389+ }
326390 elementAdapter .write (out , obj );
327391 }
328392
329393 @ Override
330394 public ActiveHealthCheck read (JsonReader in ) throws IOException {
331395 JsonElement jsonElement = elementAdapter .read (in );
332396 validateJsonElement (jsonElement );
333- return thisAdapter .fromJsonTree (jsonElement );
397+ JsonObject jsonObj = jsonElement .getAsJsonObject ();
398+ // store additional fields in the deserialized instance
399+ ActiveHealthCheck instance = thisAdapter .fromJsonTree (jsonObj );
400+ for (Map .Entry <String , JsonElement > entry : jsonObj .entrySet ()) {
401+ if (!openapiFields .contains (entry .getKey ())) {
402+ if (entry .getValue ().isJsonPrimitive ()) { // primitive type
403+ if (entry .getValue ().getAsJsonPrimitive ().isString ())
404+ instance .putAdditionalProperty (
405+ entry .getKey (), entry .getValue ().getAsString ());
406+ else if (entry .getValue ().getAsJsonPrimitive ().isNumber ())
407+ instance .putAdditionalProperty (
408+ entry .getKey (), entry .getValue ().getAsNumber ());
409+ else if (entry .getValue ().getAsJsonPrimitive ().isBoolean ())
410+ instance .putAdditionalProperty (
411+ entry .getKey (),
412+ entry .getValue ().getAsBoolean ());
413+ else
414+ throw new IllegalArgumentException (
415+ String .format (
416+ "The field `%s` has unknown primitive type. Value: %s" ,
417+ entry .getKey (),
418+ entry .getValue ().toString ()));
419+ } else if (entry .getValue ().isJsonArray ()) {
420+ instance .putAdditionalProperty (
421+ entry .getKey (),
422+ gson .fromJson (entry .getValue (), List .class ));
423+ } else { // JSON object
424+ instance .putAdditionalProperty (
425+ entry .getKey (),
426+ gson .fromJson (entry .getValue (), HashMap .class ));
427+ }
428+ }
429+ }
430+ return instance ;
334431 }
335432 }.nullSafe ();
336433 }
0 commit comments