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/** CreateUpdateSchedulePayload */
3334@ javax .annotation .Generated (
@@ -137,6 +138,50 @@ public void setRrule(@javax.annotation.Nonnull String rrule) {
137138 this .rrule = rrule ;
138139 }
139140
141+ /**
142+ * A container for additional, undeclared properties. This is a holder for any undeclared
143+ * properties as specified with the 'additionalProperties' keyword in the OAS document.
144+ */
145+ private Map <String , Object > additionalProperties ;
146+
147+ /**
148+ * Set the additional (undeclared) property with the specified name and value. If the property
149+ * does not already exist, create it otherwise replace it.
150+ *
151+ * @param key name of the property
152+ * @param value value of the property
153+ * @return the CreateUpdateSchedulePayload instance itself
154+ */
155+ public CreateUpdateSchedulePayload putAdditionalProperty (String key , Object value ) {
156+ if (this .additionalProperties == null ) {
157+ this .additionalProperties = new HashMap <String , Object >();
158+ }
159+ this .additionalProperties .put (key , value );
160+ return this ;
161+ }
162+
163+ /**
164+ * Return the additional (undeclared) property.
165+ *
166+ * @return a map of objects
167+ */
168+ public Map <String , Object > getAdditionalProperties () {
169+ return additionalProperties ;
170+ }
171+
172+ /**
173+ * Return the additional (undeclared) property with the specified name.
174+ *
175+ * @param key name of the property
176+ * @return an object
177+ */
178+ public Object getAdditionalProperty (String key ) {
179+ if (this .additionalProperties == null ) {
180+ return null ;
181+ }
182+ return this .additionalProperties .get (key );
183+ }
184+
140185 @ Override
141186 public boolean equals (Object o ) {
142187 if (this == o ) {
@@ -150,12 +195,15 @@ public boolean equals(Object o) {
150195 && Objects .equals (
151196 this .maintenanceWindow , createUpdateSchedulePayload .maintenanceWindow )
152197 && Objects .equals (this .name , createUpdateSchedulePayload .name )
153- && Objects .equals (this .rrule , createUpdateSchedulePayload .rrule );
198+ && Objects .equals (this .rrule , createUpdateSchedulePayload .rrule )
199+ && Objects .equals (
200+ this .additionalProperties ,
201+ createUpdateSchedulePayload .additionalProperties );
154202 }
155203
156204 @ Override
157205 public int hashCode () {
158- return Objects .hash (enabled , maintenanceWindow , name , rrule );
206+ return Objects .hash (enabled , maintenanceWindow , name , rrule , additionalProperties );
159207 }
160208
161209 @ Override
@@ -168,6 +216,9 @@ public String toString() {
168216 .append ("\n " );
169217 sb .append (" name: " ).append (toIndentedString (name )).append ("\n " );
170218 sb .append (" rrule: " ).append (toIndentedString (rrule )).append ("\n " );
219+ sb .append (" additionalProperties: " )
220+ .append (toIndentedString (additionalProperties ))
221+ .append ("\n " );
171222 sb .append ("}" );
172223 return sb .toString ();
173224 }
@@ -214,17 +265,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
214265 }
215266 }
216267
217- Set <Map .Entry <String , JsonElement >> entries = jsonElement .getAsJsonObject ().entrySet ();
218- // check to see if the JSON string contains additional fields
219- for (Map .Entry <String , JsonElement > entry : entries ) {
220- if (!CreateUpdateSchedulePayload .openapiFields .contains (entry .getKey ())) {
221- throw new IllegalArgumentException (
222- String .format (
223- "The field `%s` in the JSON string is not defined in the `CreateUpdateSchedulePayload` properties. JSON: %s" ,
224- entry .getKey (), jsonElement .toString ()));
225- }
226- }
227-
228268 // check to make sure all required properties/fields are present in the JSON string
229269 for (String requiredField : CreateUpdateSchedulePayload .openapiRequiredFields ) {
230270 if (jsonElement .getAsJsonObject ().get (requiredField ) == null ) {
@@ -267,14 +307,72 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
267307 public void write (JsonWriter out , CreateUpdateSchedulePayload value )
268308 throws IOException {
269309 JsonObject obj = thisAdapter .toJsonTree (value ).getAsJsonObject ();
310+ obj .remove ("additionalProperties" );
311+ // serialize additional properties
312+ if (value .getAdditionalProperties () != null ) {
313+ for (Map .Entry <String , Object > entry :
314+ value .getAdditionalProperties ().entrySet ()) {
315+ if (entry .getValue () instanceof String )
316+ obj .addProperty (entry .getKey (), (String ) entry .getValue ());
317+ else if (entry .getValue () instanceof Number )
318+ obj .addProperty (entry .getKey (), (Number ) entry .getValue ());
319+ else if (entry .getValue () instanceof Boolean )
320+ obj .addProperty (entry .getKey (), (Boolean ) entry .getValue ());
321+ else if (entry .getValue () instanceof Character )
322+ obj .addProperty (
323+ entry .getKey (), (Character ) entry .getValue ());
324+ else {
325+ JsonElement jsonElement = gson .toJsonTree (entry .getValue ());
326+ if (jsonElement .isJsonArray ()) {
327+ obj .add (entry .getKey (), jsonElement .getAsJsonArray ());
328+ } else {
329+ obj .add (entry .getKey (), jsonElement .getAsJsonObject ());
330+ }
331+ }
332+ }
333+ }
270334 elementAdapter .write (out , obj );
271335 }
272336
273337 @ Override
274338 public CreateUpdateSchedulePayload read (JsonReader in ) throws IOException {
275339 JsonElement jsonElement = elementAdapter .read (in );
276340 validateJsonElement (jsonElement );
277- return thisAdapter .fromJsonTree (jsonElement );
341+ JsonObject jsonObj = jsonElement .getAsJsonObject ();
342+ // store additional fields in the deserialized instance
343+ CreateUpdateSchedulePayload instance =
344+ thisAdapter .fromJsonTree (jsonObj );
345+ for (Map .Entry <String , JsonElement > entry : jsonObj .entrySet ()) {
346+ if (!openapiFields .contains (entry .getKey ())) {
347+ if (entry .getValue ().isJsonPrimitive ()) { // primitive type
348+ if (entry .getValue ().getAsJsonPrimitive ().isString ())
349+ instance .putAdditionalProperty (
350+ entry .getKey (), entry .getValue ().getAsString ());
351+ else if (entry .getValue ().getAsJsonPrimitive ().isNumber ())
352+ instance .putAdditionalProperty (
353+ entry .getKey (), entry .getValue ().getAsNumber ());
354+ else if (entry .getValue ().getAsJsonPrimitive ().isBoolean ())
355+ instance .putAdditionalProperty (
356+ entry .getKey (),
357+ entry .getValue ().getAsBoolean ());
358+ else
359+ throw new IllegalArgumentException (
360+ String .format (
361+ "The field `%s` has unknown primitive type. Value: %s" ,
362+ entry .getKey (),
363+ entry .getValue ().toString ()));
364+ } else if (entry .getValue ().isJsonArray ()) {
365+ instance .putAdditionalProperty (
366+ entry .getKey (),
367+ gson .fromJson (entry .getValue (), List .class ));
368+ } else { // JSON object
369+ instance .putAdditionalProperty (
370+ entry .getKey (),
371+ gson .fromJson (entry .getValue (), HashMap .class ));
372+ }
373+ }
374+ }
375+ return instance ;
278376 }
279377 }.nullSafe ();
280378 }
0 commit comments