@@ -100,6 +100,50 @@ public void setStatus(@javax.annotation.Nullable Object status) {
100100 this .status = status ;
101101 }
102102
103+ /**
104+ * A container for additional, undeclared properties.
105+ * This is a holder for any undeclared properties as specified with
106+ * the 'additionalProperties' keyword in the OAS document.
107+ */
108+ private Map <String , Object > additionalProperties ;
109+
110+ /**
111+ * Set the additional (undeclared) property with the specified name and value.
112+ * If the property does not already exist, create it otherwise replace it.
113+ *
114+ * @param key name of the property
115+ * @param value value of the property
116+ * @return the AddDomainConfig200ResponseAnyOf instance itself
117+ */
118+ public AddDomainConfig200ResponseAnyOf putAdditionalProperty (String key , Object value ) {
119+ if (this .additionalProperties == null ) {
120+ this .additionalProperties = new HashMap <String , Object >();
121+ }
122+ this .additionalProperties .put (key , value );
123+ return this ;
124+ }
125+
126+ /**
127+ * Return the additional (undeclared) property.
128+ *
129+ * @return a map of objects
130+ */
131+ public Map <String , Object > getAdditionalProperties () {
132+ return additionalProperties ;
133+ }
134+
135+ /**
136+ * Return the additional (undeclared) property with the specified name.
137+ *
138+ * @param key name of the property
139+ * @return an object
140+ */
141+ public Object getAdditionalProperty (String key ) {
142+ if (this .additionalProperties == null ) {
143+ return null ;
144+ }
145+ return this .additionalProperties .get (key );
146+ }
103147
104148
105149 @ Override
@@ -112,12 +156,13 @@ public boolean equals(Object o) {
112156 }
113157 AddDomainConfig200ResponseAnyOf addDomainConfig200ResponseAnyOf = (AddDomainConfig200ResponseAnyOf ) o ;
114158 return Objects .equals (this ._configuration , addDomainConfig200ResponseAnyOf ._configuration ) &&
115- Objects .equals (this .status , addDomainConfig200ResponseAnyOf .status );
159+ Objects .equals (this .status , addDomainConfig200ResponseAnyOf .status )&&
160+ Objects .equals (this .additionalProperties , addDomainConfig200ResponseAnyOf .additionalProperties );
116161 }
117162
118163 @ Override
119164 public int hashCode () {
120- return Objects .hash (_configuration , status );
165+ return Objects .hash (_configuration , status , additionalProperties );
121166 }
122167
123168 @ Override
@@ -126,6 +171,7 @@ public String toString() {
126171 sb .append ("class AddDomainConfig200ResponseAnyOf {\n " );
127172 sb .append (" _configuration: " ).append (toIndentedString (_configuration )).append ("\n " );
128173 sb .append (" status: " ).append (toIndentedString (status )).append ("\n " );
174+ sb .append (" additionalProperties: " ).append (toIndentedString (additionalProperties )).append ("\n " );
129175 sb .append ("}" );
130176 return sb .toString ();
131177 }
@@ -170,14 +216,6 @@ public static void validateJsonElement(JsonElement jsonElement) throws IOExcepti
170216 }
171217 }
172218
173- Set <Map .Entry <String , JsonElement >> entries = jsonElement .getAsJsonObject ().entrySet ();
174- // check to see if the JSON string contains additional fields
175- for (Map .Entry <String , JsonElement > entry : entries ) {
176- if (!AddDomainConfig200ResponseAnyOf .openapiFields .contains (entry .getKey ())) {
177- throw new IllegalArgumentException (String .format ("The field `%s` in the JSON string is not defined in the `AddDomainConfig200ResponseAnyOf` properties. JSON: %s" , entry .getKey (), jsonElement .toString ()));
178- }
179- }
180-
181219 // check to make sure all required properties/fields are present in the JSON string
182220 for (String requiredField : AddDomainConfig200ResponseAnyOf .openapiRequiredFields ) {
183221 if (jsonElement .getAsJsonObject ().get (requiredField ) == null ) {
@@ -202,14 +240,57 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
202240 @ Override
203241 public void write (JsonWriter out , AddDomainConfig200ResponseAnyOf value ) throws IOException {
204242 JsonObject obj = thisAdapter .toJsonTree (value ).getAsJsonObject ();
243+ obj .remove ("additionalProperties" );
244+ // serialize additional properties
245+ if (value .getAdditionalProperties () != null ) {
246+ for (Map .Entry <String , Object > entry : value .getAdditionalProperties ().entrySet ()) {
247+ if (entry .getValue () instanceof String )
248+ obj .addProperty (entry .getKey (), (String ) entry .getValue ());
249+ else if (entry .getValue () instanceof Number )
250+ obj .addProperty (entry .getKey (), (Number ) entry .getValue ());
251+ else if (entry .getValue () instanceof Boolean )
252+ obj .addProperty (entry .getKey (), (Boolean ) entry .getValue ());
253+ else if (entry .getValue () instanceof Character )
254+ obj .addProperty (entry .getKey (), (Character ) entry .getValue ());
255+ else {
256+ JsonElement jsonElement = gson .toJsonTree (entry .getValue ());
257+ if (jsonElement .isJsonArray ()) {
258+ obj .add (entry .getKey (), jsonElement .getAsJsonArray ());
259+ } else {
260+ obj .add (entry .getKey (), jsonElement .getAsJsonObject ());
261+ }
262+ }
263+ }
264+ }
205265 elementAdapter .write (out , obj );
206266 }
207267
208268 @ Override
209269 public AddDomainConfig200ResponseAnyOf read (JsonReader in ) throws IOException {
210270 JsonElement jsonElement = elementAdapter .read (in );
211271 validateJsonElement (jsonElement );
212- return thisAdapter .fromJsonTree (jsonElement );
272+ JsonObject jsonObj = jsonElement .getAsJsonObject ();
273+ // store additional fields in the deserialized instance
274+ AddDomainConfig200ResponseAnyOf instance = thisAdapter .fromJsonTree (jsonObj );
275+ for (Map .Entry <String , JsonElement > entry : jsonObj .entrySet ()) {
276+ if (!openapiFields .contains (entry .getKey ())) {
277+ if (entry .getValue ().isJsonPrimitive ()) { // primitive type
278+ if (entry .getValue ().getAsJsonPrimitive ().isString ())
279+ instance .putAdditionalProperty (entry .getKey (), entry .getValue ().getAsString ());
280+ else if (entry .getValue ().getAsJsonPrimitive ().isNumber ())
281+ instance .putAdditionalProperty (entry .getKey (), entry .getValue ().getAsNumber ());
282+ else if (entry .getValue ().getAsJsonPrimitive ().isBoolean ())
283+ instance .putAdditionalProperty (entry .getKey (), entry .getValue ().getAsBoolean ());
284+ else
285+ throw new IllegalArgumentException (String .format ("The field `%s` has unknown primitive type. Value: %s" , entry .getKey (), entry .getValue ().toString ()));
286+ } else if (entry .getValue ().isJsonArray ()) {
287+ instance .putAdditionalProperty (entry .getKey (), gson .fromJson (entry .getValue (), List .class ));
288+ } else { // JSON object
289+ instance .putAdditionalProperty (entry .getKey (), gson .fromJson (entry .getValue (), HashMap .class ));
290+ }
291+ }
292+ }
293+ return instance ;
213294 }
214295
215296 }.nullSafe ();
0 commit comments